Selenium server not starting for custom firefox profile

我只是一个虾纸丫 提交于 2019-12-05 05:02:32

The start command is not really starting your selenium server per se, it's connecting your selenium object to an already running server with the browser of your choice.

To actually start the selenium [Jetty Web] server that sends / receives commands to your application under test via your specified browser, use a batch file and the switch rs79 is referring to. The contents of your batch file should include his line:

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

Now you have a true selenium server running on your dev machine (localhost) with the default "4444" port. This will specify that any Firefox browser testing will use this profile.

Now your DefaultSelenium constructor, assignment, and other calls can look like this:

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

Firefox will start using the custom profile specified in the batch file that starts the Selenium server, with your desired base URL, and then navigate into your desired application [URL]. If you are beginning your test from "http://www.server.com/" and not "http://www.server.com/myApp", you can omit the last open line.

When you invoke the Selenium RC server, specify the path using the additional -firefoxProfileTemplate clause. For example -

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

This will enable you to use all the bindings you have saved within the custom profile.

  1. If you want to have Fifefox profile as default in your test:
    a) Download latest selenium-server: http://selenium-release.storage.googleapis.com/index.html
    b) Download latest Firefox
    c) Create FF profile (best in your custom directory) - in my case named "atf" https://support.mozilla.org/en-US/kb/profile-manager-create-and-remove-firefox-profiles
    Default directory where profiles are saved:

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

    d) In my case I use FF 36 and selenium-server-standalone-2.45.0.jar
    Run selenium server:

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

    Then refer to it in your code:

    driver = webdriver.Remote(command_executor='http://127.0.0.1:4444/wd/hub',      
                          desired_capabilities=DesiredCapabilities.FIREFOX)
    
  2. If you want to refer to particular profile in your code (here I use default generated folder for profile named "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. You can add certificates to custom profile
    a) Run browser with custom profile
    b) Add certificate
    c) Remember to tick option in Firefox Preferences/Advanced/Certificates
    Select one automatically
    to avoid asking for accepting certificate every time as you access tested page
    d) Restart browser
    e) Navigate to page what will be tested and accept User Identification Request
    f) Close Firefox and enjoy custom profile with certificates available from selenium server :)

Carl Pritchett

You can also start the Selenium server in java see here.

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