InvocationTargetExceptionMessage 是:无法创建新会话,因为 'createSession' 错误

InvocationTargetExceptionMessage is : It is impossible to create a new session because 'createSession' error

我正在尝试为 运行 关闭 Appium 设置一个简单的 selenium 框架。测试应该只在 android 设备上打开 Chrome。我已经创建了我的基类,不幸的是我们返回了一个错误

我原以为这个问题和URL也就是http://0.0.0.0:4723/wd/hub有关,改了还是报错。我也更改了我的 Java 版本客户端,但每次我这样做都会出现另一个错误!!

我的Appium版本如下..

[Appium] 欢迎使用 Appium v​​1.14.2 [Appium] Appium REST http 接口侦听器启动于 0.0.0.0:4723

这是我的基类

package tests;

import java.net.URL;

import org.openqa.selenium.remote.DesiredCapabilities;
import org.testng.annotations.AfterTest;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test;

import io.appium.java_client.AppiumDriver;
import io.appium.java_client.MobileElement;
import io.appium.java_client.remote.MobileCapabilityType;

public class BaseClass {


    AppiumDriver<MobileElement> driver;

    @BeforeTest
    public void setup() {

        try {

        DesiredCapabilities caps = new DesiredCapabilities();

        caps.setCapability(MobileCapabilityType.PLATFORM_NAME, "ANDROID");
        caps.setCapability(MobileCapabilityType.VERSION, "6.0.1");
        caps.setCapability(MobileCapabilityType.DEVICE_NAME, "Nexus 7");
        caps.setCapability(MobileCapabilityType.UDID, "0911b4aa");
        caps.setCapability(MobileCapabilityType.NEW_COMMAND_TIMEOUT, 60);
   //       caps.setCapability(MobileCapabilityType.APP, "");
        caps.setCapability(MobileCapabilityType.BROWSER_NAME, "Chrome");
        URL url = new URL("http://0.0.0.0:4723/wd/hub");

        driver = new AppiumDriver<MobileElement>(url,caps);


        }catch(Exception  exp) {
            System.out.append("cause is  : "+exp.getCause());
            System.out.append("Message is : "+exp.getMessage());
            exp.printStackTrace();
        }
    }
    @Test
    public void sampleTest() {
        System.out.print("I am running a test");
    }

    @AfterTest
    public void teardown() {
        driver.close();
        driver.quit();

    }

}

这是我的 POM 文件...

<project xmlns="http://maven.apache.org/POM/4.0.0"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
        <modelVersion>4.0.0</modelVersion>
        <groupId>Android_F1_TV</groupId>
        <artifactId>Android_F1_TV</artifactId>
        <version>0.0.1-SNAPSHOT</version>

        <dependencies>

            <!-- https://mvnrepository.com/artifact/io.appium/java-client -->
            <dependency>
                <groupId>io.appium</groupId>
                <artifactId>java-client</artifactId>
                <version>6.1.0</version>
            </dependency>

            <!-- https://mvnrepository.com/artifact/org.seleniumhq.selenium/selenium-java -->
            <dependency>
                <groupId>org.seleniumhq.selenium</groupId>
                <artifactId>selenium-java</artifactId>
                <version>3.14.0</version>
            </dependency>

            <!-- https://mvnrepository.com/artifact/org.testng/testng -->
            <dependency>
                <groupId>org.testng</groupId>
                <artifactId>testng</artifactId>
                <version>7.0.0</version>
                <scope>test</scope>
            </dependency>

        </dependencies>

    </project>

返回的错误是.....

    [RemoteTestNG] detected TestNG version 7.0.0
