无法在设备上运行我的代码 [英] Unable to Run my code on device
问题描述
package android;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.remote.CapabilityType;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.remote.RemoteWebDriver;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test;
public class SimpleAndroidCalcTest {
WebDriver driver;
@BeforeTest
public void setUp() throws MalformedURLException{
// Created object of DesiredCapabilities class.
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setCapability("deviceName", "0227074902999561");
capabilities.setCapability(CapabilityType.BROWSER_NAME, "Android");
capabilities.setCapability(CapabilityType.VERSION, "5.1.1");
capabilities.setCapability("platformName", "Android");
capabilities.setCapability("appPackage", "com.example.mypackage");
capabilities.setCapability("appActivity", "com.example.mypackage.MainActivity");
driver = new RemoteWebDriver(new URL("http://127.0.0.1:4723/wd/hub"), capabilities);
driver.manage().timeouts().implicitlyWait(15, TimeUnit.SECONDS);
}
@Test public void SKIP()
{
driver.findElement(By.xpath("//android.widget.Button[@text='SKIP']")).click();
}
}
这是以下控制台错误,我无法在设备上运行上述代码.我在 Ubuntu 14.04 LTS 机器上运行这些代码.Eclipse 版本 Mars.控制台错误显示为 FAILED CONFIGURATION:@BeforeTest setUporg.openqa.selenium.SessionNotCreatedException:无法创建新会话.(原错误:命令失败:/bin/sh -c "/usr/bin/adb" -s adb server is out date.killing...wait-for-deviceADB 服务器没有 ACK* 无法启动服务器 *
This is the following console error, and I am not able to Run the above code on device. I am running these code on Ubuntu 14.04 LTS machine. Eclipse version Mars.Console error is shown as FAILED CONFIGURATION: @BeforeTest setUp org.openqa.selenium.SessionNotCreatedException: A new session could not be created. (Original error: Command failed: /bin/sh -c "/usr/bin/adb" -s adb server is out of date. killing... wait-for-device ADB server didn't ACK * could not start server *
****Console Error:****
[TestNG] Running:
/tmp/testng-eclipse-1773582615/testng-customsuite.xml
FAILED CONFIGURATION: @BeforeTest setUp
org.openqa.selenium.SessionNotCreatedException: A new session could not be created. (Original error: Command failed: /bin/sh -c "/usr/bin/adb" -s adb server is out of date. killing... wait-for-device
ADB server didn't ACK
* could not start server *
) (WARNING: The server did not provide any stacktrace information)
Command duration or timeout: 14.00 seconds
Build info: version: '2.48.2', revision: '41bccdd', time: '2015-10-09 19:55:52'
System info: host: 'rishabhambre-Lenovo-B50-70', ip: '127.0.1.1', os.name: 'Linux', os.arch: 'amd64', os.version: '3.19.0-25-generic', java.version: '1.8.0_66'
Driver info: org.openqa.selenium.remote.RemoteWebDriver
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:422)
at org.openqa.selenium.remote.ErrorHandler.createThrowable(ErrorHandler.java:206)
at org.openqa.selenium.remote.ErrorHandler.throwIfResponseFailed(ErrorHandler.java:158)
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:647)
at org.openqa.selenium.remote.RemoteWebDriver.startSession(RemoteWebDriver.java:247)
at org.openqa.selenium.remote.RemoteWebDriver.<init>(RemoteWebDriver.java:129)
at org.openqa.selenium.remote.RemoteWebDriver.<init>(RemoteWebDriver.java:156)
at android.SimpleAndroidCalcTest.setUp(SimpleAndroidCalcTest.java:29)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:497)
at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:86)
at org.testng.internal.Invoker.invokeConfigurationMethod(Invoker.java:514)
at org.testng.internal.Invoker.invokeConfigurations(Invoker.java:215)
at org.testng.internal.Invoker.invokeConfigurations(Invoker.java:142)
at org.testng.TestRunner.beforeRun(TestRunner.java:656)
at org.testng.TestRunner.run(TestRunner.java:624)
at org.testng.SuiteRunner.runTest(SuiteRunner.java:366)
at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:361)
at org.testng.SuiteRunner.privateRun(SuiteRunner.java:319)
at org.testng.SuiteRunner.run(SuiteRunner.java:268)
at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52)
at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:86)
at org.testng.TestNG.runSuitesSequentially(TestNG.java:1244)
at org.testng.TestNG.runSuitesLocally(TestNG.java:1169)
at org.testng.TestNG.run(TestNG.java:1064)
at org.testng.remote.RemoteTestNG.run(RemoteTestNG.java:113)
at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:206)
at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:177)
SKIPPED: SKIP
===============================================
Default test
Tests run: 1, Failures: 0, Skips: 1
Configuration Failures: 1, Skips: 0
===============================================
===============================================
Default suite
Total tests run: 1, Failures: 0, Skips: 1
Configuration Failures: 1, Skips: 0
===============================================
[TestNG] Time taken by org.testng.reporters.JUnitReportReporter@2a098129: 15 ms
[TestNG] Time taken by org.testng.reporters.EmailableReporter2@16b4a017: 5 ms
[TestNG] Time taken by org.testng.reporters.jq.Main@68f7aae2: 17 ms
[TestNG] Time taken by org.testng.reporters.SuiteHTMLReporter@2f410acf: 7 ms
[TestNG] Time taken by org.testng.reporters.XMLReporter@1996cd68: 6 ms
[TestNG] Time taken by [FailedReporter passed=0 failed=0 skipped=0]: 2 ms
推荐答案
您的系统中可能存在重复的 adb 二进制文件
There may be duplicates of adb binaries in your system
首先删除所有 adb 二进制文件
First remove all adb binaries
sudo apt-get purge --auto-remove android-tools-adb
然后下载最新版本的 android sdk 平台工具并再次尝试运行您的脚本..
Then download latest version of android sdk platform tools and try running your script again..
确保你在你的环境路径中设置了android sdk home
Make sure you set android sdk home in your environment path
这篇关于无法在设备上运行我的代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!