尽管服务器正在运行,PHPUnit仍然报告Selenium Server处于非活动状态

时间:2016-06-02 03:57:58

标签: php selenium selenium-webdriver phpunit selenium-ide

我不知道为什么PHPUnit会说:

The Selenium Server is not active on host http://127.0.0.1:4444/wd/hub at port 4444.

我通过此命令从桌面启动了我的Selenium Server:

java -jar selenium-server-standalone-2.53.0.jar

我得到了这个日志:

enter image description here

有几个司机没有注册。我不知道为什么,但我只是关注SeleniumHQ网站上的简短安装指南。

接下来,我开始尝试运行我从Selenium IDE生成的PHPUnit测试脚本,并将其导出为PHPUnit_Extensions_SeleniumTest2Case。以下是我的设置代码的外观:

<?php
require __DIR__ . '/vendor/autoload.php';
class Example extends PHPUnit_Extensions_Selenium2TestCase
{
  protected function setUp()
  {
    $this->setHost('http://127.0.0.1:4444/wd/hub');
    $this->setPort(4444);
    $this->setBrowser("*firefox");
    $this->setBrowserUrl("http://localhost/testing");
  }

我继续以详细模式在这个脚本上运行PHPUnit,但我不知道它为什么一直说:

The Selenium Server is not active on host http://127.0.0.1:4444/wd/hub at port 4444.

我可以通过浏览器轻松访问http://127.0.0.1:4444/wd/hub。所以,我很确定我的Selenium服务器已在运行。

PHPUnit始终以此​​结果终止:

OK, but incomplete, skipped, or risky tests!
Tests: 1, Assertions: 0, Skipped: 1.

我还需要做些什么来让PHPUnit和Selenium工作?

1 个答案:

答案 0 :(得分:-1)

setHost()应该只有主持人部分

$this->setHost('127.0.0.1');

除此之外,我建议使用简单的PHPUnit,PageObjects和稍微更活跃/维护的WebDriver包装器,如php-webdriver,因为它将允许您更好地处理/集成跨浏览器测试提供程序作为BrowserStack。 /> 但那只是我的意见:))