appium grid org.openqa.selenium.webdriverexception:转发新会话时出错,找不到

oug3syen  于 2021-07-06  发布在  Java
关注(0)|答案(0)|浏览(421)

appium(版本1.18.3)网格在执行基于chrome的web应用测试时抛出错误。
chrome.java类

  1. package com.example.appium;
  2. import java.net.MalformedURLException;
  3. import java.net.URL;
  4. import java.util.concurrent.TimeUnit;
  5. import io.appium.java_client.AppiumDriver;
  6. import io.appium.java_client.remote.MobileCapabilityType;
  7. import org.openqa.selenium.By;
  8. import org.openqa.selenium.WebDriver;
  9. import org.openqa.selenium.WebElement;
  10. import org.openqa.selenium.remote.CapabilityType;
  11. import org.openqa.selenium.remote.DesiredCapabilities;
  12. import org.openqa.selenium.remote.RemoteWebDriver;
  13. import io.appium.java_client.MobileElement;
  14. import io.appium.java_client.android.AndroidDriver;
  15. import org.testng.annotations.BeforeClass;
  16. import org.testng.annotations.Optional;
  17. import org.testng.annotations.Parameters;
  18. import org.testng.annotations.Test;
  19. public class Chrome {
  20. WebDriver driver;
  21. DesiredCapabilities cap = new DesiredCapabilities();
  22. @BeforeClass
  23. public void init() throws MalformedURLException {
  24. cap.setCapability("deviceName", "ZH33L2Z6KL");
  25. cap.setCapability("platformName", "Android");
  26. cap.setCapability(CapabilityType.BROWSER_NAME, "Chrome");
  27. cap.setCapability("chromeDriverPort", "8201");
  28. cap.setCapability("chromedriverExecutable","C:\\chromedriver\\chromedriver.exe");
  29. cap.setCapability(CapabilityType.VERSION, "5.1");
  30. }
  31. @Test
  32. public void testApp() {
  33. try {
  34. driver = new RemoteWebDriver(new URL("http://127.0.0.1:4444/wd/hub"), cap);
  35. } catch (MalformedURLException e) {
  36. e.printStackTrace();
  37. }
  38. driver.get("https://www.amazon.com");
  39. }
  40. }

testng xml文件:

  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
  3. <suite name="Regression" thread-count="2" parallel="tests" preserve-order="true" verbose="2">
  4. <test name="Real Device1">
  5. <classes>
  6. <class name="com.example.appium.Chrome"/>
  7. </classes>
  8. </test>
  9. </suite>

使用以下命令调用appium selenium网格:
集线器:

  1. java -jar selenium-server-standalone-3.141.59.jar -role hub

nodeconfig\u设备1.json:

  1. {
  2. "capabilities": [
  3. {
  4. "browserName": "Chrome",
  5. "version": "6.0",
  6. "maxInstances": 10,
  7. "deviceName": "ZH33L2Z6KL",
  8. "platformName": "ANDROID",
  9. "automationName":"UiAutomator2",
  10. "chromeDriverPort":"8201"
  11. }
  12. ],
  13. "configuration": {
  14. "cleanUpCycle": 2000,
  15. "timeout": 300000,
  16. "proxy": "org.openqa.grid.selenium.proxy.DefaultRemoteProxy",
  17. "maxSession": 10,
  18. "register": true,
  19. "registerCycle": 5000,
  20. "hubPort": 4444,
  21. "hubHost": "192.168.0.105",
  22. "hubProtocol":"http"
  23. }
  24. }

使用以下命令调用node1:

  1. appium --port 6001 --nodeconfig nodeconfig_device1.json

