I am using ajax to bring up a selection. The user has to click one item in the selection.
a. Ajax takes some time, do I need a delay in the test, and if so how? b. The selection appears as multiple
items and the class in the tag defines it as clickable item. How do I tell cucumber to sel开发者_C百科ect an item from the selection?
Regards
Elan Noy
To introduce delay you could use traditional waiting mechanics:
$browser.select_list(:id,'selection_field').select('first item') # Watir uses set or select
sleep 2 # Wait 2 seconds
$browser.select_list(:id,'selection_field').set('second item') # Watir uses set or select
I am under the assumption that 'selection appears as multiple' means that a user can use 'Ctrl+LeftClick' to select multiple items in the list. In that case, the following code above should allow you to continue to set/select items until your heart is content.
http://wiki.openqa.org/display/WTR/Selection+Boxes
What you should aim to do here is to verify that the select element is present on the page before trying to interact with it.
You don't specify what you are actually using to drive your browser. But, for example, if you are using capybara, there is a has_select?
method, which, usefully, will automatically wait a short time for the element to appear if it is not found immediately, precisely to handle the kind of AJAX situation you describe.
Selenium has a wait_for_element_present
method which does much the same thing.
In general, the pattern to use basically this:
- Assert that the item is present on the page, using some method which will retry if it isn't immediately there, and times out if it does not appear after a set amount of time
- Attempt interacting with the element once you are certain it is on the page
精彩评论