cause is  : java.lang.reflect.InvocationTargetExceptionMessage is : It is impossible to create a new session because 'createSession' which takes HttpClient, InputStream and long was not found or it is not accessible
Build info: version: '3.12.0', revision: '7c6e0b3', time: '2018-05-08T14:04:26.12Z'
System info: host: 'Taylers-MacBook-Pro.local', ip: 'fe80:0:0:0:1c63:8428:5e15:4731%en0', os.name: 'Mac OS X', os.arch: 'x86_64', os.version: '10.14.6', java.version: '1.8.0_221'
Driver info: driver.version: AppiumDriverorg.openqa.selenium.WebDriverException: It is impossible to create a new session because 'createSession' which takes HttpClient, InputStream and long was not found or it is not accessible
Build info: version: '3.12.0', revision: '7c6e0b3', time: '2018-05-08T14:04:26.12Z'
System info: host: 'Taylers-MacBook-Pro.local', ip: 'fe80:0:0:0:1c63:8428:5e15:4731%en0', os.name: 'Mac OS X', os.arch: 'x86_64', os.version: '10.14.6', java.version: '1.8.0_221'
Driver info: driver.version: AppiumDriver
    at io.appium.java_client.remote.AppiumCommandExecutor.createSession(AppiumCommandExecutor.java:195)
    at io.appium.java_client.remote.AppiumCommandExecutor.createSession(AppiumCommandExecutor.java:209)
    at io.appium.java_client.remote.AppiumCommandExecutor.execute(AppiumCommandExecutor.java:231)
    at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:543)
    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:207)
    at org.openqa.selenium.remote.RemoteWebDriver.<init>(RemoteWebDriver.java:130)
    at io.appium.java_client.DefaultGenericMobileDriver.<init>(DefaultGenericMobileDriver.java:38)
    at io.appium.java_client.AppiumDriver.<init>(AppiumDriver.java:84)
    at io.appium.java_client.AppiumDriver.<init>(AppiumDriver.java:94)
    at tests.BaseClass.setup(BaseClass.java:35)
    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:133)
    at org.testng.internal.MethodInvocationHelper.invokeMethodConsideringTimeout(MethodInvocationHelper.java:62)
    at org.testng.internal.ConfigInvoker.invokeConfigurationMethod(ConfigInvoker.java:340)
    at org.testng.internal.ConfigInvoker.invokeConfigurations(ConfigInvoker.java:294)
    at org.testng.TestRunner.invokeTestConfigurations(TestRunner.java:623)
    at org.testng.TestRunner.beforeRun(TestRunner.java:613)
    at org.testng.TestRunner.run(TestRunner.java:584)
    at org.testng.SuiteRunner.runTest(SuiteRunner.java:402)
    at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:396)
    at org.testng.SuiteRunner.privateRun(SuiteRunner.java:355)
    at org.testng.SuiteRunner.run(SuiteRunner.java:304)
    at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:53)
    at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:96)
    at org.testng.TestNG.runSuitesSequentially(TestNG.java:1180)
    at org.testng.TestNG.runSuitesLocally(TestNG.java:1102)
    at org.testng.TestNG.runSuites(TestNG.java:1032)
    at org.testng.TestNG.run(TestNG.java:1000)
    at org.testng.remote.AbstractRemoteTestNG.run(AbstractRemoteTestNG.java:115)
    at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:251)
    at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:77)
Caused by: java.lang.reflect.InvocationTargetException
    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 io.appium.java_client.remote.AppiumCommandExecutor.createSession(AppiumCommandExecutor.java:185)
    ... 35 more
