如何在 Cucumber 中遵循 javascript 的重定向?
我有一个按钮(不是提交按钮),它在提交另一个表单之前执行 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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
正确 - 在 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).