Navigating through the browser history in a cucumber feature using selenium
In order to navigate through the browser history. you can manipulate the window.history object via javascript like follows:
When /^I go back in the browser history$/ do
page.evaluate_script('window.history.back()')
end
For further functions of the window and history objects check out this link Show archive.org snapshot .
An improved version of this step is now part of our gem spreewald on Github Show archive.org snapshot .
Related cards:
Mock the browser time or time zone in Selenium features
In Selenium features the server and client are running in separate processes. Therefore, when mocking time with a tool like Timecop, the browser controlled by Selenium will still see the unmocked system ...
How to grep through the DOM using the Capybara API
When your Cucumber feature needs to browse the page HTML, and you are not sure how to express your query as a clever CSS or XPath expression, there is another way: You can use [all
](http://rubydoc.info/github/jnicklas/capybara/master/Capybara/No...
Hack of the day: One-liner to run all Cucumber features matching a given string
The following will search for all .feature
files containing a search term and run them using geordi.
find features/ -name '*.feature' | xargs grep -li 'YOUR SEARCH TERM' | sort -u | tr '\n' ' ' | xargs ...
Synchronize a Selenium-controlled browser with Capybara
When you click a link or a press a button on a Selenium-controlled browser, the call will return control to your test before the next page is loaded. This can lead to concurrency issues when a Cucumber step involves a Selenium action and a Ruby ca...
Prevent the selenium webbrowser window from closing after a failed @javascript step
When cucumber encounters a failing step in a @javascript feature, the selenium browser window instantly closes. Sometimes you do not want that, because you need to see what is going on. You can click through the data your feature created, when you...
"Show me the page" fails to open a browser window
If you get an error like this:
Unable to launch /home/bruce/Projects/myproject/tmp/capybara/capybara-201110311210111407691101.html
... update your launchy
gem. It failed for us in version 0.4.x. We could fix the issue by upgrading to 2.0.5.
Hide your Selenium browser window with a VNC server
This is now part of geordi. Please don't follow the instructions below, if you use geordi.
Inspired by the recent [headless Selenium note](https://makandracards.com/makandra/1391-how-to-hide-your-...
Why your Cucumber feature loses cookies when run under Selenium
When your Cucumber feature seems to forget cookies / sessions when you run it with Selenium check if the test travels in time like here:
Given the date is 2017-10-20
When I sign in
Then I should see "Welcome!"
What happens here i...
Cucumber step to manually trigger javascript events in Selenium scenarios (using jQuery)
When you cannot make Selenium trigger events you rely on (e.g. a "change" event when filling in a form field), trigger it yourself using this step:
When /^I manually trigger a (".*?") event on (".*?")$/ do |event, selector|
page.execute_s...
Click on a piece of text in Cucumber / Capyabra
The step definition below lets you write:
When I click on "Foo"
This is useful in Selenium features where the element you click on is not necessarily a link or button, but could be any HTML element with a Javascript event binding.
The e...