Caused by: org.openqa.selenium.WebDriverException: An unknown server-side error occurred while processing the command. Original error: Could not find 'aapt' in ["/usr/local/share/android-sdk/platform-tools/aapt","/usr/local/share/android-sdk/emulator/aapt","/usr/local/share/android-sdk/tools/aapt","/usr/local/share/android-sdk/tools/bin/aapt"]. Do you have Android Build Tools installed at '/usr/local/share/android-sdk'?
Build info: version: '3.12.0', revision: '7c6e0b3', time: '2018-05-08T14:04:26.12Z'
System info: host: 'Taylers-MacBook-Pro.local', ip: 'fe80:0:0:0:1c63:8428:5e15:4731%en0', os.name: 'Mac OS X', os.arch: 'x86_64', os.version: '10.14.6', java.version: '1.8.0_221'
Driver info: driver.version: AppiumDriver
remote stacktrace: UnknownError: An unknown server-side error occurred while processing the command. Original error: Could not find 'aapt' in ["/usr/local/share/android-sdk/platform-tools/aapt","/usr/local/share/android-sdk/emulator/aapt","/usr/local/share/android-sdk/tools/aapt","/usr/local/share/android-sdk/tools/bin/aapt"]. Do you have Android Build Tools installed at '/usr/local/share/android-sdk'?
    at getResponseForW3CError (/usr/local/lib/node_modules/appium/node_modules/appium-base-driver/lib/protocol/errors.js:826:9)
    at asyncHandler (/usr/local/lib/node_modules/appium/node_modules/appium-base-driver/lib/protocol/protocol.js:447:37)
    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:423)
    at org.openqa.selenium.remote.W3CHandshakeResponse.lambda$new[=13=](W3CHandshakeResponse.java:57)
    at org.openqa.selenium.remote.W3CHandshakeResponse.lambda$getResponseFunction(W3CHandshakeResponse.java:104)
    at org.openqa.selenium.remote.ProtocolHandshake.lambda$createSession[=13=](ProtocolHandshake.java:123)
    at java.util.stream.ReferencePipeline.accept(ReferencePipeline.java:193)
    at java.util.Spliterators$ArraySpliterator.tryAdvance(Spliterators.java:958)
    at java.util.stream.ReferencePipeline.forEachWithCancel(ReferencePipeline.java:126)
    at java.util.stream.AbstractPipeline.copyIntoWithCancel(AbstractPipeline.java:499)
    at java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:486)
    at java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:472)
    at java.util.stream.FindOps$FindOp.evaluateSequential(FindOps.java:152)
    at java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234)
    at java.util.stream.ReferencePipeline.findFirst(ReferencePipeline.java:464)
    at org.openqa.selenium.remote.ProtocolHandshake.createSession(ProtocolHandshake.java:126)
    ... 40 more
I am running a testFAILED CONFIGURATION: @AfterTest teardown
java.lang.NullPointerException
    at tests.BaseClass.teardown(BaseClass.java:51)
    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:133)
    at org.testng.internal.MethodInvocationHelper.invokeMethodConsideringTimeout(MethodInvocationHelper.java:62)
    at org.testng.internal.ConfigInvoker.invokeConfigurationMethod(ConfigInvoker.java:340)
    at org.testng.internal.ConfigInvoker.invokeConfigurations(ConfigInvoker.java:294)
    at org.testng.TestRunner.invokeTestConfigurations(TestRunner.java:623)
    at org.testng.TestRunner.afterRun(TestRunner.java:853)
    at org.testng.TestRunner.run(TestRunner.java:594)
    at org.testng.SuiteRunner.runTest(SuiteRunner.java:402)
    at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:396)
    at org.testng.SuiteRunner.privateRun(SuiteRunner.java:355)
    at org.testng.SuiteRunner.run(SuiteRunner.java:304)
    at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:53)
    at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:96)
    at org.testng.TestNG.runSuitesSequentially(TestNG.java:1180)
    at org.testng.TestNG.runSuitesLocally(TestNG.java:1102)
    at org.testng.TestNG.runSuites(TestNG.java:1032)
    at org.testng.TestNG.run(TestNG.java:1000)
    at org.testng.remote.AbstractRemoteTestNG.run(AbstractRemoteTestNG.java:115)
    at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:251)
    at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:77)

PASSED: sampleTest

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


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

    enter code here

我可以在错误响应中看到提到了 AAPT,这与 Android SDK 有关。这是我的 .profile 文件,其中存储了我的 SDK 信息...

在路径环境变量中添加平台工具文件夹的路径 导出 PATH="/usr/local/Caskroom/android-sdk/4333796/platform-tools:$PATH"

正在为 ANDROID_HOME 设置 PATH 导出 ANDROID_HOME="/usr/local/share/android-sdk"

错误似乎是没有找到 class LoggingHandler。 class 通常在 selenium-api 依赖项中。您可以尝试使用 2.53.1 版本而不是 3.4.0。该版本缺少 class.

<dependency>
    <groupId>org.seleniumhq.selenium</groupId>
    <artifactId>selenium-api</artifactId>
    <version>2.53.1</version>
</dependency>