【问题标题】:Codeception $I->see() action doesn't work with WebDriverCodeception $I->see() 动作不适用于 WebDriver
【发布时间】:2022-10-23 20:35:16
【问题描述】:

相同的操作适用于 PhpBrowser,但只要我在 Acceptance.suite.yml 中设置 WebDriver,它就会引发以下错误:

[PHPUnit\Framework\Exception] Invalid argument supplied for foreach() at vendor/php-webdriver/webdriver/lib/Remote/RemoteWebDriver.php:240

我遵循了使用 Selenium 设置 WebDriver 的文档。这是我的acceptance.suite.yml 的样子:

actor: AcceptanceTester
modules:
    enabled:
        - WebDriver:
            url: '{website url here}'
            browser: chrome
        - \Helper\Acceptance
step_decorators: ~   

这是我的验收测试文件:

<?php

class FirstAcceptanceCest
{
    public function _before(AcceptanceTester $I)
    {
    }

    public function seeLoginInFrontPage(AcceptanceTester $I)
    {
        $I->amOnPage('/');
        $I->see('Login');
    }
}

任何帮助将不胜感激。

【问题讨论】:

    标签: php testing webdriver codeception acceptance-testing


    【解决方案1】:

    再次在 php-webdriver 库中处理不充分的错误。

    https://github.com/php-webdriver/php-webdriver/blob/1.13.1/lib/Remote/RemoteWebDriver.php#L228-L245

    $raw_elements = $this->execute(
        DriverCommand::FIND_ELEMENTS,
        JsonWireCompat::getUsing($by, $this->isW3cCompliant)
    );
    
    if ($raw_elements === null) {
        throw new UnknownErrorException('Unexpected server response to findElements command');
    }
    
    $elements = [];
    foreach ($raw_elements as $raw_element) {
        $elements[] = $this->newElement(JsonWireCompat::getElement($raw_element));
    }
    

    我的调试建议是添加

    if (!is_array($raw_elements) && !is_object($raw_elements)) {
      var_dump($raw_elements); die;
    }
    

    foreach 之前,看看输出是否有助于理解根本原因。

    【讨论】:

      猜你喜欢
      • 2017-02-11
      • 1970-01-01
      • 2017-03-25
      • 1970-01-01
      • 1970-01-01
      • 2022-07-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多