首页 > 解决方案 > mac/php 的正确 Codeception(Selenium 服务器,chromedriver)故障排除程序是什么?

问题描述

由于没有官方的故障排除信息,因此对于没有更全面了解使用类似系统进行安装的任何人来说,这是一场艰苦的斗争。

我想解决专门针对OSX CatalinaSelenium 服务器/Chromedriver 配置的问题,并将它们放在一个地方。我还将在最后包括我的问题

在我看来,大多数问题都围绕着:

我将从我一路上学到的东西开始,如果你能,请帮助填补空白或纠正我在下面陈述的任何内容。

安装不正确

brew install selenium-server-standalone

铬驱动程序

brew tap homebrew/cask
brew cask install chromedriver

然后您可以运行brew doctor以检查安装是否正常并按照说明或谷歌问题进行操作。更多 brew 命令

安装的 Google Chrome 和 Chromedriver 应该是同一版本。

通过转到应用程序左上角的“Chrome”和“关于 Google Chrome”来检查 Chrome。

通过运行检查 Chromedriverbrew info chromedriver

您可能在尝试使用的端口上运行旧服务器。将其关闭到谷歌浏览器中的此页面。

http://localhost:<port number>/selenium-server/driver?cmd=shutDownSeleniumServer

您可以使用 -port 标志指定在终端中运行 Selenium 的端口。像这样

java -jar <location of your server> -port 8090

然后在您的acceptance.suite.yml 配置文件中匹配它

url: 'http://localhost:<port number>/wd/hub'

我见过的最常见的是在上面代码行的末尾有一个斜杠或不包括'/wd/hub'

格式化是这样的:

actor: AcceptanceTester
modules:
    enabled:
        - WebDriver:
            url: 'http://192.168.88.100:<port number>/wd/hub'
            browser: chrome
        - \Helper\Acceptance

并且格式化扩展(自动运行)是这样的:

extensions:
    enabled:
        - Codeception\Extension\RunProcess:
            - chromedriver

使用在终端中运行代码接收测试

php vendor/bin/codecept run acceptance --steps

您必须首先使用

cd <location of your code>

我不知道如何检查路径配置是否正确。(它们是否在指向其他程序的配置文件中?)但我一直看到它们的提示分散在各处。

从下面的日志中,我认为 chromedriver 正在加载并且浏览器中发生了一些事情,但它没有加载我的网站。相反,它会加载下面的页面。非常感谢帮助!

加载的测试页面截图

日志:

Codeception PHP Testing Framework v4.1.8
Powered by PHPUnit 9.4.2 by Sebastian Bergmann and contributors.
Running with seed: 


Acceptance Tests (1) --------------------------------------------------------------------------------------------------

  [RunProcess] Starting chromedriver
QuizCest: New user_complete quiz
Signature: QuizCest:newUser_completeQuiz
Test: tests/acceptance/QuizCest.php:newUser_completeQuiz
Scenario --
 I am on page "/"
 I see "Fragrant"
 FAIL 

-----------------------------------------------------------------------------------------------------------------------
  [RunProcess] Stopping chromedriver


Time: 00:02.653, Memory: 10.00 MB

There was 1 failure:

---------
1) QuizCest: New user_complete quiz
 Test  tests/acceptance/QuizCest.php:newUser_completeQuiz
 Step  See "Fragrant"
 Fail  Failed asserting that  on page /wd/hub/static/resource/hub.html
--> Sessions
Create Session  |  Refresh Sessions
Chrome
e999201a1381fb966c9d02785c094ae6  |  Capabilities  |  Take Screenshot  |  Delete Session  |  Load Script
 Mac OS X 10.15.7  |  v3.141.59  |  re82be7d358
--> contains "Fragrant".

Scenario Steps:

 2. $I->see("Fragrant") at tests/acceptance/QuizCest.php:14
 1. $I->amOnPage("/") at tests/acceptance/QuizCest.php:13

Artifacts:

Png: /Applications/MAMP/htdocs/fragrantmandarin.com/tests/_output/QuizCest.newUser.completeQuiz.fail.png
Html: /Applications/MAMP/htdocs/fragrantmandarin.com/tests/_output/QuizCest.newUser.completeQuiz.fail.html

FAILURES!
Tests: 1, Assertions: 1, Failures: 1.

我的配置文件:

actor: AcceptanceTester
modules:
    enabled:
        - WebDriver:
            url: 'http://localhost:4444/wd/hub'
            browser: chrome
        - \Helper\Acceptance

extensions:
    enabled:
        - Codeception\Extension\RunProcess:
            - chromedriver

step_decorators: ~     

标签: phpmacosseleniumtestingcodeception

解决方案


这个关于 Selenium 如何工作的优秀解释指南带来了突破。

我错误地认为 WebDriver 的 url 是 Selenium 服务器 url,但它实际上是我的 MAMP url。

所以我将代码中的端口更改为我的 MAMP url:

- WebDriver:
            url: 'http://localhost:8888/wd/hub'
            browser: chrome
        - \Helper\Acceptance

瞧,一天的工作终于完成了。哈利路亚!希望这可以帮助其他人。


推荐阅读