Below program hangs completely, after trying to find elements. Doesn't look like anything wrong with xpath either. I need to terminate the program manually each time. Is there anything which i need to change in code or should i need to add something?
public class Test123 {
public static void main(String[] args) throws MalformedURLException, InterruptedException {
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setCapability("noReset", "true");
capabilities.setCapability(MobileCapabilityType.AUTOMATION_NAME, "Appium");
capabilities.setCapability(MobileCapabilityType.PLATFORM_NAME, "Android");
capabilities.setCapability(MobileCapabilityType.PLATFORM_VERSION, "8.1.0");
capabilities.setCapability(MobileCapabilityType.DEVICE_NAME,"Android");
capabilities.setCapability(MobileCapabilityType.APP, app.getAbsolutePath());
capabilities.setCapability(AndroidMobileCapabilityType.APP_PACKAGE, "com.talentpace.substk");
capabilities.setCapability(AndroidMobileCapabilityType.APP_ACTIVITY, "com.talentpace.substk.MainActivity");
URL url=new URL("http://127.0.0.1:4723/wd/hub");
AndroidDriver driver=new AndroidDriver(url,capabilities);
Thread.sleep(5000);
driver.findElementByXPath("//node[#class='android.widget.EditText']").click();
}
}
Change your AUTOMATION_NAME in desired capabilites from Appium to uiautomator2
capabilities.setCapability(MobileCapabilityType.AUTOMATION_NAME, "uiautomator2");
Seems that you have given the wrong xpath
the correct one should look like this
//android.widget.EditText[#class='Enter Class name here..']
Related
A new session could not be created.
[error: No app set; either start appium with --app or pass in an 'app' value in desired capabilities, or set android Package to launch pre-existing app on device)
While running code with appium using eclipse, I had this error.
public class FirstAppiumProgram {
public static void main(String[] args) throws MalformedURLException {
DesiredCapabilities dc = new DesiredCapabilities();
dc.setCapability("BROWSER_NAME", "");
dc.setCapability(MobileCapabilityType.PLATFORM_NAME,Platform.ANDROID);
dc.setCapability(MobileCapabilityType.VERSION, "5.1.1");
dc.setCapability("APP_PACKAGE", "com.android.calculator2");
dc.setCapability("APP_ACTIVITY", "com.android.calculator2.Calculator");
dc.setCapability(MobileCapabilityType.DEVICE_NAME,"Nexus 5");
WebDriver driver= new RemoteWebDriver(new
URL("http://127.0.0.1:4723/wd/hub"),dc);
System.out.println(dc.toString());
driver.quit();
}
}
I think your error is because your capabilities are set wrongly.
At least appPackage and appActivity.
Read how capabilities are. Your possible capabilities:
//Your capabilities should be something like this:
DesiredCapabilities dc = new DesiredCapabilities();
dc.setCapability("platformName", "Android");
dc.setCapability("platformVersion", "5.1.1");
dc.setCapability("deviceName", "Nexus 5");
dc.setCapability("appPackage", "com.android.calculator2");
dc.setCapability("appActivity", "com.android.calculator2.Calculator");
Give it a try and let me know if you made it work
I am stuck with a game application where the appium returns 200 status code for a spin click(none of the clicks on game page is working though appium returns 200 code) but the click is not performed on the device. It is a web application and I am using the real device. Any help would be greatly appreciated.
I have tried using implicit, explicit waits, wait using Thread, Javascript, coordinates based click but no luck.
I am using the below code:
public class AndriodDriver {
AndroidDriver<WebElement> driver;
#Test
public void testFirstCalculator() throws IOException, InterruptedException {
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities = new DesiredCapabilities();
capabilities.setCapability("deviceName", "Samsung Galaxy S7");
capabilities.setCapability("platformName", "Android");
capabilities.setCapability(CapabilityType.BROWSER_NAME, "Chrome");
capabilities.setCapability("platformVersion", "7.0");
driver = new AndroidDriver<WebElement>(new
URL("http://0.0.0.0:4723/wd/hub"), capabilities);
driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
driver.get("https://pa03-mob.wi-gameserver.com/resource-service/test-
lobby/index.html");
driver.manage().timeouts().implicitlyWait(200, TimeUnit.SECONDS);
System.out.println("main url");
driver.findElement(By.xpath(".//*[#id='Open Lobby with debug properties']")).click();
System.out.println("lobby opened");
driver.findElement(By.xpath(".//*[#id='brucelee']")).click();
System.out.println("game loading");
WebDriverWait wait= new WebDriverWait(driver, 30);
//wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath(".//*
[#id='spin-button']")));
Thread.sleep(3500);
driver.findElementByXPath(".//*[#id='spin-button']").click();
}
}
First step:
Please add the following capability :
cap.setCapability("automationName","MyTest");
Second step:
Please replace the line :
capabilities.setCapability(CapabilityType.BROWSER_NAME, "Chrome");
by this:
cap.setCapability("browserName","Chrome");
I am trying to do appium automation and i had written the appium automation code. i had used appium server and my code is mention below :
public class WaitTests {
WebDriver driver;
#Before
public void setUp() throws MalformedURLException {
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setCapability("deviceName", "XT1562");
capabilities.setCapability(CapabilityType.BROWSER_NAME, "Android");
capabilities.setCapability(CapabilityType.VERSION, "6.0.1");
capabilities.setCapability("platformName", "Android");
capabilities.setCapability("appPackage", "com.android.calculator2");
capabilities.setCapability("appActivity", "com.android.calculator2.Calculator");
driver = new RemoteWebDriver(new URL("http://127.0.0.1:4723/wd/hub"), capabilities);
driver.manage().timeouts().implicitlyWait(15, TimeUnit.SECONDS);
}
#Test
public void testFirstCalculator() {
driver.findElements(By.xpath("//android.widget.Button")).get(0).click();
driver.findElement(By.name("7")).click();
driver.manage().timeouts().implicitlyWait(30,TimeUnit.SECONDS);
}
I want to run the code without IDE after creating .apk so what should i do to achieve. please suggest me
I've had this same problem and could fix it by creating a new Java module in Android Studio, adding a new gradle task in my build.gradle file:
task(runAppium, dependsOn: 'classes', type: JavaExec) {
main = 'com.mypackage.appium.Appium'
classpath = sourceSets.main.runtimeClasspath
}
and then launching it with:
gradle runAppium
As it's a Java module you'll need to have a public static void main(String[] args) function which will launch the test.
Hope it helps!
I am getting this error given below :
java.lang.ClassNotFoundException, If I run the below code :
#Test
public void alert() throws MalformedURLException, InterruptedException {
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setCapability("browserName", "");
capabilities.setCapability("platformName", "Android");
capabilities.setCapability("deviceName", "emulator-5554");
capabilities.setCapability("platformVersion", "5.1");
capabilities.setCapability("appPackage", "com.example.android.apis");
capabilities.setCapability("appActivity","com.example.android.apis.ApiDemos");
capabilities.setCapability("newCommandTimeout", "1000");
driver = (AndroidDriver) new RemoteWebDriver(new URL("http://127.0.0.1:4723/wd/hub"),capabilities);
driver.manage().timeouts().implicitlyWait(15, TimeUnit.SECONDS);
Please let me know why this error is being thrown, have I missed any jar .
I am using :
Selenium 3.0.0 , Java Client 4.2.1 Jar , Selenium Android Driver Jar and Appium 1.16.4.1
Use jar
selenium-api-2.53.0
selenium-java-2.53.0
selenium-remote-server-2.53.0
selenium-server-standalone-2.53.0
java-client-4.1.2
I am asking this because when i automate an app(TestApp.apk) present in my workspace is working fine. But when i use another app(WnG.apk) which is not present in my workspace it doesn't works. At this time appium fails to locate the element. An error ("An element could not be located on the page using the given search parameters.") occurs.
Below is my code:
public class Appium {
WebDriver driver;
#BeforeClass
public void setUp() throws MalformedURLException{
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setCapability("deviceName", "Android Emulator");
capabilities.setCapability(CapabilityType.BROWSER_NAME, ""); //Name of mobile web browser to automate. Should be an empty string if automating an app instead.
capabilities.setCapability("platformVersion", "4.4");
capabilities.setCapability(CapabilityType.PLATFORM, "Windows");
capabilities.setCapability("platformName", "Android");
capabilities.setCapability("app", "C:/Appium/AppiumForWindows-1.2.4.1/WishAndGreet.apk");
capabilities.setCapability("app-package", "com.example.wishandgreet"); //Replace with your app's package
capabilities.setCapability("app-activity", ".LoginActivity"); //Replace with app's Activity
driver = new RemoteWebDriver(new URL("http://127.0.0.1:4723/wd/hub"), capabilities);
}
#Test
public void loginTest(){
System.out.println("*************************************************************");
WebElement e1 = driver.findElement(By.id("com.example.wishandgreet:id/usernameEditText"));
System.out.println(e1.getText());
Assert.assertTrue(e1.getText() == "email / mobile number", "Username Text incorrect");
//Assert.assertEquals(e1.getText(),"email / mobile number");
e1.sendKeys("test#gmail.com");
WebElement e2 = driver.findElement(By.id("com.example.wishandgreet:id/passwordEditText"));
Assert.assertTrue(e2.getText() == "Password", "Pass text incorrect");
e2.sendKeys("1234");
System.out.println(e2);
WebElement e3 = driver.findElement(By.id("com.example.wishandgreet:id/loginButton"));
e3.click();
System.out.println(e1);
}
#AfterClass
public void tearDown(){
driver.quit();
}
In Android case, you need only .apk file to automate using Appium.
Looks like the issue you are facing is related to identifying an element. Please double check you are using right locators to identify required element and make sure that element appears on the view.