可以';t让php-webdriver工作


Can't get php-webdriver to work

我想在browserstack上运行自动化测试,这需要安装github.com/facebook/php-webdriver中的库。

我在Ubuntu 14.04上运行Apache2。

我正在遵循GitHub repo中的"获取代码"步骤,但当我尝试运行php composer.phar install时,我会收到一些警告,说我缺少包和外部。

php-webdriver: (master)$ php composer.phar install
Loading composer repositories with package information
Installing dependencies (including require-dev)
Your requirements could not be resolved to an installable set of packages.
  Problem 1
    - phpdocumentor/phpdocumentor v2.0.0 requires phpdocumentor/template-zend ~1.3 -> satisfiable by phpdocumentor/template-zend[1.3.0, 1.3.1, 1.3.2].
    - phpdocumentor/phpdocumentor v2.0.1 requires phpdocumentor/template-zend ~1.3 -> satisfiable by phpdocumentor/template-zend[1.3.0, 1.3.1, 1.3.2].
    - phpdocumentor/phpdocumentor v2.1.0 requires phpdocumentor/template-zend ~1.3 -> satisfiable by phpdocumentor/template-zend[1.3.0, 1.3.1, 1.3.2].
    - phpdocumentor/phpdocumentor v2.2.0 requires phpdocumentor/template-zend ~1.3 -> satisfiable by phpdocumentor/template-zend[1.3.0, 1.3.1, 1.3.2].
    - phpdocumentor/phpdocumentor v2.3.2 requires phpdocumentor/template-zend ~1.3 -> satisfiable by phpdocumentor/template-zend[1.3.0, 1.3.1, 1.3.2].
    - phpdocumentor/phpdocumentor v2.4.0 requires phpdocumentor/template-zend ~1.3 -> satisfiable by phpdocumentor/template-zend[1.3.0, 1.3.1, 1.3.2].
    - phpdocumentor/phpdocumentor v2.5.0 requires phpdocumentor/template-zend ~1.3 -> satisfiable by phpdocumentor/template-zend[1.3.0, 1.3.1, 1.3.2].
    - phpdocumentor/phpdocumentor v2.6.0 requires phpdocumentor/template-zend ~1.3 -> satisfiable by phpdocumentor/template-zend[1.3.0, 1.3.1, 1.3.2].
    - phpdocumentor/phpdocumentor v2.6.1 requires phpdocumentor/template-zend ~1.3 -> satisfiable by phpdocumentor/template-zend[1.3.0, 1.3.1, 1.3.2].
    - phpdocumentor/phpdocumentor v2.7.0 requires phpdocumentor/template-zend ~1.3 -> satisfiable by phpdocumentor/template-zend[1.3.0, 1.3.1, 1.3.2].
    - phpdocumentor/phpdocumentor v2.7.1 requires phpdocumentor/template-zend ~1.3 -> satisfiable by phpdocumentor/template-zend[1.3.0, 1.3.1, 1.3.2].
    - phpdocumentor/phpdocumentor v2.8.0 requires phpdocumentor/template-zend ~1.3 -> satisfiable by phpdocumentor/template-zend[1.3.0, 1.3.1, 1.3.2].
    - phpdocumentor/phpdocumentor v2.8.1 requires phpdocumentor/template-zend ~1.3 -> satisfiable by phpdocumentor/template-zend[1.3.0, 1.3.1, 1.3.2].
    - phpdocumentor/phpdocumentor v2.8.2 requires phpdocumentor/template-zend ~1.3 -> satisfiable by phpdocumentor/template-zend[1.3.0, 1.3.1, 1.3.2].
    - phpdocumentor/phpdocumentor v2.3.1 requires dompdf/dompdf dev-master@dev -> no matching package found.
    - phpdocumentor/phpdocumentor v2.3.0 requires dompdf/dompdf dev-master@dev -> no matching package found.
    - phpdocumentor/template-zend 1.3.2 requires ext-xsl * -> the requested PHP extension xsl is missing from your system.
    - phpdocumentor/template-zend 1.3.1 requires ext-xsl * -> the requested PHP extension xsl is missing from your system.
    - phpdocumentor/template-zend 1.3.0 requires ext-xsl * -> the requested PHP extension xsl is missing from your system.
    - Installation request for phpdocumentor/phpdocumentor 2.* -> satisfiable by phpdocumentor/phpdocumentor[v2.0.0, v2.0.1, v2.1.0, v2.2.0, v2.3.0, v2.3.1, v2.3.2, v2.4.0, v2.5.0, v2.6.0, v2.6.1, v2.7.0, v2.7.1, v2.8.0, v2.8.1, v2.8.2].
