4

I want to add a suite of Selenium tests as part of a global PHPUnit test suite for an application. I have hooked the suite of Selenium tests into the global AllTests.php file and everything runs fine whilst the Selenium server is running.

However, I would like the script to skip the Selnium tests if the Selenium server isn't running so other developers aren't forced to install Selenium server in order for the tests to run. I would normally try to connect within the setUp method of each testcase and mark the tests as skipped if this failed, but this seems to throw a RuntimeException with message:

The response from the Selenium RC server is invalid: ERROR Server Exception: sessionId should not be null; has this session been started yet?

Does anyone have a method for marking the Selenium tests as skipped in this scenario?

3 Answers 3

2

You could use test dependencies that were introduced in PHPUnit 3.4.

Basically

  1. write a test that checks whether Selenium is up.
  2. If not, call $this->markTestAsSkipped().
  3. Make all your selenium requiring tests depend on this one.
Sign up to request clarification or add additional context in comments.

1 Comment

I'm using PHPUnit 3.7.x, and this method is called markTestSkipped($optionalMessage), excluding "as".
0

My preferred selenium / PHPUnit Configuration:

Maintaining integration (selenium) tests can be a lot of work. I use the firefox selenium IDE for developing test cases, which doesn't support exporting test suites to PHPUnit, and only supports individual test cases. As such - if I had to maintain even 5 tests, that'd be a lot of manual work to re-PHPUnit them every time they needed to be updated. That is why I setup PHPUnit to use Selenium IDE's HTML Test files! They can be reloaded & reused between PHPUnit & selenium IDE

<?php 
class RunSeleniumTests extends PHPUnit_Extensions_SeleniumTestCase {
    protected $captureScreenshotOnFailure = true;
    protected $screenshotPath = 'build/screenshots';
    protected $screenshotUrl = "http://localhost/site-under-test/build/screenshots";
    //This is where the magic happens! PHPUnit will parse all "selenese" *.html files
    public static $seleneseDirectory = 'tests/selenium';
    protected function setUp() {
            parent::setUp();
            $selenium_running = false;
            $fp = @fsockopen('localhost', 4444);
            if ($fp !== false) {
                    $selenium_running = true;
                    fclose($fp);
            }
            if (! $selenium_running)
                $this->markTestSkipped('Please start selenium server');

            //OK to run tests
            $this->setBrowser("*firefox");
    $this->setBrowserUrl("http://localhost/");
    $this->setSpeed(0);
    $this->start();
            //Setup each test case to be logged into WordPress
            $this->open('/site-under-test/wp-login.php');
            $this->type('id=user_login', 'admin');
            $this->type('id=user_pass', '1234');
            $this->click('id=wp-submit');
            $this->waitForPageToLoad();
    }
    //No need to write separate tests here - PHPUnit runs them all from the Selenese files stored in the $seleneseDirectory above!
} ?>

Comments

0

You can try skipWithNoServerRunning() For more information follow this link

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.