我正在使用Java和Selenium通过命令行初始化Appium,以便在Android Chrome浏览器上运行测试。
但是,该过程运行无限时间,并且来自" DesiredCapabilities
"行没有被执行..
代码:
Process proc;
String path_to_appium = System.getenv("APPIUM_HOME") + File.separator + "node_modules" + File.separator + "appium" + File.separator + "bin" + File.separator + "appium.js";
String path_to_node = System.getenv("APPIUM_HOME") + File.separator + "node.exe";
proc = Runtime.getRuntime().exec("\"" + path_to_node + "\"" + " " + "\"" + path_to_appium + "\"" + " " + "--address 127.0.0.1 --browser-name Chrome --platform-name Android --platform-version 17 --automation-name Appium --chromedriver-port 9516 --bootstrap-port 4724 --no-reset --local-timezone --log appium_log.log");
System.out.println("Android Chrome driver would be used");
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setCapability("platformName","Android");
capabilities.setCapability("deviceName", "HTC One X");
capabilities.setCapability("platformVersion", "4.2.2");
capabilities.setCapability("device", "android");
capabilities.setCapability("browserName", MobileBrowserType.CHROME);
Thread.sleep(2000);
driver = new RemoteWebDriver(new URL("http://127.0.0.1:4723/wd/hub"), capabilities);
driver.get("test.com");
我无法在控制台中获得任何输出。
什么都没发生。该过程不会进行下一行(即设置DesiredCapabilities
)。镀铬无法在设备上启动。
注意:当我从命令行执行命令,然后从DesiredCapabilities
行开始测试时,测试运行正常并且chrome已成功初始化。
代码有什么问题?
答案 0 :(得分:1)
问题在于最新的appium版本,即1_4_16_1。
当以编程方式启动appium服务器时,它正在创建一个死锁,因为驱动程序没有被初始化。
使用Appium的ServerArguments
并替换行
proc = Runtime.getRuntime().exec("\"" + path_to_node + "\"" + " " + "\"" + path_to_appium + "\"" + " " + "--address 127.0.0.1 --browser-name Chrome --platform-name Android --platform-version 17 --automation-name Appium --chromedriver-port 9516 --bootstrap-port 4724 --no-reset --local-timezone --log appium_log.log");
以下代码:
ServerArguments serverArguments = new ServerArguments();
serverArguments.setArgument("--address","127.0.0.1");
serverArguments.setArgument("--chromedriver-port", 9516);
serverArguments.setArgument("--bootstrap-port", 4724);
serverArguments.setArgument("--browser-name", "Chrome");
serverArguments.setArgument("--no-reset", true);
serverArguments.setArgument("--local-timezone", true);
AppiumServer appiumServer = new AppiumServer(appium_folder, serverArguments);
appiumServer.startServer();
driver = new RemoteWebDriver(new URL("http://127.0.0.1:4723/wd/hub"), capabilities);
driver.get("test.com");
答案 1 :(得分:0)
我认为问题在于你在proc输出中循环,你永远不会离开那里,看你甚至没有得到"这是命令的标准错误(如果任何):\ n"
我将输出日志记录放在另一个线程上以便您的程序可以继续运行,以下代码可以改进但是应该完成工作:
Process proc;
String path_to_appium = System.getenv("APPIUM_HOME") + File.separator + "node_modules" + File.separator + "appium" + File.separator + "bin" + File.separator + "appium.js";
String path_to_node = System.getenv("APPIUM_HOME") + File.separator + "node.exe";
proc = Runtime.getRuntime().exec("\"" + path_to_node + "\"" + " " + "\"" + path_to_appium + "\"" + " " + "--address 127.0.0.1 --browser-name Chrome --platform-name Android --platform-version 17 --automation-name Appium --chromedriver-port 9516 --bootstrap-port 4724 --no-reset --local-timezone --log appium_log.log");
BufferedReader stdInput = new BufferedReader(new InputStreamReader(proc.getInputStream()));
BufferedReader stdError = new BufferedReader(new InputStreamReader(proc.getErrorStream()));
new Thread()
{
public void run() {
// read thae output from the command
System.out.println("Here is the standard output of the command:\n");
String s = null;
while ((s = stdInput.readLine()) != null) {
System.out.println(s);
}
// read any errors from the attempted command
System.out.println("Here is the standard error of the command (if any):\n");
while ((s = stdError.readLine()) != null) {
System.out.println(s);
}
}
}.start();
System.out.println("Android Chrome driver would be used");
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setCapability("platformName","Android");
capabilities.setCapability("deviceName", "HTC One X");
capabilities.setCapability("platformVersion", "4.2.2");
capabilities.setCapability("device", "android");
capabilities.setCapability("browserName", MobileBrowserType.CHROME);
Thread.sleep(2000);
driver = new RemoteWebDriver(new URL("http://127.0.0.1:4723/wd/hub"), capabilities);
driver.get("test.com");