在页面上打开Javascript重定向-> open [英] Javascript redirects on page->open

查看:86
本文介绍了在页面上打开Javascript重定向-> open的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用behat/mink,我正在测试记住我"功能.从功能上讲,当用户访问主页时,javascript/ajax代码将验证用户是否被记住".如果是,则javascripts重定向到另一个页面.我的LoginPage$path = '/login.html'定义-重定向后,我将在/main.html上结束.

在我的上下文中,我使用$loginPage->open()-但这会引发异常Expected to be on "https://example.com/login.html" but found "https://example.com/main.html" instead.自然,这会中止执行并导致测试失败-但这正是我想要的行为.

如何告诉behat/mink 验证URL或忽略URL不匹配?

解决方案

如果您检查open()方法,您将发现对校验()方法中的url参数进行检查时,失败的检查就是您. >

如果要避免这种情况,可以重写此方法以仅检查响应,而不检查url参数.

为此,您需要扩展Page并声明一个新方法,如下所示:

 public function verify(array $urlParameters){
    $this->verifyResponse();
}

Using behat/mink, I'm testing the "remember me" functionality. Functionally, when the user visits the main page, javascript/ajax code verifies if the user is "remembered". If yes, then the javascripts redirects to another page. My LoginPage is defined with $path = '/login.html' - after the redirect, I will end up on /main.html.

In my context, I use $loginPage->open() - however this throws exception Expected to be on "https://example.com/login.html" but found "https://example.com/main.html" instead. Naturally, this aborts the execution and results in the test failing - yet this is exactly the behaviour I want.

How can I tell behat/mink to not verify URL or ignore URL mismatch?

解决方案

If you check the open() method you will see that the check that fails for you is when is checking the url parameters in verify() method.

If you want to avoid this you can override this method to check only for the response and not the url parameters.

In order to do this you need to extend Page and declare a new method like this:

 public function verify(array $urlParameters){
    $this->verifyResponse();
}

这篇关于在页面上打开Javascript重定向-> open的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