【问题标题】:cucumber.runtime.CucumberException: Failed to instantiate class when run on other devicescucumber.runtime.CucumberException:在其他设备上运行时无法实例化类
【发布时间】:2020-04-26 16:48:08
【问题描述】:

在这种情况下请帮助我。
尝试在其他设备上使用 Java 使用 Appium 运行 Cucumber 步骤时遇到此错误。
表示我可以在我的设备上正确运行脚本,但是当我连接到其他设备时,我遇到了这个错误。
虽然我改变了功能:" deviceName”和“platformVersion”。 这是我的钩子:

    public class Hooks {
    private static AndroidDriver driver;
    private static String packageApp;


    @Before
    public static AndroidDriver openPaxApp(String appName){
        if(appName.equals("mycar")){
            packageApp = "com.mycar.passenger";
        }else if (appName.equals("pegasus")){
            packageApp = "com.qupworld.pegasuspax";
        }
        DesiredCapabilities cap = new DesiredCapabilities();
        cap.setCapability("deviceName", "42003cedd0e144d9");
        cap.setCapability("platformName", "Android");
        cap.setCapability("platformVersion", "6.0.1");
        cap.setCapability("appPackage", packageApp);
        cap.setCapability("appActivity", "com.qup.pegasus.ui.launch.LauncherActivity");
        cap.setCapability("automationName", "UiAutomator2");
        cap.setCapability("autoGrantPermissions", "true");
        cap.setCapability("skipDeviceInitialization", "true");
        cap.setCapability("skipServerInstallation", "true");
        cap.setCapability("noReset", "true");
        try {
            driver = new AndroidDriver<MobileElement>(new URL("http://0.0.0.0:4723/wd/hub"), cap);
        } catch (
                MalformedURLException e) {
            e.printStackTrace();
        }
        driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
        return driver;
    }
}

这是我的跑步者文件:

package cucumberOptions;
import cucumber.api.CucumberOptions;
import cucumber.api.SnippetType;
import cucumber.api.junit.Cucumber;
import org.junit.runner.RunWith;


@RunWith(Cucumber.class)
@CucumberOptions(
        features = "src/test/java/features",
        glue = "stepDefinitions",
        monochrome = true,
        plugin = {"pretty", "html:target/site/cucumber-report-default", "json:target/site/cucumber.json"},
        snippets = SnippetType.CAMELCASE,
        tags = {"@RegisterAndLogin, @HomePageTestCases"}
public class CucumberTestRunner {
}

然后我遇到了这个错误:

cucumber.runtime.CucumberException: Failed to instantiate class stepDefinitions.RegisterAndLoginSteps

    at cucumber.runtime.java.DefaultJavaObjectFactory.cacheNewInstance(DefaultJavaObjectFactory.java:47)
    at cucumber.runtime.java.DefaultJavaObjectFactory.getInstance(DefaultJavaObjectFactory.java:33)
    at cucumber.runtime.java.JavaStepDefinition.execute(JavaStepDefinition.java:38)
    at cucumber.runtime.StepDefinitionMatch.runStep(StepDefinitionMatch.java:37)
    at cucumber.runtime.Runtime.runStep(Runtime.java:300)
    at cucumber.runtime.model.StepContainer.runStep(StepContainer.java:44)
    at cucumber.runtime.model.StepContainer.runSteps(StepContainer.java:39)
    at cucumber.runtime.model.CucumberScenario.run(CucumberScenario.java:44)
    at cucumber.runtime.junit.ExecutionUnitRunner.run(ExecutionUnitRunner.java:102)
    at cucumber.runtime.junit.FeatureRunner.runChild(FeatureRunner.java:63)
    at cucumber.runtime.junit.FeatureRunner.runChild(FeatureRunner.java:18)
    at org.junit.runners.ParentRunner$4.run(ParentRunner.java:330)
    at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:78)
    at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:328)
    at org.junit.runners.ParentRunner.access$100(ParentRunner.java:65)
    at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:292)
    at org.junit.runners.ParentRunner$3.evaluate(ParentRunner.java:305)
    at org.junit.runners.ParentRunner.run(ParentRunner.java:412)
    at cucumber.runtime.junit.FeatureRunner.run(FeatureRunner.java:70)
    at cucumber.api.junit.Cucumber.runChild(Cucumber.java:95)
    at cucumber.api.junit.Cucumber.runChild(Cucumber.java:38)
    at org.junit.runners.ParentRunner$4.run(ParentRunner.java:330)
    at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:78)
    at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:328)
    at org.junit.runners.ParentRunner.access$100(ParentRunner.java:65)
    at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:292)
    at org.junit.runners.ParentRunner$3.evaluate(ParentRunner.java:305)
    at org.junit.runners.ParentRunner.run(ParentRunner.java:412)
    at cucumber.api.junit.Cucumber.run(Cucumber.java:100)
    at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
    at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:68)
    at com.intellij.rt.execution.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:47)
    at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:242)
    at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:70)
