【问题标题】:Selenium server not starting for custom firefox profileSelenium 服务器未针对自定义 Firefox 配置文件启动
【发布时间】:2011-07-26 00:52:04
【问题描述】:

我正在尝试通过将自定义 firefox 配置文件传递给 DefaultSelenium 构造函数来启动 selenium 服务器。它打开具有指定 URL 的浏览器。

DefaultSelenium selenium = new DefaultSelenium("localhost", 4444, "*custom \"C:/Program Files/Mozilla Firefox/firefox.exe\"",ReadConFile.readcoFile("serverName"));
    selenium.start();

日志是

16:39:19.246 INFO - Allocated session 4eb63d37a4ba4d2fb4e351f8f59e3ea6 for https://<myURL>, launching...

然后它保持这种状态并且服务器没有启动。

但是,如果我不使用自定义配置文件,这可以正常工作。

DefaultSelenium selenium = new DefaultSelenium("localhost", 4444, "*chrome",ReadConFile.readcoFile("serverName"));
selenium.start();

我需要启动自定义配置文件,因为我保存了一些 https 所需的站点证书。另外,我正在从 Eclipse 中执行此操作。

我认为我的服务器未配置为启动自定义配置文件。请帮我解决这个问题。

【问题讨论】:

标签: firefox selenium webdriver selenium-server


【解决方案1】:

start 命令本身并没有真正启动您的 selenium 服务器,它使用您选择的浏览器将您的 selenium 对象连接到已经运行的服务器。

要实际启动 selenium [Jetty Web] 服务器,该服务器通过您指定的浏览器向您的被测应用程序发送/接收命令,请使用批处理文件和 rs79 所指的开关。你的批处理文件的内容应该包括他的行:

java -jar selenium-server-standalone-2.0a5.jar -firefoxProfileTemplate C:\custom-firefox-profile

现在你有一个真正的 selenium 服务器在你的开发机器 (localhost) 上运行,默认的“4444”端口。这将指定任何 Firefox 浏览器测试都将使用此配置文件。

现在您的 DefaultSelenium 构造函数、赋值和其他调用可能如下所示:

DefaultSelenium selenium = new DefaultSelenium("localhost", 4444, "*firefox","http://www.server.com");
selenium.start()
selenium.open("myApp/")

Firefox 将开始使用启动 Selenium 服务器的批处理文件中指定的自定义配置文件,以及所需的基本 URL,然后导航到所需的应用程序 [URL]。如果您是从“http://www.server.com/”而不是“http://www.server.com/myApp”开始测试,您可以省略最后一行open

【讨论】:

【解决方案2】:

当您调用 Selenium RC 服务器时,请使用附加的 -firefoxProfileTemplate 子句指定路径。 例如 -

java -jar selenium-server-standalone-2.0a5.jar -firefoxProfileTemplate C:\custom-firefox-profile

这将使您能够使用您在自定义配置文件中保存的所有绑定。

【讨论】:

  • 我正在使用 Eclipse 启动服务器。如何配置它以开始使用 -firefoxProfileTemplate。
【解决方案3】:
  1. 如果您想在测试中默认使用 Fifefox 配置文件:
    a) 下载最新的 selenium-serverhttp://selenium-release.storage.googleapis.com/index.html
    b) 下载最新的Firefox
    c) 创建FF 配置文件(最好在您的自定义目录中) - 在我的例子中名为“atf”https://support.mozilla.org/en-US/kb/profile-manager-create-and-remove-firefox-profiles
    保存配置文件的默认目录:

     C:\Users\johndoe\AppData\Roaming\Mozilla\Firefox\Profiles
    

    d) 就我而言,我使用 FF 36selenium-server-standalone-2.45.0.jar
    运行selenium server

    java -jar C:\driver\selenium-server-standalone-2.45.0.jar -Dwebdriver.firefox.profile=atf 
    

    然后在你的代码中引用它:

    driver = webdriver.Remote(command_executor='http://127.0.0.1:4444/wd/hub',      
                          desired_capabilities=DesiredCapabilities.FIREFOX)
    
  2. 如果你想在你的代码中引用特定的配置文件(这里我使用默认生成的文件夹来命名名为“myProfile”的配置文件):

    profile_path = C:/Users/johndoe/AppData/Roaming/Mozilla/Firefox/Profiles/2zvl3dxx.myProfile"
    fp = webdriver.FirefoxProfile(profile_path)
    driver = webdriver.Remote(command_executor='http://127.0.0.1:4444/wd/hub', 
                          desired_capabilities=DesiredCapabilities.FIREFOX,
                          browser_profile=myProfile)
    
  3. 您可以将证书添加到自定义配置文件
    a) 使用自定义配置文件运行浏览器
    b) 添加证书
    c) 记得在 Firefox Preferences/Advanced/Certificates 中勾选选项
    Select one automatically
    避免每次访问测试页面时都要求接受证书
    d) 重新启动浏览器
    e) 导航到要测试的页面并接受 @987654335 @
    f) 关闭 Firefox 并使用 selenium 服务器提供的证书享受自定义配置文件 :)

【讨论】:

    【解决方案4】:

    您也可以在 java 中启动 Selenium 服务器,请参阅here

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2015-09-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多