微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

模拟器未在 Appium 框架中启动抛出 InvocationTargetExceptionMessage

如何解决模拟器未在 Appium 框架中启动抛出 InvocationTargetExceptionMessage

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

我的模拟器类在接受所需的功能后抛出 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',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',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>

解决方法

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

capabilities.setCapability("avd","Nexus5");

和 Appium starter 中的 avd。

public void 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();

}

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。