Codeception 查看和点击功能使用 Selenium 运行 ChromeDriver 时出错
Codeception See and Click functions Error out with Selenium running ChromeDriver
我正在使用 selenium 运行 chrome 驱动程序为我的本地环境(即 MacOS,运行 代客 +)编写代码检测测试。当我尝试调用 see()
或 click()
之类的方法时遇到错误的问题。然而,其他功能如 seeInSource()
、executeJS()
和 grabPageSource()
工作正常。
例如:
$I->see('Go to au site'); //Errors out
而
$I->seeInSource('Go to au site') // works fine
我的acceptance.suite.yml如下
actor: AcceptanceTester
modules:
enabled:
# - PhpBrowser:
# url: http://npr.test/
- WebDriver:
url: http://npr.test/
browser: chrome
capabilities:
chromeOptions:
w3c: true
goog:chromeOptions:
w3c: true
- \Helper\Acceptance
extensions:
enabled:
- Codeception\Extension\RunProcess:
- chromedriver
step_decorators: ~
我在使用 see 或 click 时遇到的错误
php vendor/bin/codecept run acceptance --steps
Codeception PHP Testing Framework v4.1.21
Powered by PHPUnit 8.5.16 by Sebastian Bergmann and contributors.
Acceptance Tests (1) -------------------------------------------------------------------------------------------------------------------------
[RunProcess] Starting chromedriver
LandingPageCest: Landing page test
Signature: LandingPageCest:landingPageTest
Test: tests/acceptance/LandingPageCest.php:landingPageTest
Scenario --
I am on url "http://npr.test"
I am on page "/"
I see "Go to au site"
ERROR
----------------------------------------------------------------------------------------------------------------------------------------------
[RunProcess] Stopping chromedriver
Time: 6.38 seconds, Memory: 10.00 MB
There was 1 error:
---------
1) LandingPageCest: Landing page test
Test tests/acceptance/LandingPageCest.php:landingPageTest
[PHPUnit\Framework\Exception] Undefined index: ELEMENT at vendor/facebook/webdriver/lib/Remote/RemoteWebDriver.php:228
Scenario Steps:
3. $I->see("Go to au site") at tests/acceptance/LandingPageCest.php:16
2. $I->amOnPage("/") at tests/acceptance/LandingPageCest.php:15
1. $I->amOnUrl("http://npr.test") at tests/acceptance/LandingPageCest.php:14
#1 /Users/techlead/Projects/npr-testing/vendor/facebook/webdriver/lib/Remote/RemoteWebDriver.php:228
#2 Codeception\Module\WebDriver->see
#3 /Users/techlead/Projects/npr-testing/tests/_support/_generated/AcceptanceTesterActions.php:329
#4 /Users/techlead/Projects/npr-testing/tests/acceptance/LandingPageCest.php:16
#5 LandingPageCest->landingPageTest
Artifacts:
Png: /Users/techlead/Projects/npr-testing/tests/_output/LandingPageCest.landingPageTest.fail.png
Html: /Users/techlead/Projects/npr-testing/tests/_output/LandingPageCest.landingPageTest.fail.html
ERRORS!
Tests: 1, Assertions: 0, Errors: 1.
我也看过问题
Codeception: $i->see(text) but not $i->click(text)
这对我没有帮助,因为我将我的 wc3 设置为 true,如果我将它设置为 false,我的 selenium 将无法启动会话。
因此,在尝试了一些对我有用的方法之后,将我的 facebook/webdriver 替换为 php-webdriver。所以我的作曲家 json 看起来像。
{
"require": {
"php-webdriver/webdriver": "^1.11"
},
"require-dev": {
"codeception/codeception": "^4.1",
"codeception/module-phpbrowser": "^1.0.0",
"codeception/module-asserts": "^1.0.0",
"codeception/module-webdriver": "^1.2"
}
}
运行 在您的控制台上使用以下命令添加 php-驱动程序并删除 facebook/webdriver
composer require php-webdriver/webdriver
composer remove facebook/webdriver
我正在使用 selenium 运行 chrome 驱动程序为我的本地环境(即 MacOS,运行 代客 +)编写代码检测测试。当我尝试调用 see()
或 click()
之类的方法时遇到错误的问题。然而,其他功能如 seeInSource()
、executeJS()
和 grabPageSource()
工作正常。
例如:
$I->see('Go to au site'); //Errors out
而
$I->seeInSource('Go to au site') // works fine
我的acceptance.suite.yml如下
actor: AcceptanceTester
modules:
enabled:
# - PhpBrowser:
# url: http://npr.test/
- WebDriver:
url: http://npr.test/
browser: chrome
capabilities:
chromeOptions:
w3c: true
goog:chromeOptions:
w3c: true
- \Helper\Acceptance
extensions:
enabled:
- Codeception\Extension\RunProcess:
- chromedriver
step_decorators: ~
我在使用 see 或 click 时遇到的错误
php vendor/bin/codecept run acceptance --steps
Codeception PHP Testing Framework v4.1.21
Powered by PHPUnit 8.5.16 by Sebastian Bergmann and contributors.
Acceptance Tests (1) -------------------------------------------------------------------------------------------------------------------------
[RunProcess] Starting chromedriver
LandingPageCest: Landing page test
Signature: LandingPageCest:landingPageTest
Test: tests/acceptance/LandingPageCest.php:landingPageTest
Scenario --
I am on url "http://npr.test"
I am on page "/"
I see "Go to au site"
ERROR
----------------------------------------------------------------------------------------------------------------------------------------------
[RunProcess] Stopping chromedriver
Time: 6.38 seconds, Memory: 10.00 MB
There was 1 error:
---------
1) LandingPageCest: Landing page test
Test tests/acceptance/LandingPageCest.php:landingPageTest
[PHPUnit\Framework\Exception] Undefined index: ELEMENT at vendor/facebook/webdriver/lib/Remote/RemoteWebDriver.php:228
Scenario Steps:
3. $I->see("Go to au site") at tests/acceptance/LandingPageCest.php:16
2. $I->amOnPage("/") at tests/acceptance/LandingPageCest.php:15
1. $I->amOnUrl("http://npr.test") at tests/acceptance/LandingPageCest.php:14
#1 /Users/techlead/Projects/npr-testing/vendor/facebook/webdriver/lib/Remote/RemoteWebDriver.php:228
#2 Codeception\Module\WebDriver->see
#3 /Users/techlead/Projects/npr-testing/tests/_support/_generated/AcceptanceTesterActions.php:329
#4 /Users/techlead/Projects/npr-testing/tests/acceptance/LandingPageCest.php:16
#5 LandingPageCest->landingPageTest
Artifacts:
Png: /Users/techlead/Projects/npr-testing/tests/_output/LandingPageCest.landingPageTest.fail.png
Html: /Users/techlead/Projects/npr-testing/tests/_output/LandingPageCest.landingPageTest.fail.html
ERRORS!
Tests: 1, Assertions: 0, Errors: 1.
我也看过问题 Codeception: $i->see(text) but not $i->click(text) 这对我没有帮助,因为我将我的 wc3 设置为 true,如果我将它设置为 false,我的 selenium 将无法启动会话。
因此,在尝试了一些对我有用的方法之后,将我的 facebook/webdriver 替换为 php-webdriver。所以我的作曲家 json 看起来像。
{
"require": {
"php-webdriver/webdriver": "^1.11"
},
"require-dev": {
"codeception/codeception": "^4.1",
"codeception/module-phpbrowser": "^1.0.0",
"codeception/module-asserts": "^1.0.0",
"codeception/module-webdriver": "^1.2"
}
}
运行 在您的控制台上使用以下命令添加 php-驱动程序并删除 facebook/webdriver
composer require php-webdriver/webdriver
composer remove facebook/webdriver