findElementByAccessibilityid is not shown in eclipse intellisense - java

I am trying to do a POC for a windows app using winappdriver . I have the winappdriver version 1.1 installed up and running. I want to find the elements by using their automationId. As per winappdriver documentation, elements with AutiomationID can be located by "findElementByAccessibilityId". I am not able to see this locator strategy in my Eclipse intellisense. Instead "findElementsByAccessibilityId" ( notice elements) is been shown up. What should i do so that i can see "findElementByAccessibilityId" locator in intellisense.
import java.net.MalformedURLException;
import java.net.URL;
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.By;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
import io.appium.java_client.windows.WindowsDriver;
public class LoginTest {
private static WindowsDriver<WebElement> driver = null;
#BeforeClass
public static void setup() throws MalformedURLException {
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setCapability("app", "XXXXXXXXXXXXXXXXXXXXXX");
capabilities.setCapability("platformName", "windows");
capabilities.setCapability("deviceName", "windowsPC");
capabilities.setCapability("appWorkingDir", "XXXXXXXXXXXXXXXXXXXXXXXXXX");
driver = new WindowsDriver<WebElement>(new URL("http://127.0.0.1:4723"), capabilities);
driver.manage().timeouts().implicitlyWait(2, TimeUnit.SECONDS);
}
#Test
public void Testing()
{
driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
driver.findElement(By.className("TextBox")).sendKeys("XXXX");
driver.findElementById("TxtPwd").sendKeys("XXXX");
driver.findElementsByAccessibilityId("TxtPwd");
driver.findElement(By.id("BtnLogin")).click();
System.out.println("Hi");
}
}
POM.xml

Related

How to Handle Alerts Using Headless Browsers (HtmlUnitDriver/Phantomjs Driver)

