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

前端之家收集整理的这篇文章主要介绍了php – 如何从codeception和phantomjs测试中获取当前url?前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我正在使用我的测试在estore中创建产品,并且需要在提交表单后获取URL.

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

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

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

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

怎么做?

解决方案是在_support / AcceptanceHelper.PHP文件中为AcceptanceHelper添加一个帮助方法
  1. class AcceptanceHelper extends \Codeception\Module
  2. {
  3.  
  4. /**
  5. * Get current url from WebDriver
  6. * @return mixed
  7. * @throws \Codeception\Exception\ModuleException
  8. */
  9. public function getCurrentUrl()
  10. {
  11. return $this->getModule('WebDriver')->_getCurrentUri();
  12. }
  13.  
  14. }

然后在测试中使用它:

  1. $url = $I->getCurrentUrl();

猜你在找的PHP相关文章