Selenium服务器无法启动自定义firefox配置文件

时间:2011-03-30 11:32:13

标签: firefox selenium webdriver selenium-server

我正在尝试通过将自定义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执行的。

我认为我的服务器未配置为启动自定义配置文件。请帮帮我。

4 个答案:

答案 0 :(得分:6)

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

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

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

现在,你的dev机器(localhost)上运行了一个真正的selenium服务器,默认的“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”开始测试,则可以省略最后一个打开行。

答案 1 :(得分:1)

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

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

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

答案 2 :(得分:1)

  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首选项/高级/证书中勾选选项 Select one automatically
    每次访问测试页时都要避免要求接受证书 d)重新启动浏览器
    e)导航到页面测试内容并接受User Identification Request
    f)关闭Firefox并享受selenium服务器提供的证书的自定义配置文件:)

答案 3 :(得分:0)

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

相关问题