Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8738319
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T10:42:32+00:00 2026-06-13T10:42:32+00:00

I wrote a test case with PHPUnit extension Selenium2TestCase . It does work nice,

  • 0

I wrote a test case with PHPUnit extension Selenium2TestCase. It does work nice, but I can’t figure out how make automatically run this test on various browsers.

There is a method setBrowser() which it only works in setUp() method. I thought about something like this:

/**
 * @dataProvider browsers
 */
public function loginTest($browser) {
    $this->setBrowser($browser);
    // tests...
}

But I does not work. Try runs default browser (Propably I have a small mess with Safari, last time uses firefox)

RuntimeException: Safari could not be found in the path!
Please add the directory containing ''Safari'' to your PATH environment
variable, or explicitly specify a path to Safari like this:
*safari /blah/blah/Safari

PS. SeleniumTestCase (not based on webdriver) provides a xml config where we can specify browsers. Selenium2TestCase does not support it.

Any suggestions are welcome. Thanks.
Marcin

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T10:42:33+00:00Added an answer on June 13, 2026 at 10:42 am

    The fix for this really depends on what your data file looks like. If you could post that we could help you more.

    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.

    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.

    class customUnitTest extends PHPUnit_Extensions_Selenium2TestCase {
       public $browser = "firefox";
       public function setUp() {
          $this->setBrowser("*".$browser);
       }
    }
    

    Now when you’re writing a test extend your personal test class and set the browser accordingly

    class newTest extends customUnitTest {
       $this->browser = "safari";
       public function testBlah {
          blah blah...
       }
    }
    

    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.

    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.

    class customUnitTest extends PHPUnit_Extensions_Selenium2TestCase {
       try {
          public $browser = getenv("SELENIUM_BROWSER");
       } catch (Exception $e) {
          public $browser = "firefox";
       }
       public function setUp() {
          $this->setBrowser("*".$browser);
       }
    }
    

    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.

    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

    $this->open("www.google.com");
    

    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.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

According to the link below, I wrote a small test case. But it doesn't
I wrote a little test case for a model I created in Yii and
I wrote a test case that extends AbstractTransactionalJUnit4SpringContextTests . The single test case I've
Looking at the last JUnit test case I wrote, I called log4j's BasicConfigurator.configure() method
I have a PHPUnit test case class (consisting of some test functions). I would
I am using JUNIT4 + Spring and wrote a test case. I wired in
I can't seem to test a function I wrote in PLT Racket using the
I have to write integration test case for my one feature listing page and
I am trying to write a test case for the depot application. Below is
This is for Play! Framework 2.0. I'm trying to write a simple test case

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.