在Mac上,Appium服务器将无法通过Java从Eclipse启动

时间:2018-07-13 17:42:14

标签: java server appium

当我尝试使用Java从e​​clipse启动我的Appium服务器时,出现失败消息“ org.openqa.selenium.WebDriverException:连接被拒绝” 我一直对此感到困惑,无法弄清楚自己在做什么错。任何帮助将不胜感激

这是控制台日志:

[INFO] Scanning for projects...
[INFO]                                                                         
[INFO] ------------------------------------------------------------------------
[INFO] Building TestngCucumberBoilerPlate 0.0.1-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO] 
[INFO] --- maven-resources-plugin:2.7:resources (default-resources) @ TestngCucumberBoilerPlate ---
[WARNING] File encoding has not been set, using platform encoding UTF-8, i.e. build is platform dependent!
[WARNING] Using platform encoding (UTF-8 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] skip non existing resourceDirectory /Users/<redacted>/Documents/BlueprintTestngCucumber/src/main/resources
[INFO] 
[INFO] --- maven-compiler-plugin:3.2:compile (default-compile) @ TestngCucumberBoilerPlate ---
[INFO] Nothing to compile - all classes are up to date
[INFO] 
[INFO] --- maven-resources-plugin:2.7:testResources (default-testResources) @ TestngCucumberBoilerPlate ---
[WARNING] File encoding has not been set, using platform encoding UTF-8, i.e. build is platform dependent!
[WARNING] Using platform encoding (UTF-8 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] Copying 6 resources
[INFO] 
[INFO] --- maven-compiler-plugin:3.2:testCompile (default-testCompile) @ TestngCucumberBoilerPlate ---
[INFO] Nothing to compile - all classes are up to date
[INFO] 
[INFO] --- maven-surefire-plugin:2.18.1:test (default-test) @ TestngCucumberBoilerPlate ---
[INFO] Surefire report directory: /Users/<redacted>/Documents/BlueprintTestngCucumber/target/surefire-reports

-------------------------------------------------------
 T E S T S
-------------------------------------------------------
Running TestSuite
entered start server
commands given
Attempting to start server
Appium server started.
capabilities Set.
cucumberrunner.takescreenshot
Tests run: 5, Failures: 3, Errors: 0, Skipped: 2, Time elapsed: 6.01 sec <<< FAILURE! - in TestSuite
setUp(main.CucumberRunner)  Time elapsed: 5.702 sec  <<< FAILURE!
org.openqa.selenium.WebDriverException: Connection refused
Build info: version: '3.5.2', revision: '10229a9', time: '2017-08-21T17:29:55.15Z'
System info: host: '<redacted>-0046.local', ip: 'fe80:0:0:0:1048:a7a5:ee69:6124%en0', os.name: 'Mac OS X', os.arch: 'x86_64', os.version: '10.13.4', java.version: '1.8.0_77'
Driver info: driver.version: AppiumDriver
    at java.net.PlainSocketImpl.socketConnect(Native Method)
    at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:350)
    at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:206)
    at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:188)
    at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392)
    at java.net.Socket.connect(Socket.java:589)
    at org.apache.http.conn.socket.PlainConnectionSocketFactory.connectSocket(PlainConnectionSocketFactory.java:75)
    at org.apache.http.impl.conn.DefaultHttpClientConnectionOperator.connect(DefaultHttpClientConnectionOperator.java:142)
    at org.apache.http.impl.conn.PoolingHttpClientConnectionManager.connect(PoolingHttpClientConnectionManager.java:359)
    at org.apache.http.impl.execchain.MainClientExec.establishRoute(MainClientExec.java:381)
    at org.apache.http.impl.execchain.MainClientExec.execute(MainClientExec.java:237)
    at org.apache.http.impl.execchain.ProtocolExec.execute(ProtocolExec.java:185)
    at org.apache.http.impl.execchain.RetryExec.execute(RetryExec.java:89)
    at org.apache.http.impl.execchain.RedirectExec.execute(RedirectExec.java:111)
    at org.apache.http.impl.client.InternalHttpClient.doExecute(InternalHttpClient.java:185)
    at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:72)
    at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:56)
    at org.openqa.selenium.remote.internal.ApacheHttpClient.fallBackExecute(ApacheHttpClient.java:139)
    at org.openqa.selenium.remote.internal.ApacheHttpClient.execute(ApacheHttpClient.java:87)
    at org.openqa.selenium.remote.ProtocolHandshake.createSession(ProtocolHandshake.java:337)
    at org.openqa.selenium.remote.ProtocolHandshake.createSession(ProtocolHandshake.java:136)
    at org.openqa.selenium.remote.HttpCommandExecutor.execute(HttpCommandExecutor.java:142)
    at io.appium.java_client.remote.AppiumCommandExecutor.execute(AppiumCommandExecutor.java:89)
    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 org.openqa.selenium.remote.RemoteWebDriver.startSession(RemoteWebDriver.java:254)
    at org.openqa.selenium.remote.RemoteWebDriver.startSession(RemoteWebDriver.java:236)
    at org.openqa.selenium.remote.RemoteWebDriver.<init>(RemoteWebDriver.java:137)
    at io.appium.java_client.DefaultGenericMobileDriver.<init>(DefaultGenericMobileDriver.java:38)
    at io.appium.java_client.AppiumDriver.<init>(AppiumDriver.java:83)
    at io.appium.java_client.AppiumDriver.<init>(AppiumDriver.java:93)
    at main.CucumberRunner.setUp(CucumberRunner.java:231)

