首页 > 解决方案 > 模拟器没有在 Appium 框架中启动抛出 InvocationTargetExceptionMessage

问题描述

我用黄瓜和我的“Appium Emulator”类和POM配置创建了Appium框架,如下所示。

我的 Emulator 类在接受所需功能后抛出 Java.lang.InvocationTargetExceptionMessage 。有人可以帮我吗?

请检查服务器日志以获取更多详细信息。

//Launching the emulator
 

    package com.TWG.nlapp.stepDefinitions.Cucumber;

    import io.appium.java_client.AppiumDriver;
    import io.appium.java_client.remote.AndroidMobileCapabilityType;
    import io.appium.java_client.remote.MobileCapabilityType;
    import io.cucumber.java.After;
    import org.openqa.selenium.Platform;
    import org.openqa.selenium.remote.DesiredCapabilities;

    import java.io.File;
    import java.net.URL;
    
    public class AppiumEmulator {
         AppiumDriver driver;
    
        // To start the emulator
        @Before
        public void setUp() throws Exception {
    
            try {
                File appDir = new File("src/test/resources/");
                File app = new File(appDir, "SampleApp.apk");
         
                DesiredCapabilities capabilities = new DesiredCapabilities();
                capabilities.setCapability(MobileCapabilityType.APP, app.getAbsolutePath());
                capabilities.setCapability(MobileCapabilityType.DEVICE_NAME, "emulator-5554");
                capabilities.setCapability(MobileCapabilityType.AUTOMATION_NAME, "UiAutomator2");
                capabilities.setCapability(MobileCapabilityType.NEW_COMMAND_TIMEOUT, 120);
                capabilities.setCapability(AndroidMobileCapabilityType.APP_ACTIVITY, "nz.co.SampleApp.mynlapp.MainActivity");
                capabilities.setCapability(AndroidMobileCapabilityType.APP_PACKAGE, "nz.co.SampleApp.mynlapp.qat");
                // capabilities.setCapability(AndroidMobileCapabilityType.APP_WAIT_ACTIVITY, "com.tuenti.messenger.ui.activity.MainActivity,com.tuenti.messenger.ui.activity.MainActivity,com.tuenti.messenger.secure.session.view.PinActivity");
                capabilities.setCapability(MobileCapabilityType.PLATFORM_NAME, Platform.ANDROID);
                capabilities.setCapability(MobileCapabilityType.NO_RESET, true);   
                capabilities.setCapability(MobileCapabilityType.FULL_RESET, false);  //app get installed and uninstalled everytime
               // driver = new AndroidDriver(new URL("http://127.0.0.1:4723/wd/hub"), capabilities);
                driver = new AppiumDriver(new URL("http://127.0.0.1:4723/wd/hub"), capabilities);
            } catch (Exception exp) {
                System.out.append("cause is  : " + exp.getCause());
                System.out.append("Message is : " + exp.getMessage());
                exp.printStackTrace();
            }
        }
        @After
        public void tearDown() throws Exception {
            driver.quit();
        }
    
    }"


    but my  logs shows:
    org.openqa.selenium.SessionNotCreatedException: Unable to create a new remote session. Please check the server log for more details. Original error: An unknown server-side error occurred while processing the command. Original error: The application at '/Users/390099/repo/mob-qa-nlapp-android/src/test/resources/NoelLeeming-qat-release.apk' does not exist or is not accessible
    Build info: version: '3.141.59', revision: 'e82be7d358', time: '2018-11-14T08:17:03'
    System info: host: 'ITM305500', ip: '2406:e003:11f7:9701:d8c4:c192:7ebd:1b6%en0', os.name: 'Mac OS X', os.arch: 'x86_64', os.version: '10.15.7', java.version: '1.8.0_242-release'
    Driver info: driver.version: AppiumDriver
    remote stacktrace: UnknownError: An unknown server-side error occurred while processing the command. Original error: The application at '/Users/390099/repo/mob-qa-nlapp-android/src/test/resources/NoelLeeming-qat-release.apk' does not exist or is not accessible
        at getResponseForW3CError (/usr/local/lib/node_modules/appium/node_modules/appium-base-driver/lib/protocol/errors.js:804:9)
        at asyncHandler (/usr/local/lib/node_modules/appium/node_modules/appium-base-driver/lib/protocol/protocol.js:380:37)
    Build info: version: '3.141.59', revision: 'e82be7d358', time: '2018-11-14T08:17:03'
    System info: host: 'ITM305500', ip: '2406:e003:11f7:9701:d8c4:c192:7ebd:1b6%en0', os.name: 'Mac OS X', os.arch: 'x86_64', os.version: '10.15.7', java.version: '1.8.0_242-release'
    Driver info: driver.version: AppiumDriver
        at io.appium.java_client.remote.AppiumCommandExecutor$1.createSession(AppiumCommandExecutor.java:208)
        at io.appium.java_client.remote.AppiumCommandExecutor.createSession(AppiumCommandExecutor.java:217)
        at io.appium.java_client.remote.AppiumCommandExecutor.execute(AppiumCommandExecutor.java:239)
        at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:552)
        at io.appium.java_client.DefaultGenericMobileDriver.execute(DefaultGenericMobileDriver.java:41)
        at io.appium.java_client.AppiumDriver.execute(AppiumDriver.java:1)
        at org.openqa.selenium.remote.RemoteWebDriver.startSession(RemoteWebDriver.java:213)
        at io.appium.java_client.AppiumDriver.startSession(AppiumDriver.java:336)
        at org.openqa.selenium.remote.RemoteWebDriver.<init>(RemoteWebDriver.java:131)
        at io.appium.java_client.DefaultGenericMobileDriver.<init>(DefaultGenericMobileDriver.java:37)
        at io.appium.java_client.AppiumDriver.<init>(AppiumDriver.java:88)
        at io.appium.java_client.AppiumDriver.<init>(AppiumDriver.java:98)
        at com.TWG.nlapp.stepDefinitions.Cucumber.AppiumEmulator.setUp(AppiumEmulator.java:37)
        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.cucumber.java.Invoker.doInvoke(Invoker.java:66)
        at io.cucumber.java.Invoker.invoke(Invoker.java:24)
        at io.cucumber.java.AbstractGlueDefinition.invokeMethod(AbstractGlueDefinition.java:44)
        at io.cucumber.java.JavaHookDefinition.execute(JavaHookDefinition.java:59)
        at io.cucumber.core.runner.CoreHookDefinition.execute(CoreHookDefinition.java:44)
        at io.cucumber.core.runner.HookDefinitionMatch.runStep(HookDefinitionMatch.java:21)
        at io.cucumber.core.runner.TestStep.executeStep(TestStep.java:92)
        at io.cucumber.core.runner.TestStep.run(TestStep.java:63)
        at io.cucumber.core.runner.TestCase.run(TestCase.java:94)
        at io.cucumber.core.runner.Runner.runPickle(Runner.java:71)
        at io.cucumber.junit.PickleRunners$NoStepDescriptions.run(PickleRunners.java:151)
        at io.cucumber.junit.FeatureRunner.runChild(FeatureRunner.java:135)
        at io.cucumber.junit.FeatureRunner.runChild(FeatureRunner.java:27)
        at org.junit.runners.ParentRunner$4.run(ParentRunner.java:331)
        at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:79)
        at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:329)
        at org.junit.runners.ParentRunner.access$100(ParentRunner.java:66)
        at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:293)
        at org.junit.runners.ParentRunner$3.evaluate(ParentRunner.java:306)
        at org.junit.runners.ParentRunner.run(ParentRunner.java:413)
        at io.cucumber.junit.CucumberSerenityRunner.runChild(CucumberSerenityRunner.java:234)
        at io.cucumber.junit.CucumberSerenityRunner.runChild(CucumberSerenityRunner.java:57)
        at org.junit.runners.ParentRunner$4.run(ParentRunner.java:331)
        at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:79)
        at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:329)
        at org.junit.runners.ParentRunner.access$100(ParentRunner.java:66)
        at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:293)
        at io.cucumber.junit.CucumberSerenityRunner$RunCucumber.evaluate(CucumberSerenityRunner.java:262)
        at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:26)
        at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:27)
        at org.junit.runners.ParentRunner$3.evaluate(ParentRunner.java:306)
        at org.junit.runners.ParentRunner.run(ParentRunner.java:413)
        at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
        at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:69)
        at com.intellij.rt.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:33)
        at com.intellij.rt.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:221)
        at com.intellij.rt.junit.JUnitStarter.main(JUnitStarter.java:54)
    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$1.createSession(AppiumCommandExecutor.java:186)
        ... 53 more
    Caused by: org.openqa.selenium.WebDriverException: An unknown server-side error occurred while processing the command. Original error: The application at '/Users/390099/repo/mob-qa-nlapp-android/src/test/resources/sampleApp.apk' does not exist or is not accessible
    Build info: version: '3.141.59', revision: 'e82be7d358', time: '2018-11-14T08:17:03'
    System info: host: 'ITM305500', ip: '2406:e003:11f7:9701:d8c4:c192:7ebd:1b6%en0', os.name: 'Mac OS X', os.arch: 'x86_64', os.version: '10.15.7', java.version: '1.8.0_242-release'
    Driver info: driver.version: AppiumDriver.
    

