2

I am trying to use PHPUnit with selenium

I start the server java -jar c:/xampp/selenium-server-standalone-2.18.0.jar

This is my test

require_once 'PHPUnit/Extensions/Selenium2TestCase.php';

class WebTest extends PHPUnit_Extensions_Selenium2TestCase {
  protected function setUp() {
    $this->setBrowser("*chrome");
    $this->setBrowserUrl("http://localhost/");
  }

  public function testMyTestCase() {
    $this->url('my/url/index.php');
    $link = $this->byId('1-m-0');
    $this->assertEquals('11', $link->text());
  }
}

Item with id="1-m-0" exists on page, but test fails cause it gets element as null. I have tried with other elements, SeleniumTestCase class (with the same server) but not luck !

What i do wrong?

2 Answers 2

4

Ok, found it out. Here is my class now :

class WebTest extends PHPUnit_Extensions_SeleniumTestCase {
  protected function setUp() {
    $this->setBrowser("*firefox");
    $this->setBrowserUrl("http://localhost/");
  }

  public function testPlay() {
    $this->open('http://localhost/my/url/index.php');
    $this->waitForPageToLoad(4000);
    // Wait for ajax to load
    $this->waitForCondition("selenium.browserbot.getCurrentWindow().$('#mytable').length > 0");
    $ids = array(
      '1-m-0',
      '2-n-1',
    );
    // Click ids
    foreach ($ids as $v) {
      $xpath = "xpath=//button[@id='{$v}']";
      $this->assertElementPresent($xpath);
      $this->click($xpath);
    }
  }
}

This article helped me: http://devzone.zend.com/1014/acceptance-testing-of-web-applications-with-php/

I m using this selenium server: selenium-server-standalone-2.18.0.jar

Sign up to request clarification or add additional context in comments.

1 Comment

waitForPageToLoad and waitForPageToLoad cause "BadMethodCallException: The command 'waitForPageToLoad' is not existent or not supported yet." What does it depend on?
0

In case you find the phpunit library a little bit confusing we created a library that interacts with the Selenium Json Wire Protocol but we aimed to make it as similar as possible with the official documentation examples. So an example from the selenium site in Java would have nearly the same syntax in php.

Check it out: https://github.com/Nearsoft/PHP-SeleniumClient

If you like it share it, get involved, fork it or do as you please :)

Regards, Mark.

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.