Caused by: java.lang.reflect.InvocationTargetException
    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 cucumber.runtime.java.DefaultJavaObjectFactory.cacheNewInstance(DefaultJavaObjectFactory.java:41)
    ... 33 more
Caused by: org.openqa.selenium.SessionNotCreatedException: Unable to create a new remote session. Please check the server log for more details. Original error: org.json.JSONException: No value for desiredCapabilities
    at org.json.JSONObject.get(JSONObject.java:389)
    at org.json.JSONObject.getJSONObject(JSONObject.java:609)
    at io.appium.uiautomator2.handler.request.BaseRequestHandler.getPayload(BaseRequestHandler.java:50)
    at io.appium.uiautomator2.handler.NewSession.safeHandle(NewSession.java:38)
    at io.appium.uiautomator2.handler.request.SafeRequestHandler.handle(SafeRequestHandler.java:37)
    at io.appium.uiautomator2.server.AppiumServlet.handleRequest(AppiumServlet.java:252)
    at io.appium.uiautomator2.server.AppiumServlet.handleHttpRequest(AppiumServlet.java:243)
    at io.appium.uiautomator2.http.ServerHandler.channelRead(ServerHandler.java:44)
    at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:366)
    at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:352)
    at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:345)
    at io.netty.handler.codec.MessageToMessageDecoder.channelRead(MessageToMessageDecoder.java:102)
    at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:366)
    at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:352)
    at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:345)
    at io.netty.channel.CombinedChannelDuplexHandler$DelegatingChannelHandlerContext.fireChannelRead(CombinedChannelDuplexHandler.java:435)
    at io.netty.handler.codec.ByteToMessageDecoder.fireChannelRead(ByteToMessageDecoder.java:293)
    at io.netty.handler.codec.ByteToMessageDecoder.channelRead(ByteToMessageDecoder.java:267)
    at io.netty.channel.CombinedChannelDuplexHandler.channelRead(CombinedChannelDuplexHandler.java:250)
    at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:366)
    at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:352)
    at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:345)
    at io.netty.channel.DefaultChannelPipeline$HeadContext.channelRead(DefaultChannelPipeline.java:1294)
    at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:366)
    at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:352)
    at io.netty.channel.DefaultChannelPipeline.fireChannelRead(DefaultChannelPipeline.java:911)
    at io.netty.channel.nio.AbstractNioByteChannel$NioByteUnsafe.read(AbstractNioByteChannel.java:131)
    at io.netty.channel.nio.NioEventLoop.processSelectedKey(NioEventLoop.java:611)
    at io.netty.channel.nio.NioEventLoop.processSelectedKeysPlain(NioEventLoop.java:514)
    at io.netty.channel.nio.NioEventLoop.processSelectedKeys(NioEventLoop.java:468)
    at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:438)
    at io.netty.util.concurrent.SingleThreadEventExecutor$2.run(SingleThreadEventExecutor.java:140)
    at io.netty.util.concurrent.DefaultThreadFactory$DefaultRunnableDecorator.run(DefaultThreadFactory.java:144)
    at java.lang.Thread.run(Thread.java:818)