Potential causes:
 - A typo in the package name
 - The package is not available in a stable-enough version according to your minimum-stability setting
   see <https://groups.google.com/d/topic/composer-dev/_g3ASeIFlrc/discussion> for more details.
Read <http://getcomposer.org/doc/articles/troubleshooting.md> for further common problems.

也许我没有正确地在包装步骤中添加依赖项?在这一步中,我将composer.json文件更新为:

{
  "name": "facebook/webdriver",
  "description": "A php client for WebDriver",
  "keywords": ["webdriver", "selenium", "php", "facebook"],
  "homepage": "https://github.com/facebook/php-webdriver",
  "type": "library",
  "license": "Apache-2.0",
  "support": {
    "issues": "https://github.com/facebook/php-webdriver/issues",
    "forum": "https://www.facebook.com/groups/phpwebdriver/",
    "source": "https://github.com/facebook/php-webdriver"
  },
  "require": {
    "php": ">=5.3.19",
    "facebook/webdriver": "dev-master"
  },
  "require-dev": {
    "phpunit/phpunit": "3.7.*",
    "phpdocumentor/phpdocumentor": "2.*"
  },
  "autoload": {
    "classmap": ["lib/"]
  }
}

我是否正确添加了"facebook/webdriver": "dev-master"行?

我试着继续下一步并运行java -jar selenium-server-standalone-2.45.0.jar,但后来在终端中出现了这个错误。

php-webdriver: (master)$ java -jar selenium-server-standalone-2.45.0.jar 
12:21:07.240 INFO - Launching a standalone server
12:21:07.318 INFO - Java: Oracle Corporation 24.75-b04
12:21:07.318 INFO - OS: Linux 3.13.0-46-generic amd64
12:21:07.390 INFO - v2.45.0, with Core v2.45.0. Built from revision 5017cb8
12:21:07.557 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
12:21:07.656 INFO - RemoteWebDriver instances should connect to: http://127.0.0.1:4444/wd/hub
12:21:07.659 INFO - Version Jetty/5.1.x
12:21:07.660 INFO - Started HttpContext[/selenium-server/driver,/selenium-server/driver]
12:21:07.666 INFO - Started HttpContext[/selenium-server,/selenium-server]
12:21:07.667 INFO - Started HttpContext[/,/]
12:21:07.739 INFO - Started org.openqa.jetty.jetty.servlet.ServletHandler@2a4c6a7d
12:21:07.739 INFO - Started HttpContext[/wd,/wd]
12:21:07.742 WARN - Failed to start: SocketListener0@0.0.0.0:4444
Exception in thread "main" java.net.BindException: Selenium is already running on port 4444. Or some other service is.
    at org.openqa.selenium.server.SeleniumServer.start(SeleniumServer.java:491)
    at org.openqa.selenium.server.SeleniumServer.boot(SeleniumServer.java:300)
    at org.openqa.selenium.server.SeleniumServer.main(SeleniumServer.java:245)
    at org.openqa.grid.selenium.GridLauncher.main(GridLauncher.java:97)

更新

关于我问题的第二部分,即运行硒罐文件,我尝试了@acfreitas bellow建议的解决方案,但仍然收到了相同的错误消息。

