无法让php-webdriver工作

时间:2015-03-29 11:24:03

标签: php ubuntu selenium composer-php browserstack

我想运行automated tests on browserstack,要求安装github.com/facebook/php-webdriver的库。

我正在使用运行Apache2的Ubuntu 14.04。

我正在遵循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并运行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)

2 个答案:

答案 0 :(得分:2)

这里有两个问题:

第一个问题

你的作曲家无法解析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.说硒已经运行了。如果您想再次运行,可以将进程杀死为:

$ $ 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

从selenium流程看到 3997 约为pid。改变你的pid。

或使用此命令运行selenium:

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

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

答案 1 :(得分:2)

只是想评论为什么GitHub自述文件页面没有建议使用“最小稳定性”:“dev”。这是因为这样做是一个坏主意/做法。

  

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

     

所以请不要这样做。

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