Build info: version: '3.141.59', revision: 'e82be7d358', time: '2018-11-14T08:17:03'
System info: host: 'TAM-NGUYEN', ip: '192.168.1.86', os.name: 'Windows 10', os.arch: 'amd64', os.version: '10.0', java.version: '1.8.0_231'
Driver info: driver.version: AndroidDriver
remote stacktrace: NoSuchContextError: org.json.JSONException: No value for desiredCapabilities
    at org.json.JSONObject.get(JSONObject.java:389)
    at org.json.JSONObject.getJSONObject(JSONObject.java:609)
    at io.appium.uiautomator2.handler.request.BaseRequestHandler.getPayload(BaseRequestHandler.java:50)
    at io.appium.uiautomator2.handler.NewSession.safeHandle(NewSession.java:38)
    at io.appium.uiautomator2.handler.request.SafeRequestHandler.handle(SafeRequestHandler.java:37)
    at io.appium.uiautomator2.server.AppiumServlet.handleRequest(AppiumServlet.java:252)
    at io.appium.uiautomator2.server.AppiumServlet.handleHttpRequest(AppiumServlet.java:243)
    at io.appium.uiautomator2.http.ServerHandler.channelRead(ServerHandler.java:44)
    at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:366)
    at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:352)
    at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:345)
    at io.netty.handler.codec.MessageToMessageDecoder.channelRead(MessageToMessageDecoder.java:102)
    at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:366)
    at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:352)
    at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:345)
    at io.netty.channel.CombinedChannelDuplexHandler$DelegatingChannelHandlerContext.fireChannelRead(CombinedChannelDuplexHandler.java:435)
    at io.netty.handler.codec.ByteToMessageDecoder.fireChannelRead(ByteToMessageDecoder.java:293)
    at io.netty.handler.codec.ByteToMessageDecoder.channelRead(ByteToMessageDecoder.java:267)
    at io.netty.channel.CombinedChannelDuplexHandler.channelRead(CombinedChannelDuplexHandler.java:250)
    at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:366)
    at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:352)
    at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:345)
    at io.netty.channel.DefaultChannelPipeline$HeadContext.channelRead(DefaultChannelPipeline.java:1294)
    at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:366)
    at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:352)
    at io.netty.channel.DefaultChannelPipeline.fireChannelRead(DefaultChannelPipeline.java:911)
    at io.netty.channel.nio.AbstractNioByteChannel$NioByteUnsafe.read(AbstractNioByteChannel.java:131)
    at io.netty.channel.nio.NioEventLoop.processSelectedKey(NioEventLoop.java:611)
    at io.netty.channel.nio.NioEventLoop.processSelectedKeysPlain(NioEventLoop.java:514)
    at io.netty.channel.nio.NioEventLoop.processSelectedKeys(NioEventLoop.java:468)
    at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:438)
    at io.netty.util.concurrent.SingleThreadEventExecutor$2.run(SingleThreadEventExecutor.java:140)
    at io.netty.util.concurrent.DefaultThreadFactory$DefaultRunnableDecorator.run(DefaultThreadFactory.java:144)
    at java.lang.Thread.run(Thread.java:818)

    at errorFromMJSONWPStatusCode (C:\Users\Admin\AppData\Local\Programs\Appium\resources\app\node_modules\appium\node_modules\appium-base-driver\lib\protocol\errors.js:764:12)
    at ProxyRequestError.errorFromMJSONWPStatusCode [as getActualError] (C:\Users\Admin\AppData\Local\Programs\Appium\resources\app\node_modules\appium\node_modules\appium-base-driver\lib\protocol\errors.js:661:14)
    at JWProxy.getActualError [as command] (C:\Users\Admin\AppData\Local\Programs\Appium\resources\app\node_modules\appium\node_modules\appium-base-driver\lib\jsonwp-proxy\proxy.js:259:19)
