简体   繁体   中英

Selenium Firefox Webdriver in Java (run parameters)

I've developed a testing unit with Selenium 2 in Java that uses Firefox engine.

The deploy machine has no display so I'm using Xvfb to create it. Unfortunatly that forces me to start java using DISPLAY=:0 java -jar xxx.jar . I've searched selenium javadoc and searched some sources but can't find the method that java uses to launch Firefox, witch is my goal, making java launch firefox using same method DISPLAY=:0 firefox ... .

Long story short: I must do DISPLAY=:0 java -jar xxx.jar but I want java to do DISPLAY=:XX firefox ... instead of firefox ... so I can also use multiple displays.

Any advice?

We're actually using Xvfb and Selenium in production with a dozen Firefox instances that work continuously. We use xvfb-run java -jar xxx.jar which select a free display to run all the firefox instances for this program. If screenshot is your concern, you can use only one display and still have a dozen Firefox taking screenshots for different websites at the same time

We wrapped this under a shell script, and that's transparent.

If you really want each selenium server to have its very display, you can overwrite it in the browser string specified in configuration. just make a shell script that do xvfb-run /usr/bin/firefox and pass this script to your config. That should do the trick

Have a good testing

We have made an bash file which sets the display and then starts firefox. We have put it into the path under the name firefox , so selenium finds it using which to locate the firefox binary.

Write a 'proxy' program that does a shell execute with the desired parameters; then point "webdriver.firefox.bin" property at your proxy program. I don't think this can be a java program because it is executed through the java command. It would probably have to be native code, probably C and something like "system ("DISPLAY=:XX firefox ...");"

You should look into this manual, I used this a while ago to do about the same:

http://www.alittlemadness.com/2008/03/05/running-selenium-headless/

TLDR;

$ export DISPLAY=:0
$ firefox

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM