加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 站长学院 > PHP教程 > 正文

php – 如何从codeception和phantomjs测试中获取当前url?

发布时间:2020-12-13 13:25:38 所属栏目:PHP教程 来源:网络整理
导读:我正在使用我的测试在estore中创建产品,并且需要在提交表单后获取URL. 提交按钮后是否可以在测试范围内获取URL? $I-click('#formSubmit');$I-wait(5); // wait for redirect to new url$url = $I-someFunctionToGetCurrentUrl()` 我从控制台运行此测试,而不
我正在使用我的测试在estore中创建产品,并且需要在提交表单后获取URL.

提交按钮后是否可以在测试范围内获取URL?

$I->click('#formSubmit');
$I->wait(5); // wait for redirect to new url
$url = $I->someFunctionToGetCurrentUrl()`

我从控制台运行此测试,而不是从Web浏览器运行,因此我无法访问服务器端的$_??SERVER.

但是,如果我在代码框架中有一些像$I-> canSeeCurrentUrlEquals()这样的方法,那么我应该能以某种方式访问??当前的URL …

怎么做?

解决方案是在_support / AcceptanceHelper.php文件中为AcceptanceHelper添加一个帮助方法:
class AcceptanceHelper extends CodeceptionModule
    {

        /**
         * Get current url from WebDriver
         * @return mixed
         * @throws CodeceptionExceptionModuleException
         */
        public function getCurrentUrl()
        {
            return $this->getModule('WebDriver')->_getCurrentUri();
        }

    }

然后在测试中使用它:

$url = $I->getCurrentUrl();

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读