Build info: version: '3.141.59', revision: 'e82be7d358', time: '2018-11-14T08:17:03'
System info: host: 'TAM-NGUYEN', ip: '192.168.1.86', os.name: 'Windows 10', os.arch: 'amd64', os.version: '10.0', java.version: '1.8.0_231'
Driver info: driver.version: AndroidDriver
    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 io.appium.java_client.android.AndroidDriver.execute(AndroidDriver.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 io.appium.java_client.android.AndroidDriver.<init>(AndroidDriver.java:94)
    at cucumberOptions.Hooks.openPaxApp(Hooks.java:40)
    at stepDefinitions.RegisterAndLoginSteps.<init>(RegisterAndLoginSteps.java:40)
    ... 38 more
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: org.json.JSONException: No value for desiredCapabilities
    at org.json.JSONObject.get(JSONObject.java:389)
    at org.json.JSONObject.getJSONObject(JSONObject.java:609)
    at io.appium.uiautomator2.handler.request.BaseRequestHandler.getPayload(BaseRequestHandler.java:50)
    at io.appium.uiautomator2.handler.NewSession.safeHandle(NewSession.java:38)
    at io.appium.uiautomator2.handler.request.SafeRequestHandler.handle(SafeRequestHandler.java:37)
    at io.appium.uiautomator2.server.AppiumServlet.handleRequest(AppiumServlet.java:252)
    at io.appium.uiautomator2.server.AppiumServlet.handleHttpRequest(AppiumServlet.java:243)
    at io.appium.uiautomator2.http.ServerHandler.channelRead(ServerHandler.java:44)
    at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:366)
    at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:352)
    at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:345)
    at io.netty.handler.codec.MessageToMessageDecoder.channelRead(MessageToMessageDecoder.java:102)
    at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:366)
    at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:352)
    at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:345)
    at io.netty.channel.CombinedChannelDuplexHandler$DelegatingChannelHandlerContext.fireChannelRead(CombinedChannelDuplexHandler.java:435)
    at io.netty.handler.codec.ByteToMessageDecoder.fireChannelRead(ByteToMessageDecoder.java:293)
    at io.netty.handler.codec.ByteToMessageDecoder.channelRead(ByteToMessageDecoder.java:267)
    at io.netty.channel.CombinedChannelDuplexHandler.channelRead(CombinedChannelDuplexHandler.java:250)
    at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:366)
    at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:352)
    at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:345)
    at io.netty.channel.DefaultChannelPipeline$HeadContext.channelRead(DefaultChannelPipeline.java:1294)
    at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:366)
    at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:352)
    at io.netty.channel.DefaultChannelPipeline.fireChannelRead(DefaultChannelPipeline.java:911)
    at io.netty.channel.nio.AbstractNioByteChannel$NioByteUnsafe.read(AbstractNioByteChannel.java:131)
    at io.netty.channel.nio.NioEventLoop.processSelectedKey(NioEventLoop.java:611)
    at io.netty.channel.nio.NioEventLoop.processSelectedKeysPlain(NioEventLoop.java:514)
    at io.netty.channel.nio.NioEventLoop.processSelectedKeys(NioEventLoop.java:468)
    at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:438)
    at io.netty.util.concurrent.SingleThreadEventExecutor$2.run(SingleThreadEventExecutor.java:140)
    at io.netty.util.concurrent.DefaultThreadFactory$DefaultRunnableDecorator.run(DefaultThreadFactory.java:144)
    at java.lang.Thread.run(Thread.java:818)

Build info: version: '3.141.59', revision: 'e82be7d358', time: '2018-11-14T08:17:03'
System info: host: 'TAM-NGUYEN', ip: '192.168.1.86', os.name: 'Windows 10', os.arch: 'amd64', os.version: '10.0', java.version: '1.8.0_231'
Driver info: driver.version: AndroidDriver
remote stacktrace: NoSuchContextError: org.json.JSONException: No value for desiredCapabilities
    at org.json.JSONObject.get(JSONObject.java:389)
    at org.json.JSONObject.getJSONObject(JSONObject.java:609)

这里是RegisterAndLoginSteps类:

package stepDefinitions;

import commons.AbstractPage;
import commons.AbstractTest;
import cucumber.api.DataTable;
import cucumber.api.java.en.And;
import cucumber.api.java.en.Given;
import cucumber.api.java.en.Then;
import cucumber.api.java.en.When;
import cucumber.api.junit.Cucumber;
//import cucumberOptions.Hooks;
import cucumberOptions.Hooks;
import io.appium.java_client.MobileElement;
import io.appium.java_client.android.AndroidDriver;
import org.junit.runner.RunWith;
import org.openqa.selenium.remote.DesiredCapabilities;
import pageObjects.HomePO;
import pageObjects.LoginPO;

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

import static org.testng.Assert.assertTrue;


@RunWith(Cucumber.class)
public class RegisterAndLoginSteps {
    AndroidDriver driver;
    AbstractPage abstractPage;
    LoginPO loginPage;
    HomePO homePage;
    String appTest;

    String packageApp, passCode, defaultCode;

    public RegisterAndLoginSteps() {
        driver = Hooks.openPaxApp("mycar");
        passCode = "7620";
        defaultCode = "1211";

        abstractPage = new AbstractPage(driver);
        loginPage = new LoginPO(driver);
        homePage = new HomePO(driver);

        abstractPage.sendAppPackage();
    }

    @Given("^I logout if currently logged in$")
    public void iLogoutIfCurrentlyLoggedIn() {
        abstractPage.sleepInSecond(1);
        if (loginPage.isCurrentlyLoggedIn()){
            homePage.logout();
        }else{
            loginPage.clickToPhoneNumberTextbox();
        }

    }

