Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>The fix for this really depends on what your data file looks like. If you could post that we could help you more.</p> <p>For the time being I'm assuming since phpunit by nature is a one-at-a-time unit testing framework that you're not attempting to run multiple browsers simultaneously, but just want to reserve the option to change browsers as you see fit.</p> <p>You're right that you should be using setBrowser in setUp. When executed PHPUnit will always run setUp first, and tearDown() last. A good practice here is to make your own custom unit-test-case class where you can customize these methods.</p> <pre><code>class customUnitTest extends PHPUnit_Extensions_Selenium2TestCase { public $browser = "firefox"; public function setUp() { $this-&gt;setBrowser("*".$browser); } } </code></pre> <p>Now when you're writing a test extend your personal test class and set the browser accordingly</p> <pre><code>class newTest extends customUnitTest { $this-&gt;browser = "safari"; public function testBlah { blah blah... } } </code></pre> <p>setUp will be run on execution, and it will pull in the browser variable. By default you'll get firefox but if some tests are more appropriately tested on other browsers you have that option.</p> <p>If you're looking to be able to change all browsers across all tests simultaneously you should look into assigning the browser value based on an environment variable.</p> <pre><code>class customUnitTest extends PHPUnit_Extensions_Selenium2TestCase { try { public $browser = getenv("SELENIUM_BROWSER"); } catch (Exception $e) { public $browser = "firefox"; } public function setUp() { $this-&gt;setBrowser("*".$browser); } } </code></pre> <p>With this setup we can change the browser for every test that hasn't hard-coded the browser within itself by changing the environment variable SELENIUM_BROWSER. This way we can run the same code on different servers with different default browsers without having to re-write anything.</p> <p>Note that multiple inheritence is not good practice. It can lead to brittle code and even security threats if you don't scope you methods/variables correctly. However in this case it's useful because we can define the PHPUnit framework methods as we please, and we get all the base selenium methods within our test. So to run a default selenium method we just write</p> <pre><code>$this-&gt;open("www.google.com"); </code></pre> <p>This is a much different method than the general approach of assigning selenium to an object, as the test you write IS the selenium object, but it seems more php appropriate, especially for this use case.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload