无法让 php-webdriver 工作

Can't get php-webdriver to work

我要运行都安装automated tests on browserstack which require that the libaries from github.com/facebook/php-webdriver

我正在开发 Ubuntu 14.04 运行ning Apache2。

我正在按照 GitHub 存储库中的 Get The Code 步骤进行操作,但是当我尝试 运行 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.

可能是我在packagist步骤中没有正确添加依赖?对于这一步,我将 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" 行?

我尝试继续 next step 和 运行ning 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)

更新

关于我对 运行 selenium jar 文件的问题的第二部分,我尝试了@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)

这里有两个问题:

第一题

您的作曲家无法解析来自 facebook/webdrive 和 minimum stability flags 的依赖项。 添加 "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.表示selenium已经运行ning了。如果你想要 运行 再次,你可以杀死进程:

$ $ 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 大约是来自 selenium 过程的 pid。更改您的 pid。

或 运行 selenium 使用此命令:

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

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

只是想评论为什么 GitHub 自述文件页面不建议使用 "minimum-stability":"dev"。因为这样做不好idea/practice

One way to fix the problem would be to just lower your minimum-stability down to "dev". But that's usually a really bad idea, because it applies to all constraints and as a result you will get unstable versions of all packages.

So please, don't do that.

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