    @And("^I select the phone code by \"([^\"]*)\" country$")
    public void iSelectThePhoneCodeByCountry(String countryName) {
        loginPage.selectPhoneCode(countryName);
    }

    @Then("^I verify the passenger register successfully$")
    public void iVerifyThePassengerRegisterSuccessfully() {
        loginPage.clickToSkipButton();
        loginPage.clickToYesNoButton("Yes");
        assertTrue(loginPage.isThereHomeButtonPresent());
    }

    @When("^I select \"([^\"]*)\" server and input \"([^\"]*)\" fleet code$")
    public void iSelectServerAndInputFleetCode(String server, String fleetCode) {
//        loginPage.clickToPhoneNumberTextbox();
        loginPage.longPressToDebugArea();
        loginPage.inputToPassCodeTextbox(passCode);
        loginPage.clickToYesNoButton("YES");
        loginPage.selectServer(server, fleetCode);
        assertTrue(loginPage.isLoginPagePresent());
    }

    @Given("^I click to phone number text box$")
    public void iClickToPhoneNumberTextBox() {

        loginPage.clickToPhoneNumberTextbox();
    }

    @And("^I input the phone number$")
    public void i_input_the_phone_number(DataTable customerTable) {
        List<Map<String, String>> phoneNumber = customerTable.asMaps(String.class, String.class);
        loginPage.inputToPhoneNumberTextbox(phoneNumber.get(0).get("phoneNumber"));
    }


    @And("^I agree with Term of use and Privacy policy$")
    public void iAgreeWithTermOfUseAndPrivacyPolicy() {
        loginPage.clickToAgreeToUAndPolicy();
    }

    @And("^I click to continue button$")
    public void iClickToContinueButton() {
        loginPage.clickToLoginButton();
        loginPage.clickToYesNoButton("Yes");
    }

    @And("^I input sms verify code if have$")
    public void iInputSmsVerifyCodeIfHave(){
        loginPage.inputSMSDefaultCode(defaultCode);
    }

    @And("^I verify register message contains \"([^\"]*)\"$")
    public void iVerifyRegisterMessageContains(String textContains) {
        assertTrue(loginPage.isWelcomeMsgContains(textContains));
        loginPage.clickToYesNoButton("OK");
    }
}

仅当我尝试在其他设备上运行时才遇到此错误(这些代码仍在我的设备上运行 (Samsung Galaxy S9 - Android 9)

请帮助并感谢您的支持!

【问题讨论】:

    标签: java android maven cucumber appium


    【解决方案1】:

    你的问题写在这里:

    原因:org.openqa.selenium.SessionNotCreatedException:无法创建新的远程会话。请检查服务器日志以获取更多详细信息。原始错误:org.json.JSONException: No value for desiredCapabilities

    因此,要解决此问题,您需要提供正确的功能。我没有看到udid 功能,您必须提供它。 42003cedd0e144d9 - 这是udid 而不是deviceNamedeviceName 可以是任何东西,不会影响任何东西。

    【讨论】:

    • 将“deviceName”更改为“udid”后,我仍然遇到此错误。运行脚本时没有变化
    • 我通过将功能skipDeviceInitialization skipServerInstallation 更改为“false”解决了这个错误。感谢您的支持
    【解决方案2】:

    堆栈跟踪的第一行说:

    Failed to instantiate class stepDefinitions.RegisterAndLoginSteps
    

    但是,如果不知道该类中的内容,就很难知道错误的原因是什么。

    【讨论】:

    • 我提到了错误的类,但功能是一样的。我定义了驱动程序 = Hooks.openPaxApp("mycar")。错误将我导航到此代码。我更新了描述中的完整类 RegisterAndLoginSteps。请帮忙
    【解决方案3】:

    这个问题已经解决了。 由于我声明了所需的功能而发生错误:

    cap.setCapability("skipDeviceInitialization", "true");
    cap.setCapability("skipServerInstallation", "true");
    

    在第一次连接到其他设备时,这些功能应该是“false”来配置Android设备上的appium。如果这些功能在我们第一次连接PC时为“真”,就会出现这个错误。

    感谢大家的支持。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2018-05-21
      • 1970-01-01
      • 1970-01-01
      • 2019-09-23
      • 2017-01-30
      • 2020-09-29
      相关资源
      最近更新 更多