【发布时间】:2026-02-24 06:10:01
【问题描述】:
所以,我忠实地遵循了 Codeception Quick Start instructions。我使用 PhpBrowser 运行第一个示例测试...
# Codeception Test Suite Configuration
#
# [further comments omitted]
#
actor: AcceptanceTester
modules:
enabled:
- PhpBrowser:
url: 'http://office.localhost/'
browser: 'firefox'
- \Helper\Acceptance
和测试:
<?php
class FirstCest
{
public function frontpageWorks(AcceptanceTester $I)
{
$I->amOnPage('/');
$I->see('We hope you enjoy it');
}
}
一切都很好。
然后我把配置改成这样:
actor: AcceptanceTester
modules:
enabled:
- WebDriver:
url: 'http://office.localhost/'
browser: 'firefox'
- \Helper\Acceptance
按照说明,我已经安装并启动并运行了 Selenium,然后我们就走了......
1) FirstCest: Frontpage works
Test tests/acceptance/FirstCest.php:frontpageWorks
[PHPUnit\Framework\Exception] Undefined index: ELEMENT
Scenario Steps:
2. $I->see("InterpretersOffice") at tests/acceptance/FirstCest.php:22
1. $I->amOnPage("/") at tests/acceptance/FirstCest.php:21
#1 /opt/www/court-interpreters-office/vendor/facebook/webdriver/lib/Remote/RemoteWebDriver.php:198
#2 Codeception\Module\WebDriver->see
#3 /opt/www/court-interpreters-office/tests/_support/_generated/AcceptanceTesterActions.php:363
#4 /opt/www/court-interpreters-office/tests/acceptance/FirstCest.php:22
#5 FirstCest->frontpageWorks
Selenium 正在驱动 Firefox,页面已加载,$I 想要 see() 的内容在那里,所以这不是问题。我已经在源头上戳了一下,但还没有弄清楚。我尝试将 $I->see() 更改为 $I->seeInSource() 并发现确实有效,FWIW。
有什么想法吗?
【问题讨论】:
-
当前版本的 Firefox 似乎与 facebook/webdriver 不兼容,因为 facebook/webdriver 尚未实现新协议。
-
你得到的错误是由facebook/webdriver代码中的错误处理不充分直接引起的:github.com/facebook/php-webdriver/blob/1.4.1/lib/Remote/…欢迎你做一些调试,看看那里实际发生了什么。
-
先做简单的事。只需使用 Chrome 而不是 Firefox。
-
phptest.club/t/does-anyone-set-up-selenium-3-and-codeception/… 似乎暗示“只使用 Chrome 而不是 Firefox”是目前唯一可用的解决方案。仅供参考,我确实进行了一些调试,检查了github.com/facebook/php-webdriver/blob/1.4.1/lib/Remote/… 发生的情况,而且——毫不奇怪——index 'ELEMENT' 确实是未定义的。
标签: php selenium-webdriver phpunit codeception