如何在 Cucumber 中遵循 javascript 的重定向?

发布于 2024-09-17 08:13:18 字数 651 浏览 1 评论 0原文

我有一个按钮(不是提交按钮),它在提交另一个表单之前执行 ajax 调用。

我想做的是,

Given I am viewing homepage
When I press "JustAButton"
Then I should be on "/users/home"

但是重定向发生得有点晚,考虑到该页面仍在主页中,“然后”语句失败。我怎样才能等到ajax调用(点击按钮导致的)完成并且页面获得提交者?

有什么想法吗?

编辑:示例javascript代码

对于

<input type="button" id="btn_Send" value="Send"/>

Javascript来说是(请忽略语法错误,我想你会得到整体的想法)

document.ready(){
$("#btn_Send").click(function(){
   ajax.post('some url',<params>, callbackForSuccess);
}

function callbackForSuccess(result){
   $("#form1").submit();
}

I have a a button (not a submit button) which does ajax calls before submitting another form.

What I want to do is

Given I am viewing homepage
When I press "JustAButton"
Then I should be on "/users/home"

But the redirection happens somewhat late and "Then" statement fails considering that the page is still in homepage. How can I wait till the ajax calls (that result from clicking the button) are finished and the page gets submitter??

Any ideas?

EDIT : Sample javascript code

For

<input type="button" id="btn_Send" value="Send"/>

Javascript is (pls ignore the syntax errors, I think you would get the overall idea)

document.ready(){
$("#btn_Send").click(function(){
   ajax.post('some url',<params>, callbackForSuccess);
}

function callbackForSuccess(result){
   $("#form1").submit();
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

爱情眠于流年 2024-09-24 08:13:19

正确 - 在 JavaScript 有机会加载另一个寻呼机之前,“我应该打开”立即执行断言。

您需要定义一个步骤,等待浏览器位于指定页面(或超时)。

Correct - "I should be on" performs the assertion immediately, before the JavaScript has a chance to load another pager.

You will need to define a step that waits until the browser is on a specified page (or timeout).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文