php-webdriver: (master)$ kill -9 {pid from selenium process}
bash: kill: {pid: arguments must be process or job IDs
bash: kill: from: arguments must be process or job IDs
bash: kill: selenium: arguments must be process or job IDs
bash: kill: process}: arguments must be process or job IDs
php-webdriver: (master)$ ps aux | grep selenium
ross      3451  0.0  0.7 2413344 45508 pts/12  Tl   14:53   0:00 java -jar selenium-server-standalone-2.45.0.jar
ross      7874  0.0  0.0  15940   944 pts/12   S+   16:14   0:00 grep --color=auto selenium
php-webdriver: (master)$ java -jar selenium-server-standalone-2.45.0.jar
16:15:00.689 INFO - Launching a standalone server
16:15:00.767 INFO - Java: Oracle Corporation 24.75-b04
16:15:00.767 INFO - OS: Linux 3.13.0-46-generic amd64
16:15:00.833 INFO - v2.45.0, with Core v2.45.0. Built from revision 5017cb8
16:15:00.984 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:15:01.062 INFO - RemoteWebDriver instances should connect to: http://127.0.0.1:4444/wd/hub
16:15:01.063 INFO - Version Jetty/5.1.x
16:15:01.064 INFO - Started HttpContext[/selenium-server/driver,/selenium-server/driver]
16:15:01.065 INFO - Started HttpContext[/selenium-server,/selenium-server]
16:15:01.065 INFO - Started HttpContext[/,/]
16:15:01.142 INFO - Started org.openqa.jetty.jetty.servlet.ServletHandler@2a4c6a7d
16:15:01.143 INFO - Started HttpContext[/wd,/wd]
16:15:01.156 WARN - Failed to start: SocketListener0@0.0.0.0:4444
Exception in thread "main" java.net.BindException: Selenium is already running on port 4444. Or some other service is.
    at org.openqa.selenium.server.SeleniumServer.start(SeleniumServer.java:491)
    at org.openqa.selenium.server.SeleniumServer.boot(SeleniumServer.java:300)
    at org.openqa.selenium.server.SeleniumServer.main(SeleniumServer.java:245)
    at org.openqa.grid.selenium.GridLauncher.main(GridLauncher.java:97)

这里有两个问题:

第一个问题

您的composer无法解析facebook/webdrive和最低稳定性标志的依赖关系。添加"minimum-stability": "dev"

{
  "name": "facebook/webdriver",
  "description": "A php client for WebDriver",
  "keywords": ["webdriver", "selenium", "php", "facebook"],
  "homepage": "https://github.com/facebook/php-webdriver",
  "type": "library",
  "license": "Apache-2.0",
  "support": {
    "issues": "https://github.com/facebook/php-webdriver/issues",
    "forum": "https://www.facebook.com/groups/phpwebdriver/",
    "source": "https://github.com/facebook/php-webdriver"
  },
  "minimum-stability": "dev",
  "require": {
    "php": ">=5.3.19",
    "facebook/webdriver": "dev-master"
  },
  "require-dev": {
    "phpunit/phpunit": "3.7.*",
    "phpdocumentor/phpdocumentor": "2.*"
  },
  "autoload": {
    "classmap": ["lib/"]
  }
}

并运行

$ php composer.phar install

第二个问题

端口默认的Selenium是4444Exception in thread "main" java.net.BindException: Selenium is already running on port 4444. Or some other service is.说硒已经在运行。若你们想再次运行,你们可以终止进程为:

$ $ ps aux | grep selenium
root   3997  2.6  3.2 465024 33336 pts/0    Sl+  15:40   0:00 java -jar selenium-server-standalone-2.45.0.jar
$ kill -9 3997

请参阅3997是关于硒过程的pid。更改你的pid。

或者使用以下命令运行selenium:

$ java -jar selenium-server-standalone-2.45.0.jar -role hub -port 4441

因此,您应该在测试中编辑主机端口。更多信息,您可以查看文档

我只是想评论一下为什么GitHub Readme页面不建议使用"最低稳定性":"dev"。这是因为这样做是个坏主意/坏做法

解决问题的一种方法是降低最低稳定性降至"dev"。但这通常是一个非常糟糕的主意,因为它适用于所有约束,因此您将得到所有包的不稳定版本。

所以请不要那样做。

(参见https://igor.io/2013/02/07/composer-stability-flags.html)