Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Php webdriver - how to force new test to use different profile?

I'm running multiple tests across a Selenium grid containing a multiple nodes, using a dynamically created Firefox profile, like this:

$firefoxProfile = new FirefoxProfile();
$capabilities = DesiredCapabilities::firefox ();
$capabilities->setCapability(FirefoxDriver::PROFILE, $firefoxProfile);

$this->webdriver = RemoteWebDriver::create("http://my.tests.com", $capabilities, 5000);

But every time the hub picks up a node with a previous running Firefox instance it uses the same profile and drops the previously running session. It happens because the application uses the same cookies for authentication purposes.

Is there some way to force selenium grid to create a new profile on the fly and get a totally new firefox instance?

Some further information

For getting the hub started I currently use the following command line

    java -jar /opt/selenium/selenium-server.jar -trustAllSSLCertificates -timeout  300 \
                                        -role hub -newSessionWaitTimeout 60 -maxSession 2 \
                                        -port 9444 -nodeTimeout 300 \
                                        -browserTimeout 300 &

And to get nodes started I use

    xvfb-run -n 99 --server-args="-screen 0 800x600x16 -ac"  \
      -a java -jar /opt/selenium/selenium-server.jar -role node \
                 -browser browserName=firefox,maxInstances=2 \
                 -hub http://my.tests.com:9444/grid/register 

The weird thing is that when I set up a standalone Selenium server it creates multiple firefox instances as I would like to be...

like image 221
Omar Alves Avatar asked Mar 01 '16 02:03

Omar Alves


1 Answers

You could also try an alternative lightweight Selenium replacement called Selenoid. The main difference is that it starts every browser in new Docker container. This guarantees that your sessions are completely isolated.

like image 132
vania-pooh Avatar answered Oct 11 '22 18:10

vania-pooh