PHPUnit with selenium


PHPUnit with selenium

我正在尝试将PHPUnit与硒一起使用

我启动服务器java-jar c:/examplep/selenium-server-standalone-2.18.0.jar

这是我的测试

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());
  }
}

页面上存在id为"1-m-0"的项,但测试失败,因为它将元素设为null。我尝试过其他元素,SeleniumTestCase类(使用相同的服务器),但运气不好!

我做错了什么?

好的,找到了。这是我现在的课:

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);
    }
  }
}

这篇文章帮助了我:http://devzone.zend.com/1014/acceptance-testing-of-web-applications-with-php/

我正在使用这个硒服务器:硒服务器-标准-2.18.0.jar

如果您发现phpunit库有点令人困惑,我们创建了一个与Selenium Json Wire Protocol交互的库,但我们的目标是使其与官方文档示例尽可能相似。因此,Java中selenium站点的一个示例在php中具有几乎相同的语法。

看看:https://github.com/Nearsoft/PHP-SeleniumClient

如果你喜欢它,分享它,参与进来,分叉它或做你想做的事:)

问候,马克。