How can I send headless Selenium RC tests via an external proxy server?
I need to use Selenium RC on a headless Ubuntu server to run tests against a website using an external proxy server to simulate a user in a different country.
To test the process, I've created a really simple PHPUnit test script, which basically does:
$this->setBrowser("*firefox");
$this->setBrowserUrl("http://www.ipchicken.com/");
$this->open("/");
$this->assertTrue($this->isTextPresent(<proxy ip>));
I start my Selenium RC using these proxy server directives (there's no authentication on the proxy):
export DISPLAY=":99" && java -Dhttp.proxyHost=<proxy ip> -Dhttp.proxyPort=<proxy port> -jar /var/lib/selenium/selenium-server.jar -avoidProxy
but my test script fails the assertion. If I change th开发者_运维问答e test to assert for my Selenium server IP address, the assertion passes, which makes it look to me as though Selenium is sending the "open" request directly to ipchicken.com, and not sending it through the proxy server.
The selenium server can access the proxy server OK - I've tested this with a simple PHP Curl script. If I request ipchicken.com using Curl through the proxy server, it returns the proxy server IP address just fine.
I experienced the same issue trying to get a proxy to work on an Ubuntu system and was unable to get the -Dhttp.proxyHost etc... settings to work. My solution was to export http_proxy prior to the java command - just like you're doing with the DISPLAY.
export http_proxy = http://username:password@host:port
Update: Since you are using firefox, you'll also need to set appropriate proxy settings within firefox. (The hang you mention in your comment is firefox failing to go through the proxy). You'll need to run the firefox profilemanager with
firefox -ProfileManager
then create a new profile. Create a new directory for the profile's path since it will put a large number of files in that location. Within that profile create the appropriate proxy settings. You can now use the firefoxProfileTemplate option with the selenium rc:
java -jar ..... -firefoxProfileTemplate /path/to/your/new/profile
Note that you'll only need to run the profile manager once, so thereafter you'll be able to run headless.
I will explain in short using Selenium Grid
1. First start the display on using Xorg:96 -ac on Linux
2. Now export the DISPLAY=96.
3. start firefox
4. Start the Selenium Port using selenium grid.
The Above steps should be done on Linux Server.
1. Before starting the selenium server on linux start the hub on your machine.
2. Now execute the the script it will go to the active port on linux.
Thanks
精彩评论