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
Do you protect your variables? It's like you reused some class instance.spl_object_hash()
could help you out here. It
returns a unique identifier for the object
which is always the same for a given instance.
PS:
Try to separate them & use unittests /use the fixtures 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 }}
This example won't share the same $driver between both FirefoxTest and XXXTest but that is recommended as you will want a clean slate for each test.
However all the tests in FirefoxTest will share the same driver.The execution order of tests, when you do 'phpunit tests' will be: setUpBeforeClass()
setUp()testTitle()setUp()testSomethingElse()tearDownAfterClass()
a bit more about fixtures