[英]Java Appium Test failed to run on AWS Device Farm
I have Appium script in Java language which recoreded by Appium Insecptor. 我有Java语言的Appium脚本,该脚本由Appium Insecptor复核。
My script is going to do only 5 steps: 我的脚本将仅执行5个步骤:
Click username field 点击用户名字段
Input username 输入用户名
Click password field 单击密码字段
Inout password 输入密码
Click login button 点击登录按钮
I would like to run my script on AWS Device Farm. 我想在AWS Device Farm上运行脚本。
I did follow the document of AWS Device Farm to modify my pom.xml
file, packaged it by using Maven package mvn clean package -Dskiptests=true
and finally uploaded the zip-with-dependencies.zip
to AWS Device Farm. 我确实按照AWS Device Farm的文档修改了pom.xml
文件,使用Maven软件包mvn clean package -Dskiptests=true
打包了该文件,最后将zip-with-dependencies.zip
上传到了AWS Device Farm。
But my test failed to run. 但是我的测试无法运行。 Here are the screenshots of the result 这是结果的屏幕截图
I don't know where I did mistake to make AWS failed to run my script. 我不知道我在哪里犯了错误,使AWS无法运行脚本。
Here is what I recorded, 这是我记录的
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://0.0.0.0: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.EditText[1]")).click();
wd.findElement(By.xpath("android.widget.EditText[1]")).sendKeys("username");
wd.findElement(By.xpath("android.widget.EditText[2]")).click();
wd.findElement(By.name("Android.widget.EditText[2]")).sendKeys("password");
wd.findElement(By.xpath("android.widget.Button[1]")).click();
wd.close();
}
I work for the AWS Device Farm team. 我为AWS Device Farm团队工作。
Thank you for the detailed information. 感谢您提供详细信息。 This helps. 这会有所帮助。
Solution 解
Desired Capabilities : Device farm ignores the desired capabilities that you have used. 所需功能 :设备场将忽略您已使用的所需功能。 Since you upload the app separately in device farm and choose the device while scheduling a run the device type, name and other capabilities that you use in your code will not be honored and any code that depends on it most likely will not work. 由于您是在设备场中分别上传应用程序并在安排运行时选择设备的,因此将不支持您在代码中使用的设备类型,名称和其他功能,并且依赖于此代码的任何代码都将不起作用。 Creating an empty desired capability object and passing that to the AndroidDriver constructor would be the ideal way to approach this. 创建一个空的所需功能对象并将其传递给AndroidDriver构造函数将是实现此目标的理想方法。
Android Driver : The code that you used Android驱动程序 :您使用的代码
wd = new AndroidDriver<AndroidElement>(new URL("http://0.0.0.0:4723/wd/hub"), capabilities);
should be 应该
wd = new AndroidDriver<AndroidElement>(new URL("http://127.0.0.1:4723/wd/hub"), capabilities);
Video : We have video recording capability for both iOS and Android. 视频 :我们具有iOS和Android的视频录制功能。 When a test fails it helps immensely if there is a video of that run. 如果测试失败,那么如果有运行该视频的视频,它将提供极大帮助。 You can check this under the "Files" tab. 您可以在“文件”标签下进行检查。 It could be the case that a pop appeared on the device or some other unexpected event while running the test. 可能是在运行测试时设备上出现了弹出声或其他意外事件。 The video should give you more insight in this case. 在这种情况下,视频应该可以为您提供更多的见识。
I would suggest trying these 3 changes. 我建议尝试这3种变化。 Let me know if you are still unable to proceed. 让我知道您是否仍然无法继续。
Hope this helps. 希望这可以帮助。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.