Php webdriver - how to make a new test use a different profile?

I run several tests on a Selenium grid containing multiple nodes using a dynamically created Firefox profile, for example:

$firefoxProfile = new FirefoxProfile(); $capabilities = DesiredCapabilities::firefox (); $capabilities->setCapability(FirefoxDriver::PROFILE, $firefoxProfile); $this->webdriver = RemoteWebDriver::create("http://my.tests.com", $capabilities, 5000); 

But each time the hub selects a node with a previous instance of Firefox, it uses the same profile and discards the previous session. This is because the application uses the same cookies for authentication purposes.

Is there a way to get the selenium grid to create a new profile on the fly and get a completely new instance of firefox?

Additional Information

To start the hub, 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 run the nodes 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 strange thing is that when I set up a standalone Selenium server, it creates multiple instances of firefox, as I would like to be ...

+8
php selenium webdriver
source share
2 answers

You can also try an alternative Selenium lightweight replacement called Selenoid . The main difference is that it launches each browser in a new Docker container. This ensures that your sessions are completely isolated.

+1
source share

I run several tests on a selenium grid containing multiple nodes using a dynamically created Firefox profile like this

Do you protect your variables? This is similar to reusing an instance of a class. spl_object_hash() can help you here. it

returns a unique identifier for an object

which is always the same for a given instance.

PS:

Try to separate them and use unittests / to use the tools available in PHPUnit /:

 class BaseTestCase extends PHPUnit_Framework_TestCase { static $driver; private $capabilities; public function setCapabilities($capabilities) { $this->capabilities = $capabilities; } public static function setUpBeforeClass() { $host = 'http://my.tests.com'; self::$driver = RemoteWebDriver::create($host, $this->capabilities, 5000); } public static function tearDownAfterClass() { self::$driver->close(); } public function getDriver() { return self::$driver; } } class FirefoxTest extends BaseTestCase { public function setUp() { $firefoxProfile = new FirefoxProfile(); $capabilities = DesiredCapabilities::firefox (); $capabilities->setCapability(FirefoxDriver::PROFILE, $firefoxProfile); self->setCapabilities($capabilities); $this->getDriver()->get("http://my.tests.com/x"); } public function testTitle() { echo $this->getDriver()->getTitle(); } public function testSomethingElse() { // do test } } 

In this example, the same $ driver between FirefoxTest and XXXTest will not be used, but this is recommended since you will need a clean list for each test.

However, all tests in FirefoxTest will share the same driver. The order of execution of the tests when you execute the "phpunit tests" will be: setUpBeforeClass ()

 setUp() testTitle() setUp() testSomethingElse() tearDownAfterClass() 

little more about fixtures

0
source share

All Articles