PHPUnit + Selenium 2.35 = BadMethodCallException

时间:2013-09-04 11:02:37

标签: selenium phpunit selenium-webdriver

我的英语不太好。遗憾。

我有:

PHPUnit 3.7.24
Selenium 2.35.0

我正在启动selenium服务器:

java -jar /usr/local/bin/selenium-server-standalone-2.35.0.jar 

输出:

04.09.2013 13:51:15 org.openqa.grid.selenium.GridLauncher main
INFO: Launching a standalone server
13:51:25.373 INFO - Java: Sun Microsystems Inc. 20.45-b01
13:51:25.374 INFO - OS: Linux 3.8.0-29-generic i386
13:51:25.388 INFO - v2.35.0, with Core v2.35.0. Built from revision c916b9d
13:51:25.542 INFO - RemoteWebDriver instances should connect to: http://127.0.0.1:4444/wd/hub
13:51:25.543 INFO - Version Jetty/5.1.x
13:51:25.544 INFO - Started HttpContext[/selenium-server/driver,/selenium-server/driver]
13:51:25.545 INFO - Started HttpContext[/selenium-server,/selenium-server]
13:51:25.546 INFO - Started HttpContext[/,/]
13:51:25.567 INFO - Started org.openqa.jetty.jetty.servlet.ServletHandler@dda25b
13:51:25.567 INFO - Started HttpContext[/wd,/wd]
13:51:25.571 INFO - Started SocketListener on 0.0.0.0:4444
13:51:25.577 INFO - Started org.openqa.jetty.jetty.Server@b61fd1

我的简单测试:

public function testTitle()
{
    $this->url('/');
    $this->assertEquals('My title.', $this->title());
}

接下来,使用命令运行phpunit test:

phpunit --debug functional/MainPageTest.php

输出:

PHPUnit 3.7.24 by Sebastian Bergmann.

Configuration read from /home/demyan112rv/www/boo/protected/tests/phpunit.xml
Starting test 'MainPageTest::testTitle'.
E

Time: 17.59 seconds, Memory: 2.75Mb
There was 1 error:

1) MainPageTest::testTitle
PHP Warning:  include(PHPUnit_Extensions_Story_TestCase.php): failed to open stream: No such file or directory in /home/demyan112rv/www/yii/YiiBase.php on line 421
PHP Warning:  include(): Failed opening 'PHPUnit_Extensions_Story_TestCase.php' for inclusion (include_path='.:/home/demyan112rv/www/boo/protected/helpers:/home/demyan112rv/www/boo/protected/widgets:/home/demyan112rv/www/boo/protected/extensions/mail:/home/demyan112rv/www/boo/protected/services:/home/demyan112rv/www/boo/protected/components:/home/demyan112rv/www/boo/protected/models:/usr/share/php:/usr/share/pear') in /home/demyan112rv/www/yii/YiiBase.php on line 421
BadMethodCallException: The command http://localhost:4444/wd/hub/session/url is not recognized by the server.

/home/demyan112rv/www/yii/test/CWeb2TestCase.php:60
/home/demyan112rv/www/boo/protected/tests/functional/MainPageTest.php:11
/home/demyan112rv/www/boo/protected/tests/functional/MainPageTest.php:11

FAILURES!
Tests: 1, Assertions: 0, Errors: 1.

此时在selenium服务器中有一个下一个输出:

13:55:39.438 INFO - Executing: [new session: {browserName=firefox}] at URL: /session)
13:55:39.452 INFO - Creating a new session for Capabilities [{browserName=firefox}]
13:55:56.642 INFO - Done: /session

我有错误“BadMethodCallException:服务器无法识别命令http:// localhost:4444 / wd / hub / session / url。”此错误在此link中修复为2.35,但我有2.35并且我有此错误。

如何解决这个问题?

解决方案(我不会回答我的问题,因为我的评分低于10。

$ whereis phpunit
phpunit: /usr/bin/phpunit /usr/bin/X11/phpunit /usr/local/bin/phpunit

我有3条通往phphunit的途径。我不知道,这是正常的还是没有。

当我改变命令时:

phpunit --debug functional/MainPageTest.php

/usr/bin/phpunit --debug functional/MainPageTest.php

它正在工作!!!

1 个答案:

答案 0 :(得分:0)

如果您已设置浏览器启动方法,即


    function setUp()
      {
        $this->setBrowser("*firefox");
        $this->setBrowserUrl("http://www.google.com/");
      }

你的功能应该是这样的


    public function testTitle()
    {
        $this->open('/');
        $this->assertEquals('My title.', $this->title());
    }

我已经改变了这个 - > URL( '/');到$ this - >打开('/'); 请立即尝试。