php Codeception 启动不那么快 : [PHPUnit\Framework\Exception] Undefined index: ELEMENT

标签 php selenium-webdriver phpunit codeception

所以,我遵循了 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。

有什么想法吗?

最佳答案

问题显然是 Facebook 的 php-webdriver 与当前的 Firefox 不兼容。

These threads更详细地讨论该问题,以及 php-webdriver issue #469跟踪添加完整的 W3C WebDriver 支持(这将修复不兼容性)。

解决方法是在启动 Selenium 时添加 -enablePassthrough false 参数。例如:

java -Dwebdriver.gecko.driver=./geckodriver -jar selenium-server-standalone-3.8.1.jar -enablePassThrough false

不幸的是,Selenium removed support for pass through mode in 3.9 ,因此您必须使用旧版本。

另一个解决方法是切换到 Chrome。

关于php Codeception 启动不那么快 : [PHPUnit\Framework\Exception] Undefined index: ELEMENT,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46913377/

相关文章:

php - 我应该创建额外的函数来使我的代码可测试吗?

ubuntu - 无法在 Ubuntu 10.04 中安装最新的 phpUnit

PHP - 使用 require_once/include/require,路径相对于什么?

php - MySQL 按另一个表的计数排序

php - 将数据从 Drupal 发送到 node.js

selenium - 未为自定义 protractor.conf 文件创建 Webdriver 实例

php - mysql总工作时间

python-3.x - selenium.common.exceptions.ElementNotInteractableException : Message: element not interactable when clicking on an element using Selenium Python

java - IE 访问 http ://localhost:36559/with message "This is the initial start page for the WebDriver server"

phpunit - Laravel 黄昏改变了 URL