php - mac/php 的正确 Codeception(Selenium 服务器,chromedriver)故障排除程序是什么?
问题描述
由于没有官方的故障排除信息,因此对于没有更全面了解使用类似系统进行安装的任何人来说,这是一场艰苦的斗争。
我想解决专门针对OSX Catalina和Selenium 服务器/Chromedriver 配置的问题,并将它们放在一个地方。我还将在最后包括我的问题。
在我看来,大多数问题都围绕着:
- Selenium、Codeception 或 Chromedriver 安装不正确
- 以上(或php?)的冲突版本
- Selenium 服务器运行的端口问题
- 编码错误:错别字、旧代码等
- 缺乏终端/java命令的知识
- 路径问题
- 任何我不知道的/我的问题
我将从我一路上学到的东西开始,如果你能,请帮助填补空白或纠正我在下面陈述的任何内容。
安装不正确
- 通过自制软件安装似乎是最简单的方法。
硒
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
- 缺乏终端/java命令的知识
使用在终端中运行代码接收测试
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: ~
解决方案
这个关于 Selenium 如何工作的优秀解释指南带来了突破。
我错误地认为 WebDriver 的 url 是 Selenium 服务器 url,但它实际上是我的 MAMP url。
所以我将代码中的端口更改为我的 MAMP url:
- WebDriver:
url: 'http://localhost:8888/wd/hub'
browser: chrome
- \Helper\Acceptance
瞧,一天的工作终于完成了。哈利路亚!希望这可以帮助其他人。
推荐阅读
- spring-mvc - 使用 GPC 部署 Spring MVC 应用程序:Cloud SQL、Kubernetes(服务和入口)和带有 Google 托管证书的 HTTP(S) 负载均衡器
- intellij-idea - IntelliJ IDEA 的 JVM 调试器内存视图
- rust - `UnsafeCell` 是 Rust 中的编译器优化障碍吗?
- json - 在 go 中解析自定义 JSON,类型动态确定
- javascript - 单击新图标时,地图图标不会恢复到正常大小
- html - 如何使用标签管理器跟踪与 Facebook 聊天插件的互动?
- css - 如何在移动设备上将 div 内的元素对齐为 2-3 行(响应式)
- go - 无需硬编码类型或将类型信息存储在数组中的类型检查
- reactjs - 使用 CRACO 禁用文件分块
- linux - 如何减去日期