With ruby, I'm doing some cucumber tests with capybara to test a Shiny application (
shiny is a R package to do web applications). But I'm a newbie with ruby and cucumber (and this is my first post here).
I have a scenario like this:
Given a user uses the application When he sets the x-axis limits "10,20,30" And he clicks on the changeaxis button Then the graph has no error
Currently, I expect that this test should fail, i.e. there should be an error on the graph.
The application displays a graph in a
div with id
graph. When the user sets the axis limits "10,20,30" and clicks on the "changeaxis" button, there is an error in the application: Shiny assigns the class
error to the
div containing the graph. Then my above scenario tries to check that the
div with id
graph containing the class
error does not exist:
Then (/^the graph has no error$/) do @screen.graph_page.check_graph_has_no_error end def check_graph_has_no_error check_element_is_not_present GRAPH_ERROR end GRAPH_ERROR = "//div[(@id='graph') and (@class and contains(concat(' ', normalize-space(@class), ' '), ' error '))]" def check_element_is_not_present xpath should have_no_selector(:xpath, xpath) end
The test does not fail. That's because things go too fast: the class
error is assigned on the element
<div id="graph"> only after the user clicks the button.
I have a workaround using
Given a user uses the application When he sets the x-axis limits "10,20,30" And he clicks on the changeaxis button And he waits for 5 seconds Then the graph has no error And (/^he waits for (\d+) seconds?/) do |n| sleep(n.to_i) end
Here the test fails, as expected.
But is there a way without using