2

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();
}
Jey Geethan
  • 2,235
  • 5
  • 33
  • 60
  • Are you running that Cucumber scenario with a driver that supports Javascript e.g. Selenium? If not, the javascript/ajax on your page won't execute when your scenario runs. – Sidane Sep 02 '10 at 09:12
  • @sidane, yea i am doing it. normal ajax calls are being handled properly. but when there are javascript form submits, it does not recognise them – Jey Geethan Sep 03 '10 at 08:03
  • Ok. And this behaviour works if you test it manually in the browser? Can you post any of your code to give a clearer idea of what you're doing? – Sidane Sep 03 '10 at 08:26
  • I have added an edit. And it works manually in the browser. Thanks – Jey Geethan Sep 06 '10 at 14:19

1 Answers1

0

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).

Wojtek Kruszewski
  • 13,940
  • 6
  • 38
  • 38