java 浏览器堆栈/应用程序:将Selenium版本更新为4后出现错误

jv4diomz  于 2023-02-11  发布在  Java
关注(0)|答案(1)|浏览(189)

我正在Browserstack上运行应用自动化,在我升级Selenium和Java客户端版本之前,它一直运行良好。
Java客户端- 8.1.1 selenium - 4.2.2

Error: org.openqa.selenium.SessionNotCreatedException: Could not start a new session. Possible causes are invalid address of the remote server or browser start-up failure. 
    at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:565)
    at io.appium.java_client.AppiumDriver.startSession(AppiumDriver.java:224)
    at org.openqa.selenium.remote.RemoteWebDriver.<init>(RemoteWebDriver.java:157)
    at io.appium.java_client.AppiumDriver.<init>(AppiumDriver.java:79)
    at io.appium.java_client.AppiumDriver.<init>(AppiumDriver.java:87)
    at io.appium.java_client.android.AndroidDriver.<init>(AndroidDriver.java:116)
    at com.browserstack.run_first_test.BrowserStackTestNGTest.setUp(BrowserStackTestNGTest.java:61)
    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:86)
    at org.testng.internal.Invoker.invokeConfigurationMethod(Invoker.java:514)
    at org.testng.internal.Invoker.invokeConfigurations(Invoker.java:215)
    at org.testng.internal.Invoker.invokeMethod(Invoker.java:589)
    at org.testng.internal.Invoker.invokeTestMethod(Invoker.java:820)
    at org.testng.internal.Invoker.invokeTestMethods(Invoker.java:1128)
    at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:129)
    at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:112)
    at org.testng.TestRunner.privateRun(TestRunner.java:782)
    at org.testng.TestRunner.run(TestRunner.java:632)
    at org.testng.SuiteRunner.runTest(SuiteRunner.java:366)
    at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:361)
    at org.testng.SuiteRunner.privateRun(SuiteRunner.java:319)
    at org.testng.SuiteRunner.run(SuiteRunner.java:268)
    at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52)
    at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:86)
    at org.testng.TestNG.runSuitesSequentially(TestNG.java:1244)
    at org.testng.TestNG.runSuitesLocally(TestNG.java:1169)
    at org.testng.TestNG.run(TestNG.java:1064)
    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: org.openqa.selenium.WebDriverException: java.lang.reflect.InvocationTargetException
Build info: version: '4.5.0', revision: 'fe167b119a'
System info: os.name: 'Windows 10', os.arch: 'amd64', os.version: '10.0', java.version: '1.8.0_172'
Driver info: driver.version: AndroidDriver
    at io.appium.java_client.remote.AppiumProtocolHandshake.createSession(AppiumProtocolHandshake.java:130)
    at io.appium.java_client.remote.AppiumProtocolHandshake.createSession(AppiumProtocolHandshake.java:102)
    at io.appium.java_client.remote.AppiumCommandExecutor.createSession(AppiumCommandExecutor.java:146)
    at io.appium.java_client.remote.AppiumCommandExecutor.execute(AppiumCommandExecutor.java:180)
    at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:547)
    ... 32 more
z2acfund

z2acfund1#

找到了解决方案,因为需要一些配置。下面是我添加的值和在BrowserStack上运行的测试脚本:
对于Android应用程序:

`DesiredCapabilities mobileApp = new DesiredCapabilities();`
 mobileApp.setCapability("project", "Project Name");
mobileApp.setCapability("build", "You Build Name");
mobileApp.setCapability("name", "Any Name you want to provide");
mobileApp.setCapability("browserstack.debug", "true");
mobileApp.setCapability("app", "Your application URL on BrowserStack");
mobileApp.setCapability("deviceName", "Google Pixel 6");
mobileApp.setCapability("platformVersion", "12.0");

对于移动的(Android)中的浏览器:

MutableCapabilities androidCap = new MutableCapabilities();
HashMap<String, Object> androidOptions = new HashMap<String, Object>();
androidOptions.put("osVersion", "12.0");
androidOptions.put("deviceName", "Google Pixel 6");
androidOptions.put("realMobile", "true");
androidOptions.put("local", "false");
androidCap.setCapability("bstack:options", androidOptions);
driver = new RemoteWebDriver(new URL("Your credentials"), androidCap);

相关问题