在Eclipse中使用appium運行腳本作爲testng。它告訴我無法創建新會話。在Eclipse中使用appium運行腳本作爲testng。它告訴我無法創建新會話
的錯誤是如下:
FAILED CONFIGURATION: @BeforeClass setUp org.openqa.selenium.SessionNotCreatedException: A new session could not be created. (Original error: Could not find a connected Android device.) (WARNING: The server did not provide any stacktrace information) Command duration or timeout: 27.86 seconds Build info: version: '2.48.2', revision: '41bccdd', time: '2015-10-09 19:55:52' System info: host: 'Emnas-Mac.local', ip: '192.168.116.130', os.name: 'Mac OS X', os.arch: 'x86_64', os.version: '10.10.5', java.version: '1.8.0_65' Driver info: io.appium.java_client.android.AndroidDriver 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 io.appium.java_client.DefaultGenericMobileDriver.execute(DefaultGenericMobileDriver.java:42) at io.appium.java_client.AppiumDriver.execute(AppiumDriver.java:1) at io.appium.java_client.android.AndroidDriver.execute(AndroidDriver.java:1) at org.openqa.selenium.remote.RemoteWebDriver.startSession(RemoteWebDriver.java:247) at org.openqa.selenium.remote.RemoteWebDriver.(RemoteWebDriver.java:129) at org.openqa.selenium.remote.RemoteWebDriver.(RemoteWebDriver.java:142) at io.appium.java_client.DefaultGenericMobileDriver.(DefaultGenericMobileDriver.java:37) at io.appium.java_client.AppiumDriver.(AppiumDriver.java:161) at io.appium.java_client.AppiumDriver.(AppiumDriver.java:170) at io.appium.java_client.android.AndroidDriver.(AndroidDriver.java:82) at test.HomePage.setUp(HomePage.java:30) 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:85) at org.testng.internal.Invoker.invokeConfigurationMethod(Invoker.java:510) at org.testng.internal.Invoker.invokeConfigurations(Invoker.java:211) at org.testng.internal.Invoker.invokeConfigurations(Invoker.java:138) at org.testng.internal.TestMethodWorker.invokeBeforeClassMethods(TestMethodWorker.java:170) at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:104) at org.testng.TestRunner.privateRun(TestRunner.java:773) at org.testng.TestRunner.run(TestRunner.java:623) at org.testng.SuiteRunner.runTest(SuiteRunner.java:357)
Here is my setup method:
AndroidDriver driver; //UiDevice mydevice = getUiDevice(); @BeforeClass public void setUp() throws MalformedURLException{ DesiredCapabilities capabilities = new DesiredCapabilities(); capabilities.setCapability("deviceName", "6b1cffac"); capabilities.setCapability("version", "5.0.1"); capabilities.setCapability("platformName", "Android"); capabilities.setCapability("appPackage", "MyPackage"); capabilities.setCapability("appActivity", "com.gtl.activity.SplashActivity"); driver = new AndroidDriver(new URL("http://127.0.0.1:4723/wd/hub"),capabilities); driver.manage().timeouts().implicitlyWait(15, TimeUnit.SECONDS);}
I also get this exception : [TestNG] Running: /private/var/folders/b4/4xhr5zcs3y75f17swbzvkbj40000gn/T/testng-eclipse-661364855/testng-customsuite.xml
FAILED CONFIGURATION: @BeforeClass setUp org.openqa.selenium.remote.UnreachableBrowserException: Could not start a new session. Possible causes are invalid address of the remote server or browser start-up failure. Build info: version: '2.48.2', revision: '41bccdd', time: '2015-10-09 19:55:52' System info: host: 'Emnas-Mac.local', ip: '192.168.116.130', os.name: 'Mac OS X', os.arch: 'x86_64', os.version: '10.10.5', java.version: '1.8.0_65' Driver info: driver.version: AndroidDriver at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:641) at io.appium.java_client.DefaultGenericMobileDriver.execute(DefaultGenericMobileDriver.java:42) at io.appium.java_client.AppiumDriver.execute(AppiumDriver.java:1) at io.appium.java_client.android.AndroidDriver.execute(AndroidDriver.java:1) at org.openqa.selenium.remote.RemoteWebDriver.startSession(RemoteWebDriver.java:247) at org.openqa.selenium.remote.RemoteWebDriver.(RemoteWebDriver.java:129) at org.openqa.selenium.remote.RemoteWebDriver.(RemoteWebDriver.java:142) at io.appium.java_client.DefaultGenericMobileDriver.(DefaultGenericMobileDriver.java:37) at io.appium.java_client.AppiumDriver.(AppiumDriver.java:161) at io.appium.java_client.AppiumDriver.(AppiumDriver.java:170) at io.appium.java_client.android.AndroidDriver.(AndroidDriver.java:82) at test.HomePage.setUp(HomePage.java:30) 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:85) at org.testng.internal.Invoker.invokeConfigurationMethod(Invoker.java:510) at org.testng.internal.Invoker.invokeConfigurations(Invoker.java:211) at org.testng.internal.Invoker.invokeConfigurations(Invoker.java:138) at org.testng.internal.TestMethodWorker.invokeBeforeClassMethods(TestMethodWorker.java:170) at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:104) at org.testng.TestRunner.privateRun(TestRunner.java:773) at org.testng.TestRunner.run(TestRunner.java:623) at org.testng.SuiteRunner.runTest(SuiteRunner.java:357) at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:352) at org.testng.SuiteRunner.privateRun(SuiteRunner.java:310) at org.testng.SuiteRunner.run(SuiteRunner.java:259) at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52) at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:86) at org.testng.TestNG.runSuitesSequentially(TestNG.java:1185) at org.testng.TestNG.runSuitesLocally(TestNG.java:1110) at org.testng.TestNG.run(TestNG.java:1018) at org.testng.remote.RemoteTestNG.run(RemoteTestNG.java:111) at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:204) at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:175) Caused by: org.openqa.selenium.WebDriverException: org.apache.http.conn.HttpHostConnectException: Connect to 127.0.0.1:4723 [/127.0.0.1] failed: Connection refused Build info: version: '2.48.2', revision: '41bccdd', time: '2015-10-09 19:55:52' System info: host: 'Emnas-Mac.local', ip: '192.168.116.130', os.name: 'Mac OS X', os.arch: 'x86_64', os.version: '10.10.5', java.version: '1.8.0_65' Driver info: driver.version: AndroidDriver at io.appium.java_client.remote.AppiumCommandExecutor.execute(AppiumCommandExecutor.java:79) at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:620)
我的問題是,代碼運行正常,如果我收appium並重新啓動它,清理,建造我的Eclipse項目。因此,如果我再次運行一個異常。每次我想運行我的腳本時,我是否有義務重啓appium並清理我的項目?
你可以分享你的代碼? – Paras
「找不到連接的Android設備。」是你最大的線索。要麼啓動的AVD沒有啓動,要麼無法找到連接的設備。如果是AVD,請重新檢查您的ANDROID_HOME路徑,並/或手動啓動它。如果它是連接的設備,請確保開發人員工具已打開並啓用了USB調試。 – econoMichael
運行appium-doctor檢查所有環境變量是否設置正確,在開始測試前檢查「adb設備」確保設備已連接。 – Manidroid