Selenium Tests take several minutes to start when loading a profile

試著忘記壹切 提交于 2021-02-05 08:59:09

问题


I am just trying to figure out if anyone else has seen their Selenium tests run significantly slower (takes 2+ minutes to start) when they load a profile into the FirefoxDriver as shown in: Selenium a default profile for the Firefox

The question originator of the above post mentioned this issue in a comment, but never updated whether he fixed this slowness issue.

At some point my tests stopped running all together and I started getting the error

org.openqa.selenium.WebDriverException: java.io.Exception: unexpected end of stream on Connection. 

If I remove the profile option from the FirefoxDriver call then the test runs within 5 seconds of selecting "RUN" but the test fails because the default profile Selenium uses does not have the certificates I need to access my site.

Anyone else in the same boat or know how to fix this? How do you adjust how much information is saved within a profile?

  • Firefox Version: 60.3.0
  • Selenium Version: 3.14.0
  • GeckoDriver Version: 0.23.0
  • OS: Linux Redhat 6
  • Eclipse Version: Neon

Code:

WebDriver browser;
System.setProperty("webdriver.gecko.driver", "/path/to/geckodriver.exe");
ProfilesIni profile = new ProfilesIni();
FirefoxProfile ffprofile = profile.get("SeleniumUser");
FirefoxOptions options = new FirefoxOptions().setProfile(ffprofile);
browser = new FirefoxDriver(options); // takes a long time and eventually fails here
browser.get("site.url");

If you take out the {options} parameter from the new FirefoxDriver() call the test will start in about 5 seconds. Keeping the options causes the error "org.openqa.selenium.WebDriverException: java.io.Exception: unexpected end of stream on Connection" as stated above.


回答1:


When you initiate the process to load a new/existing FirefoxProfile through GeckoDriver the underlying framework consisting of:

  • The Driver (Selenium binding)
  • The Server (GeckoDriver)
  • The Client (Firefox Browser)

Needs to initialize and intercommunicate with different internal modules.

You can find a detailed discussion on how to access a FirefoxProfile through GeckoDriver with in Cannot resolve constructor FirefoxDriver(org.openqa.selenium.firefox.FirefoxProfile)

Additionally the saved:

  • Bookmarks
  • Password
  • User Preferences

are also loaded when an existing FirefoxProfile loads. Hence some added time is required.

You can find a detailed discussion in webdriver.FirefoxProfile(): Is it possible to use a profile without making a copy of it?



来源:https://stackoverflow.com/questions/53886741/selenium-tests-take-several-minutes-to-start-when-loading-a-profile

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!