Last active
December 14, 2015 06:49
-
-
Save DylanLacey/5046283 to your computer and use it in GitHub Desktop.
An example of how to convert exported Selenium IDE tests into runnable tests with Sauce
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
# rubygems manages gem loading | |
require "rubygems" | |
require "selenium-webdriver" | |
# test::unit is now part of the standard suite | |
require "test/unit" | |
class RubyExample < Test::Unit::TestCase | |
def setup | |
# set up capabilities | |
caps = Selenium::WebDriver::Remote::Capabilities.firefox | |
caps.version = "6" | |
caps.platform = "Mac 10.6" | |
caps[:name] = "An Example Script that's super awesome" | |
@driver = Selenium::WebDriver.for( | |
:remote, | |
:url => "http://username:[email protected]/wd/hub", | |
:desired_capabilities => caps | |
) | |
@base_url = "http://translink.com.au/" | |
@accept_next_alert = true | |
@driver.manage.timeouts.implicit_wait = 30 | |
@verification_errors = [] | |
end | |
def teardown | |
@driver.quit | |
assert_equal [], @verification_errors | |
end | |
def test_ruby_example | |
@driver.get(@base_url + "/") | |
@driver.find_element(:id, "start-location").clear | |
@driver.find_element(:id, "start-location").send_keys "Moorooka Station" | |
@driver.find_element(:id, "end-location").clear | |
@driver.find_element(:id, "end-location").send_keys "Central Station" | |
@driver.find_element(:css, "input.blueButton").click | |
end | |
def element_present?(how, what) | |
@driver.find_element(how, what) | |
true | |
rescue Selenium::WebDriver::Error::NoSuchElementError | |
false | |
end | |
def verify(&blk) | |
yield | |
rescue Test::Unit::AssertionFailedError => ex | |
@verification_errors << ex | |
end | |
def close_alert_and_get_its_text(how, what) | |
alert = @driver.switch_to().alert() | |
if (@accept_next_alert) then | |
alert.accept() | |
else | |
alert.dismiss() | |
end | |
alert.text | |
ensure | |
@accept_next_alert = true | |
end | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Exported as Test::Unit from Selenium IDE | |
require "selenium-webdriver" | |
gem "test-unit" | |
require "test/unit" | |
class RubyExample < Test::Unit::TestCase | |
def setup | |
@driver = Selenium::WebDriver.for :firefox | |
@base_url = "http://translink.com.au/" | |
@accept_next_alert = true | |
@driver.manage.timeouts.implicit_wait = 30 | |
@verification_errors = [] | |
end | |
def teardown | |
@driver.quit | |
assert_equal [], @verification_errors | |
end | |
def test_ruby_example | |
@driver.get(@base_url + "/") | |
@driver.find_element(:id, "start-location").clear | |
@driver.find_element(:id, "start-location").send_keys "Beenleigh Station" | |
@driver.find_element(:id, "end-location").clear | |
@driver.find_element(:id, "end-location").send_keys "Central Station" | |
@driver.find_element(:css, "input.blueButton").click | |
end | |
def element_present?(how, what) | |
@driver.find_element(how, what) | |
true | |
rescue Selenium::WebDriver::Error::NoSuchElementError | |
false | |
end | |
def verify(&blk) | |
yield | |
rescue Test::Unit::AssertionFailedError => ex | |
@verification_errors << ex | |
end | |
def close_alert_and_get_its_text(how, what) | |
alert = @driver.switch_to().alert() | |
if (@accept_next_alert) then | |
alert.accept() | |
else | |
alert.dismiss() | |
end | |
alert.text | |
ensure | |
@accept_next_alert = true | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment