【问题标题】:Selenium server - PHPUnit can't connectSelenium 服务器 - PHPUnit 无法连接
【发布时间】:2014-08-20 23:33:31
【问题描述】:

我尝试对 PHP Unit & Selenium 服务器进行一些测试。 我有一个难以置信的问题,我不知道为什么。

我正在使用最新的 Selenium 支架服务器 2.42.2。当我运行服务器时,它显示:

root@test:/home/jakub# java -jar /usr/local/bin/selenium-server-standalone-2.42.2.jar
Jun 30, 2014 4:32:53 PM org.openqa.grid.selenium.GridLauncher main
INFO: Launching a standalone server
16:32:53.398 INFO - Java: Oracle Corporation 24.51-b03
16:32:53.399 INFO - OS: Linux 3.12-1-amd64 amd64
16:32:53.413 INFO - v2.42.2, with Core v2.42.2. Built from revision 6a6995d
16:32:53.508 INFO - Default driver org.openqa.selenium.ie.InternetExplorerDriver 
registration is skipped: registration capabilities Capabilities [{platform=WINDOWS,  
ensureCleanSession=true, browserName=internet explorer, version=}] does not match
with    
current platform: LINUX
16:32:53.563 INFO - RemoteWebDriver instances should connect to: 
http://test.jacon.cz:4444/wd/hub
16:32:53.564 INFO - Version Jetty/5.1.x
16:32:53.565 INFO - Started HttpContext[/selenium-server/driver,/selenium-server
/driver]
16:32:53.566 INFO - Started HttpContext[/selenium-server,/selenium-server]
16:32:53.566 INFO - Started HttpContext[/,/]
16:34:07.013 INFO - Started org.openqa.jetty.jetty.servlet.ServletHandler@7cbae009
16:34:07.014 INFO - Started HttpContext[/wd,/wd]
16:34:07.022 INFO - Started SocketListener on 0.0.0.0:4444
16:34:07.023 INFO - Started org.openqa.jetty.jetty.Server@17056563

Selenium 服务器似乎运行正常。但是当我尝试使用 PHPUnit 在 php 中运行简单测试时,它说它无法连接到 Selenium 服务器。

root@test:/home/jakub# /usr/local/bin/phpunit --verbose sel.php
PHPUnit 4.1.3 by Sebastian Bergmann.

SS

Time: 73 ms, Memory: 3.25Mb

There were 2 skipped tests:

1) loginTest::testLoginTrue
The Selenium Server is not active on host http://test.jacon.cz at port 4444.

2) loginTest::testLoginFalse
The Selenium Server is not active on host http://test.jacon.cz at port 4444.

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

我通过 netstat -apn | 进行了检查grep 4444 如果 Selenium 服务器正在侦听端口 4444 并且它正在侦听。有人知道如何解决这个问题吗?我用谷歌搜索,但没有任何结果。

顺便说一句。这是php中的测试代码:

<?php
class loginTest extends PHPUnit_Extensions_Selenium2TestCase
{
protected $captureScreenshotsOnFailure = TRUE;
protected $screenshotsPath = '';
    protected $screenshotsUrl = '';

protected function SetUp()
  {
  $this->setBrowser('chrome');
  $this->setBrowserUrl('http://test.jacon.cz/');
  //$this->setPort(4444);
  //$this->setTimeout(2);
  $this->setHost("http://test.jacon.cz");
}

public function testLoginTrue()
  {
      $this->url('/sms');
  $this->byName('username')->value('Kristyna');
  $this->byName('password')->value('*****');
  $this->byCssSelector('form')->submit();
      $url = $this->url();
  $this->assertEquals('Statistics', $this->title(), 'Přihlášení neproběhlo');
  $this->assertStringEndsWith('sms/', $this->url(), 'Přihlášení neproběhlo');
  }

     public function testLoginFalse()
  {
  $this->url('/sms');
  $this->byName('username')->value('abcdefgh');
  $this->byName('password')->value('123456');
  $this->byCssSelector('form')->submit();
      $url = $this->title();
  $this->assertEquals('Login to SM', $this->title(), 'Přihlášení proběhlo');
  }
}
?>

希望您能提供帮助。谢谢。

【问题讨论】:

  • 我没有遇到同样的问题,但我更幸运的是扩展 PHPUnit_Extensions_SeleniumTestCase 而不是 PHPUnit_Extensions_Selenium2TestCase
  • 感谢提示,但没有任何成就。
  • 您是否尝试运行 Selenium Grid?
  • 不,我正在运行标准 selenium 独立服务器,运行命令中没有任何参数。

标签: php selenium phpunit


【解决方案1】:

对 php 不乐观...但是。

Selenium Standalone 是“GRID”服务器。您必须将同一服务器注册为集线器和节点,才能在浏览器上获取和执行。我还建议您创建一个传入的配置文件……目前它说的是 windows,平台实际上是 linux。

因此,您启动独立系统以允许 GRID 运行。

    java -jar /usr/local/bin/selenium-server-standalone-2.42.2.jar -role hub

然后将集线器注册为运行它的同一台机器...使用配置文件指示应该可用的内容。

    java -jar /usr/local/bin/selenium-server-standalone-2.42.2.jar -role node -hub http://localhost:4444/grid/register

一旦启动,您应该能够在http://test.jacon.cz:4444/grid/console 打开控制台。通常,您需要配置文件中的参数,因为这是您指定要注册的浏览器和并发运行数的方式。

GRID 参考:https://code.google.com/p/selenium/wiki/Grid2

【讨论】:

  • 感谢提示,我试过了,我看到了 webadmin,但似乎 xvfb 坏了。顺便提一句。我认为他们的手册不是很有帮助。
【解决方案2】:

我一直在做一些非常相似的事情,但是是在 Python 中。但我不必运行 Selenium 服务器。我所要做的就是下载 selenium 模块,我很高兴。也许在 PHP 中可能是一样的?我真的不知道服务器是做什么用的,您只需要模拟浏览器的驱动程序,还是 Python 自己在某个地方运行服务器?

【讨论】:

    【解决方案3】:

    PHPUnit 安装错误的问题。现在一切正常,非常感谢所有提示和答案。

    【讨论】:

    • 你能解释一下到底是什么问题吗?是版本不兼容吗?
    • 据我记得,路径和浏览器模拟存在问题......
    猜你喜欢
    • 2016-12-16
    • 2010-11-13
    • 2012-01-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-19
    相关资源
    最近更新 更多