Last active
January 4, 2016 21:49
-
-
Save mogya/8683624 to your computer and use it in GitHub Desktop.
This file contains 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
# -*- encoding: utf-8 -*- | |
require "rubygems" | |
require "selenium-webdriver" | |
require "test/unit" | |
module HtmlTestSuppeter | |
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 | |
end | |
class SaucelabsTestCase < Test::Unit::TestCase | |
include HtmlTestSuppeter | |
def initialize *args | |
@remote_driver_url = "http://YOUR REMOTE DRIVER URL@ondemand.saucelabs.com:80/wd/hub".freeze | |
super | |
end | |
def setup | |
create_browser unless @browser | |
end | |
def teardown | |
@browser.quit if (@browser) | |
end | |
end | |
class SaucelabsTestCasePC < SaucelabsTestCase | |
def create_browser | |
browser_env = ENV["BROWSER"] | |
cap = nil | |
case browser_env | |
when "win_ie6" | |
cap = Selenium::WebDriver::Remote::Capabilities.internet_explorer | |
cap.platform = 'Windows XP' | |
cap.version = '6' | |
cap[:name] = "WindowsXP IE6" | |
when "win_ie7", nil | |
cap = Selenium::WebDriver::Remote::Capabilities.internet_explorer | |
cap.platform = 'Windows XP' | |
cap.version = '7' | |
cap[:name] = "WindowsXP IE7" | |
when "win_ie_latest" | |
cap = Selenium::WebDriver::Remote::Capabilities.internet_explorer | |
cap.platform = 'Windows 8.1' | |
cap.version = '11' | |
cap[:name] = "Windows8.1 IE11" | |
when /\Awin_ff/ | |
cap = Selenium::WebDriver::Remote::Capabilities.firefox | |
cap.platform = 'Windows 8.1' | |
cap.version = '26' | |
cap[:name] = "Windows8.1 firefox26" | |
when /\Awin_chrome/ | |
cap = Selenium::WebDriver::Remote::Capabilities.chrome | |
cap.platform = 'Windows 8.1' | |
cap.version = '31' | |
cap[:name] = "Windows8.1 Chrome31" | |
when /\Amac_chrome/ | |
cap = Selenium::WebDriver::Remote::Capabilities.chrome | |
cap.platform = 'OS X 10.9' | |
cap.version = '31' | |
cap[:name] = "Mac OSX10.9 Chrome31" | |
when /\Amac_safari/ | |
cap = Selenium::WebDriver::Remote::Capabilities.safari | |
cap.platform = 'OS X 10.9' | |
cap.version = '7' | |
cap[:name] = "Mac OSX10.9 Safari7" | |
end | |
raise "invalid browser: <#{browser_env.inspect}>" unless (cap) | |
@browser_name = cap[:name] | |
@browser = Selenium::WebDriver.for( | |
:remote, | |
:url => @remote_driver_url, | |
:desired_capabilities => cap) | |
end | |
end |
This file contains 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
# -*- encoding: utf-8 -*- | |
require "saucelabsTestCase.rb" | |
class Search < SaucelabsTestCasePC | |
def test_search1 | |
# STDERR.puts "[test]%s with %s"%[__method__,@browser_name] | |
@browser.navigate.to "http://www.google.com" | |
element = @browser.find_element(:name, 'q') | |
element.send_keys "Hello WebDriver!" | |
element.submit | |
puts @browser.title | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment