有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java Selenium firefox驱动程序启动firefox需要3040秒

我正在使用selenium webdriver 2.3开发测试,并按如下方式初始化浏览器:

if (testBrowser.equalsIgnoreCase("Mozilla")) 
{
 dvr = new FirefoxDriver();
  System.out.println("Invoking firefox in your system");
}
else if (testBrowser.equalsIgnoreCase("IE"))
{
 File file = new File(System.getProperty("user.dir")+"/IEDriverServer.exe"); 
 System.setProperty("webdriver.ie.driver", file.getAbsolutePath());
 dvr = new InternetExplorerDriver();
 } else if (testBrowser.equalsIgnoreCase("Chrome")) 
{
   File file = new File(System.getProperty("user.dir")+"/chromedriver.exe"); 
   System.setProperty("webdriver.chrome.driver", file.getAbsolutePath());
   dvr = new ChromeDriver();

} 

firefox每次启动大约需要30-40秒,而chrome或safari e.t.c等其他浏览器则在几秒钟内启动

虽然我尝试了下面博客中建议的解决方案,但不适用于我: https://groups.google.com/forum/#!topic/selenium-users/a2fNfF-mD_E

如果有人能解决这个问题,我会非常感激的


共 (1) 个答案

  1. # 1 楼答案

    我有一些FF的配置文件设置,我在python上的测试用例中使用了这些设置。 据我所知,它的性能更好:

    profile = webdriver.FirefoxProfile()
            profile.set_preference('general.useragent.override', user_agent)
            # Paint delay off
            profile.set_preference('nglayout.initialpaint.delay', 0)
            # Tabs animation
            profile.set_preference('browser.tabs.animate', False)
            # Gif animation off
            profile.set_preference('image.animation_mode', 'none')
            # Tabs memory off
            profile.set_preference('browser.sessionhistory.max_total_viewer', 1)
            profile.set_preference('browser.sessionhistory.max_entries', 3)
            profile.set_preference('browser.sessionhistory.max_total_viewers', 1)
            profile.set_preference('browser.sessionstore.max_tabs_undo', 0)
            # Asynchronous requests to the server
            profile.set_preference('network.http.pipelining', True)
            profile.set_preference('network.http.pipelining.maxrequests', 8)
            # Cache enabled
            profile.set_preference('browser.cache.memory.enable', True)
            profile.set_preference('browser.cache.disk.enable', True)
            # Autosuggests
            profile.set_preference('browser.search.suggest.enabled', False)
            # Formfills
            profile.set_preference('browser.formfill.enable', False)
            # scan downloads
            profile.set_preference('browser.download.manager.scanWhenDone', False)
            # no bookmarks backup
            profile.set_preference('browser.bookmarks.max_backups', 0) 
    

    试试Java语法