I have Appium Test script recorded by Appium
Here is my script
package com.hostname.myapp;
import io.appium.java_client.AppiumDriver;
import io.appium.java_client.android.AndroidDriver;
import io.appium.java_client.android.AndroidElement;
import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.concurrent.TimeUnit;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;
import org.openqa.selenium.By;
public class AppiumTest {
private static AppiumDriver<AndroidElement> wd;
@BeforeClass
public static void setUpClass() throws MalformedURLException {
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setCapability("appium-version", "1.0");
capabilities.setCapability("platformName", "Android");
capabilities.setCapability("platformVersion", "5.0.2");
capabilities.setCapability("deviceName", "XXXXXXXXXXXX");
capabilities.setCapability("app", "/Users/X/X.apk");
capabilities.setCapability("appPackage", "com.hostname.myapp");
wd = new AndroidDriver<AndroidElement>(new URL("http://127.0.0.1:4723/wd/hub"), capabilities);
wd.manage().timeouts().implicitlyWait(60, TimeUnit.SECONDS);
}
@AfterClass
public static void tearDownClass() {
if (wd != null) {
wd.quit();
}
}
@Test
public void test() throws IOException {
wd.findElement(By.xpath("//android.widget.LinearLayout[1]/.../android.widget.EditText[1]")).click();
wd.findElement(By.xpath("//android.widget.LinearLayout[1]/.../android.widget.EditText[1]")).sendKeys("username");
wd.findElement(By.xpath("//android.widget.LinearLayout[1]/.../android.widget.EditText[2]")).click();
wd.findElement(By.name("//android.widget.LinearLayout[1]/.../android.widget.EditText[2]")).sendKeys("password");
wd.findElement(By.xpath("//android.widget.LinearLayout[1]/.../android.widget.Button[1]")).click();
wd.close();
}
After I package into MAVEN project and uploaded to AWS Device Farm.
The script run failed, and the error message is:
An element could not be located on the page using the given search parameters.
(WARNING: The server did not provide any stacktrace information)
Command duration or timeout: 10.27 seconds For documentation on this error, please visit: http://seleniumhq.org/exceptions/no_such_element.html
Build info: version: '2.50.1',
revision: 'd7fc91b29de65b790abb01f3ac5f7ea2191c88a7',
time: '2016-01-29 11:11:26'
System info: host: 'ip-172-31-13-65',
ip: '172.31.13.65',
os.name: 'Linux',
os.arch: 'amd64',
os.version: '3.13.0-53-generic',
java.version: '1.8.0_65'
Driver info: io.appium.java_client.android.AndroidDriver Capabilities [{networkConnectionEnabled=true, desired={}, platformVersion=6.0.1, warnings={}, webStorageEnabled=false, locationContextEnabled=false, browserName=Android, takesScreenshot=true, javascriptEnabled=true, databaseEnabled=false, deviceName=6e4c6027, platform=LINUX}] Session ID: c0ec736d-c4d8-4b3a-8d3c-1beb24dd0782 ***
Element info: {Using=xpath, value=//android.widget.LinearLayout[1]/.../android.widget.EditText[1]}
If I am not wrong, my parameters of my elements are something wrong
But these path/parameter are recorded by Appium Insector
They should be correct, aren't them?
I did Google search and I found an answer which told me to change xpath into
By.xpath("//android.widget.EditText[@text='Email ID']")
But what should I do when I having 2 Textbox? I have username and password textbox
Thank a lot.