【问题标题】:PHPUnit with selenium带有硒的 PHPUnit
【发布时间】:2012-02-24 12:39:43
【问题描述】:

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

我启动服务器 java -jar c:/xampp/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" 的项目,但测试失败,因为它获取元素为空。 我尝试过使用其他元素,SeleniumTestCase 类(使用相同的服务器),但没有运气!

我做错了什么?

【问题讨论】:

    标签: php selenium phpunit selenium-webdriver


    【解决方案1】:

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

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

    如果您喜欢它,请分享、参与、分叉或随心所欲:)

    问候,马克。

    【讨论】:

      【解决方案2】:

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

      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/

      我正在使用这个 selenium 服务器:selenium-server-standalone-2.18.0.jar

      【讨论】:

      • waitForPageToLoad 和 waitForPageToLoad 导致“BadMethodCallException:命令 'waitForPageToLoad' 不存在或尚不受支持。”它取决于什么?
      猜你喜欢
      • 2013-03-22
      • 2016-01-07
      • 1970-01-01
      • 1970-01-01
      • 2011-02-16
      • 1970-01-01
      • 2017-03-16
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多