调用chrome apk时引发以下错误:

  1. org.openqa.selenium.WebDriverException: Error forwarding the new session cannot find : Capabilities {browserName: Chrome, chromeDriverPort: 6001, chromedriverExecutable: C:\chromedriver\chromedrive..., deviceName: ZH33L2Z6KL, platformName: android, version: 5.1}
  2. Command duration or timeout: 282 milliseconds
  3. at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
  4. at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
  5. at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
  6. at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
  7. at org.openqa.selenium.remote.ErrorHandler.createThrowable(ErrorHandler.java:214)
  8. at org.openqa.selenium.remote.ErrorHandler.throwIfResponseFailed(ErrorHandler.java:166)
  9. at org.openqa.selenium.remote.JsonWireProtocolResponse.lambda$errorHandler$0(JsonWireProtocolResponse.java:54)
  10. at org.openqa.selenium.remote.HandshakeResponse.lambda$getResponseFunction$0(HandshakeResponse.java:30)
  11. at org.openqa.selenium.remote.ProtocolHandshake.lambda$createSession$0(ProtocolHandshake.java:126)
  12. at java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:193)
  13. at java.util.Spliterators$ArraySpliterator.tryAdvance(Spliterators.java:958)
  14. at java.util.stream.ReferencePipeline.forEachWithCancel(ReferencePipeline.java:126)
  15. at java.util.stream.AbstractPipeline.copyIntoWithCancel(AbstractPipeline.java:499)
  16. at java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:486)
  17. at java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:472)
  18. at java.util.stream.FindOps$FindOp.evaluateSequential(FindOps.java:152)
  19. at java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234)
  20. at java.util.stream.ReferencePipeline.findFirst(ReferencePipeline.java:464)
  21. at org.openqa.selenium.remote.ProtocolHandshake.createSession(ProtocolHandshake.java:128)
  22. at org.openqa.selenium.remote.ProtocolHandshake.createSession(ProtocolHandshake.java:74)
  23. at org.openqa.selenium.remote.HttpCommandExecutor.execute(HttpCommandExecutor.java:136)
  24. at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:552)
  25. at org.openqa.selenium.remote.RemoteWebDriver.startSession(RemoteWebDriver.java:213)
  26. at org.openqa.selenium.remote.RemoteWebDriver.<init>(RemoteWebDriver.java:131)
  27. at org.openqa.selenium.remote.RemoteWebDriver.<init>(RemoteWebDriver.java:144)
  28. at com.example.appium.Chrome.testApp(Chrome.java:45)
  29. at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
  30. at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
  31. at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
  32. at java.lang.reflect.Method.invoke(Method.java:498)
  33. at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:124)
  34. at org.testng.internal.Invoker.invokeMethod(Invoker.java:583)
  35. at org.testng.internal.Invoker.invokeTestMethod(Invoker.java:719)
  36. at org.testng.internal.Invoker.invokeTestMethods(Invoker.java:989)
  37. at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:125)
  38. at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:109)
  39. at org.testng.TestRunner.privateRun(TestRunner.java:648)
  40. at org.testng.TestRunner.run(TestRunner.java:505)
  41. at org.testng.SuiteRunner.runTest(SuiteRunner.java:455)
  42. at org.testng.SuiteRunner.access$000(SuiteRunner.java:40)
  43. at org.testng.SuiteRunner$SuiteWorker.run(SuiteRunner.java:489)
  44. at org.testng.internal.thread.ThreadUtil$1.call(ThreadUtil.java:52)
  45. at java.util.concurrent.FutureTask.run(FutureTask.java:266)
  46. at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
  47. at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
  48. at java.lang.Thread.run(Thread.java:748)
  49. Caused by: org.openqa.selenium.WebDriverException: Error forwarding the new session cannot find : Capabilities {browserName: Chrome, chromeDriverPort: 6001, chromedriverExecutable: C:\chromedriver\chromedrive..., deviceName: ZH33L2Z6KL, platformName: android, version: 5.1}
  50. Build info: version: '3.141.59', revision: 'e82be7d358', time: '2018-11-14T08:17:03'
  51. System info: host: 'DESKTOP-E205GQ8', ip: '192.168.0.105', os.name: 'Windows 10', os.arch: 'amd64', os.version: '10.0', java.version: '1.8.0_261'
  52. Driver info: driver.version: unknown
  53. at org.openqa.grid.web.servlet.handler.RequestHandler.process(RequestHandler.java:118)
  54. at org.openqa.grid.web.servlet.DriverServlet.process(DriverServlet.java:85)
  55. at org.openqa.grid.web.servlet.DriverServlet.doPost(DriverServlet.java:69)
  56. at javax.servlet.http.HttpServlet.service(HttpServlet.java:707)
  57. at javax.servlet.http.HttpServlet.service(HttpServlet.java:790)
  58. at org.seleniumhq.jetty9.servlet.ServletHolder.handle(ServletHolder.java:865)
  59. at org.seleniumhq.jetty9.servlet.ServletHandler.doHandle(ServletHandler.java:535)
  60. at org.seleniumhq.jetty9.server.handler.ScopedHandler.handle(ScopedHandler.java:146)
  61. at org.seleniumhq.jetty9.security.SecurityHandler.handle(SecurityHandler.java:548)
  62. at org.seleniumhq.jetty9.server.handler.HandlerWrapper.handle(HandlerWrapper.java:132)
  63. at org.seleniumhq.jetty9.server.handler.ScopedHandler.nextHandle(ScopedHandler.java:257)
  64. at org.seleniumhq.jetty9.server.session.SessionHandler.doHandle(SessionHandler.java:1595)
  65. at org.seleniumhq.jetty9.server.handler.ScopedHandler.nextHandle(ScopedHandler.java:255)
  66. at org.seleniumhq.jetty9.server.handler.ContextHandler.doHandle(ContextHandler.java:1340)
  67. at org.seleniumhq.jetty9.server.handler.ScopedHandler.nextScope(ScopedHandler.java:203)
  68. at org.seleniumhq.jetty9.servlet.ServletHandler.doScope(ServletHandler.java:473)
  69. at org.seleniumhq.jetty9.server.session.SessionHandler.doScope(SessionHandler.java:1564)
  70. at org.seleniumhq.jetty9.server.handler.ScopedHandler.nextScope(ScopedHandler.java:201)
  71. at org.seleniumhq.jetty9.server.handler.ContextHandler.doScope(ContextHandler.java:1242)
  72. at org.seleniumhq.jetty9.server.handler.ScopedHandler.handle(ScopedHandler.java:144)
  73. at org.seleniumhq.jetty9.server.handler.HandlerWrapper.handle(HandlerWrapper.java:132)
  74. at org.seleniumhq.jetty9.server.Server.handle(Server.java:503)
  75. at org.seleniumhq.jetty9.server.HttpChannel.handle(HttpChannel.java:364)
  76. at org.seleniumhq.jetty9.server.HttpConnection.onFillable(HttpConnection.java:260)
  77. at org.seleniumhq.jetty9.io.AbstractConnection$ReadCallback.succeeded(AbstractConnection.java:305)
  78. at org.seleniumhq.jetty9.io.FillInterest.fillable(FillInterest.java:103)
  79. at org.seleniumhq.jetty9.io.ChannelEndPoint$2.run(ChannelEndPoint.java:118)
  80. at org.seleniumhq.jetty9.util.thread.strategy.EatWhatYouKill.runTask(EatWhatYouKill.java:333)
  81. at org.seleniumhq.jetty9.util.thread.strategy.EatWhatYouKill.doProduce(EatWhatYouKill.java:310)
  82. at org.seleniumhq.jetty9.util.thread.strategy.EatWhatYouKill.tryProduce(EatWhatYouKill.java:168)
  83. at org.seleniumhq.jetty9.util.thread.strategy.EatWhatYouKill.run(EatWhatYouKill.java:126)
  84. at org.seleniumhq.jetty9.util.thread.ReservedThreadExecutor$ReservedThread.run(ReservedThreadExecutor.java:366)
  85. at org.seleniumhq.jetty9.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:765)
  86. at org.seleniumhq.jetty9.util.thread.QueuedThreadPool$2.run(QueuedThreadPool.java:683)
  87. at java.lang.Thread.run(Unknown Source)

注:
当调用appiumgui(版本1.18.3)时,该代码工作正常,ip地址设置为127.0.0.1,端口设置为4723。这次,驱动程序更改如下:

  1. driver = new RemoteWebDriver(new URL("http://127.0.0.1:4723/wd/hub"), cap);

问题:
为什么appium grid没有在android设备中调用chrome应用程序?
为什么会抛出“org.openqa.selenium.webdriverexception:error forwarding the new session cannot find”错误,即使chrome应用程序和chrome驱动程序没有任何冲突?
是否需要其他设置?

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题