I am using PhantomJs Driver for Headless Testing , I am getting below exception
Sample code:
import static org.testng.Assert.assertEquals;
import org.openqa.selenium.Alert;
import org.openqa.selenium.By;
import org.openqa.selenium.Capabilities;
import org.openqa.selenium.NoAlertPresentException;
import org.openqa.selenium.UnexpectedAlertBehaviour;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.phantomjs.PhantomJSDriver;
import org.openqa.selenium.remote.CapabilityType;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
public class TestLogin {
WebDriver d;
#BeforeMethod
public void launh_Browser() {
System.setProperty("phantomjs.binary.path", "D:\\Selenium\\driver\\phantomjs-2.1.1-windows\\bin\\phantomjs.exe");
Capabilities caps = new DesiredCapabilities();
((DesiredCapabilities) caps).setJavascriptEnabled(true);
((DesiredCapabilities) caps).setCapability("takesScreenshot", true);
d=new PhantomJSDriver(caps);
}
#Test
public void guru_banking_login_excel() throws Exception {
d.get("http://www.demo.guru99.com/V4/");
d.findElement(By.name("uid")).sendKeys("TestUser");
d.findElement(By.name("password")).sendKeys("testpwd");
d.findElement(By.name("btnLogin")).click();
try{
Alert alt = d.switchTo().alert();
String actualBoxMsg = alt.getText(); // get content of the Alter Message
assertEquals(actualBoxMsg,"User or Password is not valid");
alt.accept();
}
catch (NoAlertPresentException Ex){
String hometitle=d.getTitle();
assertEquals(hometitle,"Guru99 Bank Manager HomePage");
}
d.quit
}
Error Observed :
Exception : org.openqa.selenium.UnsupportedCommandException: Invalid Command Method - {"headers":{"Accept-Encoding":"gzip,deflate","Cache-Control":"no-cache","Connection":"Keep-Alive","
I am trying to handle popup using phantomjs as a driver
Please help on This .........
Thanks in Advance..!!!!
You have to take care of a lot of points here in your code :
While working with PhantomJS when you mention System.setProperty use the following code lines instead :
File src = new File("C:\\Utility\\phantomjs-2.1.1-windows\\bin\\phantomjs.exe");
System.setProperty("phantomjs.binary.path", src.getAbsolutePath());
DesiredCapabilities type of objects must be initiated with reference to DesiredCapabilities class only. So change to :
DesiredCapabilities caps = new DesiredCapabilities();
While using assertEquals use Assert.assertEquals as follows :
Assert.assertEquals(actualBoxMsg,"User or Password is not valid");
//
Assert.assertEquals(hometitle,"Guru99 Bank Manager HomePage");
As you are using TestNG, for Assert, use org.testng.Assert; instead of static org.testng.Assert.assertEquals; as an import :
import org.testng.Assert;
You need to wrap up the line d.quit() within a separate TestNG Annotated function too as follows :
#AfterMethod
public void tearDown() {
d.quit();
}
Here is your own code block which executes successfully :
package headlessBrowserTesting;
import java.io.File;
import org.openqa.selenium.Alert;
import org.openqa.selenium.By;
import org.openqa.selenium.NoAlertPresentException;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.phantomjs.PhantomJSDriver;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.testng.Assert;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
public class PhantomJS_webdriver_binary
{
WebDriver d;
#BeforeMethod
public void launh_Browser() {
File src = new File("C:\\Utility\\phantomjs-2.1.1-windows\\bin\\phantomjs.exe");
System.setProperty("phantomjs.binary.path", src.getAbsolutePath());
DesiredCapabilities caps = new DesiredCapabilities();
((DesiredCapabilities) caps).setJavascriptEnabled(true);
((DesiredCapabilities) caps).setCapability("takesScreenshot", true);
d=new PhantomJSDriver(caps);
}
#Test
public void guru_banking_login_excel() throws Exception {
d.get("http://www.demo.guru99.com/V4/");
d.findElement(By.name("uid")).sendKeys("TestUser");
d.findElement(By.name("password")).sendKeys("testpwd");
d.findElement(By.name("btnLogin")).click();
try{
Alert alt = d.switchTo().alert();
String actualBoxMsg = alt.getText();
Assert.assertEquals(actualBoxMsg,"User or Password is not valid");
alt.accept();
}
catch (NoAlertPresentException Ex){
String hometitle=d.getTitle();
Assert.assertEquals(hometitle,"Guru99 Bank Manager HomePage");
}
}
#AfterMethod
public void tearDown() {
d.quit();
}
}

"The attribute value is undefined for the annotation type Parameters" error is displayed for Cross-Browser Testing Script

I am trying this cross-browser testing using Selenium.
CrossBrowser.java:
package automationFramewok;
import java.net.MalformedURLException;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.opera.OperaDriver;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test;
import com.beust.jcommander.Parameters;
// I am getting the following error on the next line
//
// "The attribute value is undefined for the annotation type Parameters"
//
#Parameters({"browser"})
public class CrossBrowser {
#SuppressWarnings("deprecation")
#BeforeTest
public void setUp(String browser) throws MalformedURLException {
if (browser.equalsIgnoreCase("Firefox")) {
System.out.println("Running Firefox");
System.setProperty("webdriver.gecko.driver","E:\\\\Selenium-required files\\geckodriver\\geckodriver.exe");
FirefoxDriver driver = new FirefoxDriver();
} else if (browser.equalsIgnoreCase("chrome")) {
System.out.println("Running Chrome");
System.setProperty("webdriver.chrome.driver", "E:\\\\\\\\Selenium-required files\\\\chromedriver\\\\chromedriver.exe");
ChromeDriver driver = new ChromeDriver();
} else if (browser.equalsIgnoreCase("opera")) {
System.out.println("Running Opera");
// driver = new OperaDriver(); --Use this if the location is set properly--
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setCapability("opera.binary", "C://Program Files (x86)//Opera//opera.exe");
capabilities.setCapability("opera.log.level", "CONFIG");
System.setProperty("webdriver.opera.driver", "E:\\\\\\\\Selenium-required files\\\\operadriver\\\\operadriver.exe");
OperaDriver driver = new OperaDriver(capabilities);
}
}
}
I am receiving the following error message:
The attribute value is undefined for the annotation type Parameters
How can I resolve this?
Check out your list of import statements. I think you want
import org.testng.annotations.Parameters;
and not
import com.beust.jcommander.Parameters;
The same issue I was facing and problem was with import statement. I was using the following import statement.
import org.junit.runners.Parameterized.Parameters;
Replaced with the following import statement and issue got resolved.
import org.testng.annotations.Parameters;

web element can not find the element in eclipse java with appium android app test

This is my Code. actually i was run the android app with appium using eclipse. here app is launch but it is not find any element and it show the error in console. the error is " Exception in thread "main" java.lang.NullPointerException ".
package amazon;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.concurrent.TimeUnit;
//import junit.framework.Assert;
import org.junit.Assert;
import org.openqa.selenium.By;
import org.openqa.selenium.WebElement;
//import org.junit.Assert;
//import org.junit.Test;
import org.openqa.selenium.remote.CapabilityType;
import org.openqa.selenium.remote.DesiredCapabilities;
import io.appium.java_client.android.AndroidDriver;
public class StartApplication {
private static AndroidDriver driver;
public static void main(String[] args) throws MalformedURLException, InterruptedException {
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setCapability(CapabilityType.BROWSER_NAME, "");
capabilities.setCapability("deviceName", "a71ce4a7");
capabilities.setCapability("platformVersion", "5.0.2");
capabilities.setCapability("platformName", "Android");
capabilities.setCapability("appPackage", "com.hypersoft.vwallet");
//capabilities.setCapability("appActivity", "com.hypersoft.vwallet.ui.activity.HomeActivityNew_");
capabilities.setCapability("appActivity", "com.hypersoft.vwallet.ui.activity.SignInActivity_");
driver = new AndroidDriver(new URL("http://127.0.0.1:4723/wd/hub"), capabilities);
driver.manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS);
//Thread.sleep(10000);
System.out.println("App launched");
//Thread.sleep(10000);
driver.findElementById("com.hypersoft.vwallet:id/tvGetHelp").click();
driver.findElement(By.id("com.hypersoft.vwallet:id/etMailAddress")).sendKeys("test#gmail.com");
//driver.findElementByClassName("android.widget.EditText").sendKeys("test#gmail.com");;
System.out.println("test");
driver.findElement(By.id("com.hypersoft.vwallet:id/btnAgree")).click();
driver.findElement(By.id("com.hypersoft.vwallet:id/etMailAddress")).sendKeys("test321#gmail.com");
driver.findElement(By.id("com.hypersoft.vwallet:id/etPassword")).sendKeys("test4321");
driver.findElement(By.id("com.hypersoft.vwallet:id/etPasswordRe")).sendKeys("test4321");
driver.findElement(By.id("com.hypersoft.vwallet:id/etLastName")).sendKeys("Patel");
driver.findElement(By.id("com.hypersoft.vwallet:id/etFirstName")).sendKeys("Niravpp");
driver.hideKeyboard();
driver.findElement(By.id("com.hypersoft.vwallet:id/btnSignUp")).click();
driver.findElement(By.className("android.widget.ImageButton")).click();
driver.findElementByName("Logout").click();
driver.findElement(By.id("android:id/button1")).click();
driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
driver.findElement(By.id("com.hypersoft.vwallet:id/etMailAddress")).sendKeys("test321#gmail.com");
driver.findElement(By.id("com.hypersoft.vwallet:id/etPassword")).sendKeys("test4321");
driver.findElement(By.id("com.hypersoft.vwallet:id/btnSignIn")).click();
WebElement element = driver.findElement(By.name("VCA Wallet"));
String strng = element.getText();
Assert.assertEquals(strng,"VCA Wallet");
if(strng.equals("VCA Wallet"))
{
System.out.printf("pass\n");
} else {
System.out.println("Fail\n");
}
System.out.println(strng);
//driver.swipe(startx, starty, endx, endy, duration);
driver.close();
}
}
I will add my console in bellow screen shoot so, please check it and give some suggestion.

NoSuchMethodError: org.openqa.selenium.remote.CommandInfo.<init>(Ljava/lang/String;Lorg/openqa/selenium/remote/HttpVerb;)V

i'm trying to run selendroid web for practice but i'm getting errors even i update selenium version (2.48.2) and set all paths correctly.
below is my code and i'm getting this error.
Please help me...
NoSuchMethodError: org.openqa.selenium.remote.CommandInfo.(Ljava/lang/String;Lorg/openqa/selenium/remote/HttpVerb;)V
package com.guru.test;
import io.selendroid.SelendroidCapabilities;
import io.selendroid.SelendroidDriver;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.testng.annotations.AfterSuite;
import org.testng.annotations.BeforeSuite;
import org.testng.annotations.Test;
public class testWeb {
public WebDriver driver;
#BeforeSuite
public void setUp() throws Exception
{
DesiredCapabilities caps = SelendroidCapabilities.android();
driver = new SelendroidDriver(caps);
}
#Test
public void WebSiteTest() throws Exception
{
driver.get("http://google.com");
WebElement searchQuery = driver.findElement(By.name("q"));
searchQuery.click();
searchQuery.sendKeys("Test");
WebElement submit = driver.findElement(By.name("btnG"));
submit.click();
}
#AfterSuite
public void tearDown() throws Exception{
driver.quit();
}
}
I think you have mixed up selenium and selendroid jars. selendroid-standalone + selendroid-client should be enough for this.

appium test findElement button click doesnt work when it should

I'm trying to run a test in eclipse using appium for android. While the test starts and the application launches it throws an error on the first command while trying to press a button. I'm pretty sure that the id for the button is correct since running the same code with selendroid worked. The error at failure trace shows java.lang.NullPointerException. Here is my code:
package thePack;
import static org.junit.Assert.*;
import io.appium.java_client.AppiumDriver;
import java.io.File;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.concurrent.TimeUnit;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.interactions.Actions;
import org.openqa.selenium.remote.CapabilityType;
import org.openqa.selenium.remote.DesiredCapabilities;
public class theTest {
static AppiumDriver driver;
#Before
public void setUp() throws MalformedURLException, InterruptedException, Exception
{
WebDriver dr;
File app = new File("C:\\development\\src\\main\\resources\\app.apk");
DesiredCapabilities capabilities= new DesiredCapabilities();
capabilities.setCapability(CapabilityType.BROWSER_NAME, "");
capabilities.setCapability("deviceName", "Vodafone Smart 4G");
capabilities.setCapability("platformVersion", "4.2.2");
capabilities.setCapability("platformName", "Android");
capabilities.setCapability("app", app.getAbsolutePath());
capabilities.setCapability("appium-version", "1.2.1");
capabilities.setCapability("appPackage", "mypackage.mine.net");
capabilities.setCapability("appActivity", "mypackage.mine.net.activities.mainActivity");
dr = new AppiumDriver(new URL("http://127.0.0.1:4723/wd/hub"), capabilities) ;
}
#Test
public void login() throws Exception
{
Thread.sleep(0500);
driver.findElement(By.id("english")).click();
Thread.sleep(0500);
}
Any ideas? Thanks!
the line:
capabilities.setCapability(CapabilityType.BROWSER_NAME, "");
indicates that your test will be performed on the browser, and this should open the browser when start your test. Thus your elements will never be found
Figured out the issue. For me the problem was the Appium version itself. I was running the 1.3.4.1 and using an Android 4.2.2 device. As soon as i switched to version 1.2.4.1 for Appium i had no problems!

Categories

Resources