如何修复会话未创建异常,而使用远程Web驱动程序 selenium ?

mm9b1k5b  于 2023-02-19  发布在  其他
关注(0)|答案(1)|浏览(202)
  1. FirefoxOptions chromeOptions = new FirefoxOptions();
  2. WebDriver driver = null;
  3. @BeforeTest
  4. public void beforeTest() throws Exception
  5. {
  6. driver = new RemoteWebDriver(new URL("http://localhost:4444"), chromeOptions);
  7. }
  8. @Test
  9. //Checking the title of iamNeo (Home - iamneo)
  10. public void iamNeo() throws InterruptedException
  11. {
  12. // driver.manage().window().maximize();
  13. driver.navigate().to("http://iamneo.ai/");
  14. String title = driver.getTitle();
  15. System.out.println(title);
  16. Assert.assertEquals(title, "Learning and assessment solution for Universities and Enterprises");
  17. }
  18. @Test
  19. //Moving to FACEBOOK
  20. public void nextPage() throws InterruptedException
  21. {
  22. driver.navigate().to("https://www.facebook.com");
  23. String title = driver.getTitle();
  24. Assert.assertEquals(title, "Facebook – log in or sign up");
  25. }
  26. @Test
  27. //Back to iamNeo
  28. public void backPage() throws InterruptedException
  29. {
  30. driver.navigate().back();
  31. String title = driver.getTitle();
  32. System.out.println(title);
  33. Assert.assertEquals(title, "Learning and assessment solution for Universities and Enterprises");
  34. }
  35. @Test
  36. //Current URL
  37. public void currentURL() throws InterruptedException
  38. {
  39. System.out.println(driver.getCurrentUrl());
  40. String title = driver.getTitle();
  41. System.out.println(title);
  42. Assert.assertEquals(title, "Learning and assessment solution for Universities and Enterprises");
  43. driver.navigate().forward();
  44. driver.navigate().refresh();
  45. }
  46. @AfterTest
  47. public void afterTest()
  48. {
  49. driver.quit();
  50. }
  1. :
  1. It is Throwing Session Not created Exception :
  2. Could not start a new session. Possible causes are invalid address of the remote server or browser start-up :
  3. org.openqa.selenium.SessionNotCreatedException:
  4. Could not start a new session. Possible causes are invalid address of the remote server or browser start-up failure.
  5. Build info: version: '4.1.0', revision: '87802e897b'
  6. System info: host: 'eeeccebaefcebfacecbccfaabacdfdabdafecefecf-0', ip: '10.41.17.6', os.name: 'Linux', os.arch: 'amd64', os.version: '5.4.217+', java.version: '11.0.13'
  7. Driver info: org.openqa.selenium.remote.RemoteWebDriver
  8. Command: [null, newSession {capabilities=[Capabilities {acceptInsecureCerts: true, browserName: firefox, moz:debuggerAddress: true, moz:firefoxOptions: {}}], desiredCapabilities=Capabilities {acceptInsecureCerts: true, browserName: firefox, moz:debuggerAddress: true, moz:firefoxOptions: {}}}]
  9. Capabilities {}
  10. at ai.iamneo.testing.Testing_Selenium_TestNg.AppTest.beforeTest(AppTest.java:24)
  11. Caused by: java.lang.RuntimeException: NettyHttpHandler request execution error
  12. at ai.iamneo.testing.Testing_Selenium_TestNg.AppTest.beforeTest(AppTest.java:24)
  13. Caused by: java.util.concurrent.ExecutionException: java.util.concurrent.TimeoutException: Request timeout to localhost/127.0.0.1:4444 after 180000 ms
  14. at ai.iamneo.testing.Testing_Selenium_TestNg.AppTest.beforeTest(AppTest.java:24)
  15. Caused by: ja
wlwcrazw

wlwcrazw1#

取代:

  1. new URL("http://localhost:4444")

您需要通过:

  1. new URL("http:///127.0.0.1:4444")

您可能需要在末尾追加 * /wd/hub *,如下所示:

  1. new URL("http:///127.0.0.1:4444/wd/hub")

参考文献

您可以在以下位置找到相关的详细讨论:

展开查看全部

相关问题