//下面是POM

    POM File
    <?xml version="1.0" encoding="UTF-8"?>
    <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>com.NL.Mobile</groupId>
        <artifactId>nlAndroidSerenityFramework</artifactId>
        <version>1.0.0-SNAPSHOT</version>
        <packaging>jar</packaging>
    
        <name>NL Android Serenity project using Cucumber and WebDriver</name>
    
        <properties>
            <serenity.version>2.3.12</serenity.version>
            <serenity.maven.version>2.3.12</serenity.maven.version>
            <serenity.cucumber.version>2.3.12</serenity.cucumber.version>
            <cucumber.version>6.9.1</cucumber.version>
            <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
            <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
            <webdriver.driver>appium</webdriver.driver>
            <!--suppress UnresolvedMavenProperty -->
            <build.number>${current.time}</build.number>
        </properties>
    
        <repositories>
          <repository>
            <snapshots>
                <enabled>false</enabled>
            </snapshots>
            <id>central</id>
            <name>bintray</name>
            <url>https://repo1.maven.org/maven2/</url>
          </repository>
        </repositories>
        
        <pluginRepositories>
          <pluginRepository>
            <snapshots>
            <enabled>false</enabled>
            </snapshots>
            <id>central</id>
            <name>bintray-plugins</name>
            <url>https://repo1.maven.org/maven2/</url>
          </pluginRepository>
        </pluginRepositories>
    
        <dependencies>
            <dependency>
                <groupId>net.serenity-bdd</groupId>
                <artifactId>serenity-core</artifactId>
                <version>${serenity.version}</version>
                <scope>test</scope>
                <exclusions>
                    <exclusion>
                        <groupId>io.cucumber</groupId>
                        <artifactId>cucumber-core</artifactId>
                    </exclusion>
                </exclusions>
            </dependency>
            <dependency>
                <groupId>net.serenity-bdd</groupId>
                <artifactId>serenity-cucumber6</artifactId>
                <version>${serenity.cucumber.version}</version>
                <scope>test</scope>
            </dependency>
            <dependency>
                <groupId>io.cucumber</groupId>
                <artifactId>cucumber-java</artifactId>
                <version>${cucumber.version}</version>
            </dependency>
            <dependency>
                <groupId>io.cucumber</groupId>
                <artifactId>cucumber-junit</artifactId>
                <version>${cucumber.version}</version>
            </dependency>
            <dependency>
                <groupId>net.serenity-bdd</groupId>
                <artifactId>serenity-junit</artifactId>
                <version>${serenity.version}</version>
                <scope>test</scope>
            </dependency>
            <dependency>
                <groupId>org.slf4j</groupId>
                <artifactId>slf4j-log4j12</artifactId>
                <version>1.7.7</version>
                <scope>test</scope>
            </dependency>
            <dependency>
                <groupId>junit</groupId>
                <artifactId>junit</artifactId>
                <version>4.13.1</version>
                <scope>test</scope>
            </dependency>
            <dependency>
                <groupId>org.assertj</groupId>
                <artifactId>assertj-core</artifactId>
                <version>3.6.2</version>
                <scope>test</scope>
            </dependency>
            <dependency>
                <groupId>org.hamcrest</groupId>
                <artifactId>hamcrest-all</artifactId>
                <version>1.3</version>
                <scope>test</scope>
            </dependency>
            
            <dependency>
                <groupId>com.saucelabs</groupId>
                <artifactId>saucerest</artifactId>
                <version>1.0.23</version>
                <scope>test</scope>
            </dependency>
            <!-- https://mvnrepository.com/artifact/com.applitools/eyes-common-java4 -->
            <dependency>
                <groupId>com.applitools</groupId>
                <artifactId>eyes-appium-java4</artifactId>
                <version>4.2.1</version>
            </dependency>
            <!-- https://mvnrepository.com/artifact/cglib/cglib -->
            <dependency>
                <groupId>cglib</groupId>
                <artifactId>cglib</artifactId>
                <version>3.3.0</version>
            </dependency>
            <dependency>
                <groupId>org.apache.commons</groupId>
                <artifactId>commons-lang3</artifactId>
                <version>3.8.1</version>
                <scope>compile</scope>
            </dependency>
            <dependency>
                <groupId>org.apache.commons</groupId>
                <artifactId>commons-lang3</artifactId>
                <version>3.8.1</version>
                <scope>compile</scope>
            </dependency>
            <dependency>
                <groupId>org.seleniumhq.selenium</groupId>
                <artifactId>selenium-api</artifactId>
                <version>3.141.59</version>
            </dependency>
            <dependency>
                <groupId>org.apache.commons</groupId>
                <artifactId>commons-lang3</artifactId>
                <version>3.8.1</version>
                <scope>compile</scope>
            </dependency>
            <dependency>
                <groupId>net.serenity-bdd</groupId>
                <artifactId>serenity-core</artifactId>
                <version>2.3.12</version>
                <scope>compile</scope>
            </dependency>
    
        </dependencies> 
        
        <build>
            <plugins>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-surefire-plugin</artifactId>
                    <version>3.0.0-M5</version>
                    <configuration>
                        <skip>true</skip>
                    </configuration>
                </plugin>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-failsafe-plugin</artifactId>
                    <version>3.0.0-M5</version>
                    <configuration>
                        <includes>
                             <include>**/*.java</include>
                        </includes>
                        <argLine>-Xmx512m</argLine>
                        <systemPropertyVariables>
                            <webdriver.driver>${webdriver.driver}</webdriver.driver>
                        </systemPropertyVariables>
                    </configuration>
                    <executions>
                        <execution>
                            <goals>
                                <goal>integration-test</goal>
                                <goal>verify</goal>
                            </goals>
                        </execution>
                    </executions>
                </plugin>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-compiler-plugin</artifactId>
                    <version>3.8.1</version>
                    <configuration>
                        <source>1.8</source>
                        <target>1.8</target>
                    </configuration>
                </plugin>
                <plugin>
                    <groupId>net.serenity-bdd.maven.plugins</groupId>
                    <artifactId>serenity-maven-plugin</artifactId>
                    <version>${serenity.maven.version}</version>
                    <configuration>
                        <!--suppress UnresolvedMavenProperty -->
                        <tags>${tags}</tags>
                    </configuration>
                    <dependencies>
                        <dependency>
                            <groupId>net.serenity-bdd</groupId>
                            <artifactId>serenity-core</artifactId>
                            <version>${serenity.version}</version>
                        </dependency>
                    </dependencies>
                    <executions>
                        <execution>
                            <id>serenity-reports</id>
                            <phase>post-integration-test</phase>
                            <goals>
                                <goal>aggregate</goal>
                            </goals>
                            <configuration>
                                <outputDirectory>${basedir}/reports/${build.number}</outputDirectory>
                            </configuration>
                        </execution>
                    </executions>
                </plugin>
                <plugin>
                    <groupId>org.codehaus.mojo</groupId>
                    <artifactId>build-helper-maven-plugin</artifactId>
                    <version>3.2.0</version>
                    <executions>
                        <execution>
                            <id>current-time</id>
                            <phase>validate</phase>
                            <goals>
                                <goal>timestamp-property</goal>
                            </goals>
                            <configuration>
                                <name>current.time</name>
                                <pattern>dd-MM-yyyy_HH-mm-ss</pattern>
                                <timeZone>GMT+13</timeZone>
                            </configuration>
                        </execution>
                    </executions>
                </plugin>
            </plugins>
        </build>
    
    </project>

标签: androidappiumemulation

解决方案


我自己解决了。如果有人有更好的,请告诉我。我们必须在所需的功能中添加 avd。

能力.setCapability("avd","Nexus5");

和 avd 在 Appium starter 中。

公共无效 startAppium(){

service = AppiumDriverLocalService.buildService(new AppiumServiceBuilder()
        .withArgument(new ServerArgument(){
            public String getArgument() {
                return "--avd";
            }
        }, "Nexus5")
        .usingDriverExecutable(new File("/Applications/Appium.app/Contents/Resources/node/bin/node"))
        .withAppiumJS(new File("/Applications/Appium.app/Contents/Resources/node_modules/appium/bin/appium.js"))
        .withLogFile(new File("target/\"+deviceUnderExecution+\".log")));

service.start();

}


推荐阅读