takeScreenshot(main.CucumberRunner)  Time elapsed: 0.002 sec  <<< FAILURE!
java.lang.NullPointerException: null
    at main.CucumberRunner.takeScreenshot(CucumberRunner.java:300)

quit(main.CucumberRunner)  Time elapsed: 0.021 sec  <<< FAILURE!
java.lang.NullPointerException: null
    at main.CucumberRunner.quit(CucumberRunner.java:336)


Results :

Failed tests: 
  CucumberRunner.quit:336 NullPointer
  CucumberRunner.setUp:231 » WebDriver Connection refused
Build info: version: '...
  CucumberRunner.takeScreenshot:300 NullPointer

Tests run: 5, Failures: 3, Errors: 0, Skipped: 2

[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 10.736 s
[INFO] Finished at: 2018-07-13T13:00:57-04:00
[INFO] Final Memory: 29M/1206M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.18.1:test (default-test) on project TestngCucumberBoilerPlate: There are test failures.
[ERROR] 
[ERROR] Please refer to /Users/<redacted>/Documents/BlueprintTestngCucumber/target/surefire-reports for the individual test results.
[ERROR] -> [Help 1]
[ERROR] 
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR] 
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoFailureException

这是我的Appium服务器类代码。每当我启动服务器,然后尝试连接到服务器时,都会收到错误消息。

公共类AppiumServer {

public void startServer() {
    System.out.println("entered start server");
    CommandLine command = new CommandLine(
            "/Applications/Appium.app/Contents/Resources/node/bin/node");
    command.addArgument(
            "/Applications/Appium.app/Contents/Resources/node_modules/appium/bin/appium.js",
            false);
    command.addArgument("--address", false);
    //command.addArgument("http://localhost:");
    command.addArgument("127.0.0.1");
    command.addArgument("--port", false);
    command.addArgument("4723");
    command.addArgument("--full-reset", false);
    System.out.println("commands given");
    DefaultExecuteResultHandler resultHandler = new DefaultExecuteResultHandler();




    DefaultExecutor executor = new DefaultExecutor();
    executor.setExitValue(1);
    System.out.println("Attempting to start server");
    try {
        executor.execute(command, resultHandler);


        Thread.sleep(5000);
        System.out.println("Appium server started.");
    } catch (IOException e) {
        e.printStackTrace();
    } catch (InterruptedException e) {
        e.printStackTrace();
    }
}

public void stopServer() {
    String[] command = { "/usr/bin/killall", "-KILL", "node" };
    try {
        Runtime.getRuntime().exec(command);
        System.out.println("Appium server stopped.");
    } catch (IOException e) {
        e.printStackTrace();
    }
}

}

这里是调用类,直到失败为止。如果我通过打开Appium手动启动服务器,则该类成功连接。我很确定当我尝试通过Eclipse启动服务器时,服务器没有启动。

public static AppiumServer server = new AppiumServer();
@BeforeSuite
public void setUp() throws MalformedURLException {

System.out.println("Before suite started.");

server.startServer();

DesiredCapabilities capabilities = new DesiredCapabilities();
    // Set ios deviceName desired capability. Set your device name.
    capabilities.setCapability("deviceName", "My iPhone");
    // Set BROWSER_NAME desired capability. It’s iOSin our case here.
    capabilities.setCapability(CapabilityType.BROWSER_NAME, "iOS");
    // Set iOS VERSION desired capability. Set your mobile device’s OS version.
    capabilities.setCapability(CapabilityType.VERSION, "11.2.6");
    // Set iOS platformName desired capability. It’s Android in our case here.
    capabilities.setCapability("noReset", false);
    capabilities.setCapability("platformName", "iOS");
    //capabilities.setCapability("platformVersion", "7.1.1");
    // Set your application’s appPackage if you are using any other app.
    capabilities.setCapability("xcodeSigningId", "iPhone Developer");
    capabilities.setCapability("appActivity", "com.<redacted>.<redacted>.<redacted>");
    // It will launch app in iOS device.
    capabilities.setCapability("udid", "<redacted>");
    capabilities.setCapability("xcodeOrgId", "<redacted>");
    capabilities.setCapability("automationName", "XCUITest");
    capabilities.setCapability("bundleId", "com.<redacted>.<redacted>");
    System.out.println("capabilities Set.");


    driver = new AppiumDriver(new URL("http://127.0.0.1:4723/wd/hub"), capabilities);
    System.out.println("connection suceeded");

1 个答案:

答案 0 :(得分:0)

有几种可能的解决方案:

plt.plot_date表示Appium服务器由于某些原因无法处理传入的请求。

1。检查可能的本地问题

检查是否尚未启动相同的进程或具有相同端口的进程。

2。认为是基于服务器的

或者每次尝试都不运行Appium时,请尝试打开服务器并将其保留为服务器应该能够正常运行的所有时间,并在需要时处理请求。 在开始时,我还尝试通过编程方式运行服务器来尝试此方法,但实际上没有必要,它速度较慢,需要维护,并且必须始终启动。 我的观点是这很耗时,并且没有必要。从命令行/控制台启动它,有多种方法可以执行它,例如node.js,shell脚本,Appium服务器IDE。

这是最简单的命令(来自Mac)Connection refused

3。通过appium --address 127.0.0.1 --port 4723

可能的解决方案
AppiumDriverLocalService

注意:如果您使用的Appium版本是1.5.3或更高版本,则必须在环境变量中设置APPIUM_BINARY_PATH。

例如APPIUM_BINARY_PATH = ... \ node_modules \ appium \ build \ lib \ main.js

希望这会有所帮助,