【问题标题】:Selenium RC throws sessionsid should not be null exception with assertTextPresent, phpunit 3.4 bug only?Selenium RC 抛出 sessionid 不应该是带有 assertTextPresent 的空异常,仅 phpunit 3.4 错误?
【发布时间】:2013-02-10 21:37:49
【问题描述】:

我希望将我的 selenium RC 测试从 PHPUnit 3.3.2 迁移到使用 PHPUnit 3.4.12。

当我使用assertTextPresent() 时,selenium 测试将失败,但以下情况除外:

PHPUnit_Framework_Exception: Response from Selenium RC server for getLocation().
ERROR Server Exception: sessionId should not be null; has this session been started yet?.

例如:

public function testSending($browser)
{
   ...
   $browser->click("send");
   $browser->waitForPageToLoad("30000");
   $browser->assertTextPresent("text");                
}

以下是 selenium RC 日志(在 Windows 上运行):

15:40:19.676 INFO - Command request: isTextPresent[text, ] on session 153d03a123c42098711994f43c2db34
15:40:19.691 INFO - Got result: OK,false on session 153d023a123c42098711994f43cdb34
15:40:19.879 INFO - Command request: testComplete[, ] on session 153d023a123c4298711994f43c2db34
15:40:19.879 INFO - Killing Firefox...
15:40:20.269 INFO - Got result: OK on session 153d023a123c42098711994f43c2db34
15:40:20.472 INFO - Command request: getLocation[, ] on session null
15:40:20.472 ERROR - Exception running 'getLocation 'command on session null
java.lang.NullPointerException: sessionId should not be null; has this session been started yet?

如您所见,测试应该已完成,如“Killing Firefox”位所示,但它继续执行其他操作并触发导致异常的 getLocation[, ] 命令。

我已尝试使用 PHPUnit 3.3.2 进行相同的测试,但没有产生此问题 - 如果没有 getLocation(),测试将愉快地结束。

有什么想法吗?

【问题讨论】:

  • 在 PHPUnit 3.3.2 中通过了完全相同的测试?在 Selenium 会话停止后,您的拆解中似乎有一些东西。有任何自定义侦听器吗?
  • 嗨戴夫,感谢您的评论。我的拆解中有以下内容:protected function tearDown() { if ($this->autoStop) { try { $this->stop(); } 捕捉 (RuntimeException $e) { } } }

标签: selenium phpunit selenium-rc


【解决方案1】:

实际上问题在于 setAutoStop() 方法 - 默认情况下它设置为 TRUE,因此 PHPUnit 在 tearDown() 之前向 Selenium RC 发送停止信号。

$this->setAutoStop(false); 添加到您的setUp() 方法,并将$this->stop(); 添加到tearDown() 的末尾。

【讨论】:

    猜你喜欢
    • 2017-09-05
    • 1970-01-01
    • 2011-05-27
    • 2020-03-08
    • 2020-12-21
    • 2011-07-16
    • 2018-03-31
    • 2021-05-14
    • 1970-01-01
    相关资源
    最近更新 更多