无法在ubuntu中为Eclipse中的Android项目运行appium

时间:2017-01-23 17:02:34

标签: android automated-tests appium

这是我的java类,我试图在ubuntu中使用控制台运行Appium但由于所需的功能而无法创建新的远程会话(查看屏幕截图)

import java.net.MalformedURLException;
import java.net.URL;
import java.util.concurrent.TimeUnit;


import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.remote.RemoteWebDriver;


public class FirstTest {

    WebDriver driver;

    @BeforeClass
    public void setUp() throws MalformedURLException{
        DesiredCapabilities capabilities = new DesiredCapabilities();
        capabilities.setCapability("deviceName", "SM-G360H");       
        capabilities.setCapability("version", "4.4.4");
        capabilities.setCapability("platformName", "Android");
        capabilities.setCapability("platformVersion", "platform");
        capabilities.setCapability("udid", "************");
        capabilities.setCapability("appPackage", "com.bulldozer.gaa");
        capabilities.setCapability("appActivity", "com.bulldozer.gaa.activities.MainActivity");
        driver = new RemoteWebDriver(new URL("http://0.0.0.0:4723/wd/hub"),capabilities);
        driver.manage().timeouts().implicitlyWait(15, TimeUnit.SECONDS);
    }

    @Test 
    public void Test1() throws InterruptedException {

        //driver.wait(10000);
        System.out.println("GAA");
        driver.findElement(By.id("acceptCheckbox")).click();
        driver.findElement(By.id("continueBtn")).click();

    }

    @AfterClass
    public void tearDown() {
        driver.quit();

    }

}

这是我在控制台中用于运行Appium的代码。我正在使用Appium 1.6.3版本(最新版本)。

appium --default-capabilities '{"app":"gaa","appium-version":"1.6.3","platformName":"Android","deviceName":"SM-G360H","nativeInstrumentsLib":true}' --command-timeout "0" --pre-launch





   [TestNG] Running:
  /tmp/testng-eclipse-1594673304/testng-customsuite.xml

Jan 23, 2017 5:55:43 PM org.openqa.selenium.remote.ProtocolHandshake createSession
INFO: Attempting bi-dialect session, assuming Postel's Law holds true on the remote end
Jan 23, 2017 5:55:43 PM org.openqa.selenium.remote.ProtocolHandshake createSession
INFO: Falling back to original OSS JSON Wire Protocol.
Jan 23, 2017 5:55:43 PM org.openqa.selenium.remote.ProtocolHandshake createSession
INFO: Falling back to straight W3C remote end connection
FAILED CONFIGURATION: @BeforeClass setUp
org.openqa.selenium.SessionNotCreatedException: Unable to create new remote session. desired capabilities = Capabilities [{appPackage=com.bulldozer.gaa, appActivity=com.bulldozer.gaa.activities.MainActivity, udid=************}], required capabilities = Capabilities [{}]
Build info: version: '3.0.1', revision: '1969d75', time: '2016-10-18 09:48:19 -0700'
System info: host: 'tarek-Vostro-3902', ip: '127.0.1.1', os.name: 'Linux', os.arch: 'amd64', os.version: '4.4.0-59-generic', java.version: '1.8.0_91'
Driver info: driver.version: RemoteWebDriver
    at org.openqa.selenium.remote.ProtocolHandshake.createSession(ProtocolHandshake.java:91)
    at org.openqa.selenium.remote.HttpCommandExecutor.execute(HttpCommandExecutor.java:141)
    at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:601)
    at org.openqa.selenium.remote.RemoteWebDriver.startSession(RemoteWebDriver.java:241)
    at org.openqa.selenium.remote.RemoteWebDriver.<init>(RemoteWebDriver.java:128)
    at org.openqa.selenium.remote.RemoteWebDriver.<init>(RemoteWebDriver.java:155)
    at FirstTest.setUp(FirstTest.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:498)
    at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:85)
    at org.testng.internal.Invoker.invokeConfigurationMethod(Invoker.java:517)
    at org.testng.internal.Invoker.invokeConfigurations(Invoker.java:213)
    at org.testng.internal.Invoker.invokeConfigurations(Invoker.java:140)
    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:771)
    at org.testng.TestRunner.run(TestRunner.java:621)
    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:1199)
    at org.testng.TestNG.runSuitesLocally(TestNG.java:1124)
    at org.testng.TestNG.run(TestNG.java:1032)
    at org.testng.remote.AbstractRemoteTestNG.run(AbstractRemoteTestNG.java:132)
    at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:236)
    at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:81)

SKIPPED CONFIGURATION: @AfterClass tearDown
SKIPPED: Test1

===============================================
    Default test
    Tests run: 1, Failures: 0, Skips: 1
    Configuration Failures: 1, Skips: 1
===============================================


===============================================
Default suite
Total tests run: 1, Failures: 0, Skips: 1
Configuration Failures: 1, Skips: 1
===============================================

[TestNG] Time taken by org.testng.reporters.EmailableReporter2@47f37ef1: 6 ms
[TestNG] Time taken by [FailedReporter passed=0 failed=0 skipped=0]: 2 ms
[TestNG] Time taken by org.testng.reporters.SuiteHTMLReporter@7907ec20: 8 ms
[TestNG] Time taken by org.testng.reporters.jq.Main@6ea6d14e: 15 ms
[TestNG] Time taken by org.testng.reporters.JUnitReportReporter@4563e9ab: 3 ms
[TestNG] Time taken by org.testng.reporters.XMLReporter@d7b1517: 3 ms

This is the error i got :

2 个答案:

答案 0 :(得分:1)

您正在使用的构造函数

According to source应该是要测试的端点的远程 ip。

public RemoteWebDriver(URL remoteAddress ...

您是否可以尝试将0.0.0.0 uri更改为要测试的设备的有效IP /主机?

修改

如果这不是问题,我会看到错误

  

at org.openqa.selenium.remote.ProtocolHandshake.createSession(ProtocolHandshake.java:91)

协议握手让我觉得您的服务器也可能正在侦听https请求,而您正尝试通过http建立连接?

尝试将您的uri从http更改为https

答案 1 :(得分:0)

问题来自.apk文件本身!我已经改变了另一个文件,它工作正常