首页 文章

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

提问于
浏览
7

我试图通过将自定义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

    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/ " and not " http://www.server.com/myApp”开始测试,则可以省略最后一个打开的行 .

  • 1

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

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

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

  • 1
    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)
    
    • 如果要在代码中引用特定的配置文件(这里我使用默认生成的文件夹作为名为“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)
    
    • 您可以将证书添加到自定义配置文件
      a) 使用自定义配置文件运行浏览器
      b) 添加证书
      c) 请记住勾选Firefox首选项/高级/证书中的选项
      Select one automatically
      每次访问测试页时都要避免要求接受证书
      d) 重启浏览器
      e) 导航到页面将测试的内容并接受 User Identification Request
      f) 关闭Firefox,享受selenium服务器提供的证书的自定义配置文件:)
  • 6

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

相关问题