You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Codeception $I->see()方法在WebDriver环境下失效求助

Codeception WebDriver模块下$I->see()抛出foreach()无效参数错误

我在使用Codeception框架时,$I->see()方法在PhpBrowser模块下可以正常运行,但切换到WebDriver模块后,抛出如下错误:

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

我的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');
    }
}

我已经按照文档完成WebDriver与Selenium的配置,恳请帮忙解决这个问题。


可能的解决方案:

  • 确认Selenium Server处于运行状态
    打开浏览器访问http://localhost:4444/wd/hub(默认端口),能正常打开页面说明服务启动正常。若未启动,执行java -jar selenium-server-standalone-{version}.jar启动服务。

  • 替换占位符为实际可访问URL
    将acceptance.suite.yml中url字段的{website url here}替换为完整的网站地址,比如http://localhost:8000,必须包含协议(http/https)。

  • 匹配ChromeDriver与Chrome版本
    确保ChromeDriver版本和本地Chrome浏览器版本完全兼容,版本不匹配会导致WebDriver连接异常。可以在配置中指定ChromeDriver路径:

    - WebDriver:
        url: 'http://your-website-url'
        browser: chrome
        path: '/path/to/chromedriver'
    
  • 更新php-webdriver依赖库
    执行composer update php-webdriver/webdriver,将库更新到最新稳定版,避免旧版本的已知bug。

  • 等待页面完全加载后再断言
    在$I->see('Login');前添加等待逻辑,确保页面元素加载完成:

    $I->amOnPage('/');
    $I->waitForPageLoad();
    $I->see('Login');
    

内容的提问来源于stack exchange,提问作者AdamOB

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.16 13:45:30