Module: BrowserStackHelper
- Defined in:
- lib/test_utils/browser_tests/browser_stack_helper.rb
Instance Method Summary collapse
- #bs_account ⇒ Object
- #bs_browser(browser) ⇒ Object
- #bs_browser_version(browser_version) ⇒ Object
- #bs_caps ⇒ Object
- #bs_delete_env_bars ⇒ Object
- #bs_mobile?(platform) ⇒ Boolean
- #bs_mobile_browser(browser) ⇒ Object
- #bs_mobile_device(device) ⇒ Object
- #bs_mobile_platform(platform) ⇒ Object
- #bs_os(os) ⇒ Object
- #bs_os_version(os_version) ⇒ Object
- #bs_remote_url ⇒ Object
- #bs_set_env_vars_caps(browser) ⇒ Object
- #desktop_caps ⇒ Object
- #generic_caps ⇒ Object
- #mobile_caps ⇒ Object
- #run_test_in_browser_stack? ⇒ Boolean
Instance Method Details
#bs_account ⇒ Object
12 13 14 15 16 17 18 19 20 |
# File 'lib/test_utils/browser_tests/browser_stack_helper.rb', line 12 def bs_account user_name = ENV['BS_USER_NAME'] auth_key = ENV['BS_AUTH_KEY'] if user_name.to_s.strip.empty? || auth_key.to_s.strip.empty? fail "Browser Stack credentials not found in environment variables. \nBS_USER_NAME:#{user_name}\nBS_AUTH_KEY:#{auth_key}\n" else {:user_name => user_name, :auth_key => auth_key} end end |
#bs_browser(browser) ⇒ Object
126 127 128 129 130 131 132 133 134 135 |
# File 'lib/test_utils/browser_tests/browser_stack_helper.rb', line 126 def bs_browser(browser) case browser.downcase when 'ie' then 'IE' when 'edge' then 'Edge' when 'safari' then 'Safari' when 'firefox' then 'Firefox' when 'chrome' then 'Chrome' else fail "Invalid Browser: #{browser}" end end |
#bs_browser_version(browser_version) ⇒ Object
137 138 139 140 141 142 |
# File 'lib/test_utils/browser_tests/browser_stack_helper.rb', line 137 def bs_browser_version(browser_version) case browser_version.downcase when /\d/, /\d\.\d/ then browser_version else fail "Invalid Browser version: #{browser_version}" end end |
#bs_caps ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/test_utils/browser_tests/browser_stack_helper.rb', line 22 def bs_caps if !ENV['BS'].nil? && !ENV['BS'].strip.empty? if bs_mobile?(ENV['BS']) mobile_caps else desktop_caps end else if !ENV['BS_BROWSER'].nil? generic_caps end end end |
#bs_delete_env_bars ⇒ Object
144 145 146 147 148 149 150 |
# File 'lib/test_utils/browser_tests/browser_stack_helper.rb', line 144 def ENV['BS_BROWSER']=nil ENV['BS_BROWSER_VERSION']=nil ENV['BS_OS']=nil ENV['BS_OS_VERSION']=nil ENV['BS_DEVICE']=nil end |
#bs_mobile?(platform) ⇒ Boolean
36 37 38 39 40 |
# File 'lib/test_utils/browser_tests/browser_stack_helper.rb', line 36 def bs_mobile?(platform) unless platform.nil? true if (platform.downcase.include? 'android') || (platform.downcase.include? 'iphone') end end |
#bs_mobile_browser(browser) ⇒ Object
79 80 81 82 83 84 85 |
# File 'lib/test_utils/browser_tests/browser_stack_helper.rb', line 79 def bs_mobile_browser(browser) case browser.downcase when 'iphone' then 'iPhone' when 'android' then 'android' else fail "Invalid Mobile Browser: #{browser}" end end |
#bs_mobile_device(device) ⇒ Object
95 96 97 98 99 100 101 102 103 104 105 |
# File 'lib/test_utils/browser_tests/browser_stack_helper.rb', line 95 def bs_mobile_device(device) case device.downcase when '6splus' then 'iPhone 6S Plus' when '6s' then 'iPhone 6S' when '6plus' then 'iPhone 6 Plus' when '6' then 'iPhone 6' when 's5' then 'Samsung Galaxy S5' when 'nexus5' then 'Google Nexus 5' else fail "Invalid Mobile Device: #{device}" end end |
#bs_mobile_platform(platform) ⇒ Object
87 88 89 90 91 92 93 |
# File 'lib/test_utils/browser_tests/browser_stack_helper.rb', line 87 def bs_mobile_platform(platform) case platform.downcase when 'iphone' then 'MAC' when 'android' then 'android' else fail "Invalid Mobile Platform: #{platform}" end end |
#bs_os(os) ⇒ Object
107 108 109 110 111 112 113 |
# File 'lib/test_utils/browser_tests/browser_stack_helper.rb', line 107 def bs_os(os) case os.downcase when 'win', 'windows' then 'Windows' when 'osx', 'mac' then 'OS X' else fail "Invalid OS: #{os}" end end |
#bs_os_version(os_version) ⇒ Object
115 116 117 118 119 120 121 122 123 124 |
# File 'lib/test_utils/browser_tests/browser_stack_helper.rb', line 115 def bs_os_version(os_version) case os_version.downcase when 'elcapitan', 'capitan' then 'El Capitan' when 'yosemite' then 'Yosemite' when 'mavericks' then 'Mavericks' when 'mountainlion' then 'Mountain Lion' when /\d/, /\d\.\d/ then os_version else fail "Invalid OS version: #{os_version}" end end |
#bs_remote_url ⇒ Object
8 9 10 |
# File 'lib/test_utils/browser_tests/browser_stack_helper.rb', line 8 def bs_remote_url "http://#{bs_account[:user_name]}:#{bs_account[:auth_key]}@hub.browserstack.com/wd/hub" end |
#bs_set_env_vars_caps(browser) ⇒ Object
152 153 154 155 156 157 158 |
# File 'lib/test_utils/browser_tests/browser_stack_helper.rb', line 152 def bs_set_env_vars_caps(browser) ENV['BS_BROWSER'] = browser['browser'].tr(' ', '_') unless browser['browser'].nil? ENV['BS_BROWSER_VERSION'] = browser['browser_version'].tr(' ', '_') unless browser['browser_version'].nil? ENV['BS_OS'] = browser['os'].tr(' ', '_') unless browser['os'].nil? ENV['BS_OS_VERSION'] = browser['os_version'].tr(' ', '_') unless browser['os_version'].nil? ENV['BS_DEVICE'] = browser['device'].tr(' ', '_') unless browser['device'].nil? end |
#desktop_caps ⇒ Object
53 54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/test_utils/browser_tests/browser_stack_helper.rb', line 53 def desktop_caps bs_env = ENV['BS'].split('_') # Ex: win_7_ie_11 fail 'Invalid Platform' if bs_env.length < 3 caps = WebDriver::Remote::Capabilities.new caps[:os] = bs_os(bs_env[0]) caps[:os_version] = bs_os_version(bs_env[1]) caps[:browser] = bs_browser(bs_env[2]) caps[:browser_version] = bs_browser_version(bs_env[3]) unless bs_env[3].nil? caps[:javascriptEnabled] = true caps['browserstack.idleTimeout'] = 30 caps end |
#generic_caps ⇒ Object
42 43 44 45 46 47 48 49 50 51 |
# File 'lib/test_utils/browser_tests/browser_stack_helper.rb', line 42 def generic_caps caps = Selenium::WebDriver::Remote::Capabilities.new caps[:os] = ENV['BS_OS'].tr('_', ' ') unless ENV['BS_OS'].nil? caps[:os_version] = ENV['BS_OS_VERSION'].tr('_', ' ') unless ENV['BS_OS_VERSION'].nil? caps[:browser] = ENV['BS_BROWSER'].tr('_', ' ') unless ENV['BS_BROWSER'].nil? caps[:browser_version] = ENV['BS_BROWSER_VERSION'].tr('_', ' ') unless ENV['BS_BROWSER_VERSION'].nil? caps[:device] = ENV['BS_DEVICE'].tr('_', ' ') unless ENV['BS_DEVICE'].nil? caps['browserstack.idleTimeout'] = 30 caps end |
#mobile_caps ⇒ Object
67 68 69 70 71 72 73 74 75 76 77 |
# File 'lib/test_utils/browser_tests/browser_stack_helper.rb', line 67 def mobile_caps bs_env = ENV['BS'].split('_') # Ex: iphone_6s fail 'Invalid Platform' if bs_env.length < 2 caps = WebDriver::Remote::Capabilities.new caps[:browserName] = bs_mobile_browser(bs_env[0]) caps[:platform] = bs_mobile_platform(bs_env[0]) caps['device'] = bs_mobile_device(bs_env[1]) caps['browserstack.idleTimeout'] = 30 caps end |
#run_test_in_browser_stack? ⇒ Boolean
4 5 6 |
# File 'lib/test_utils/browser_tests/browser_stack_helper.rb', line 4 def run_test_in_browser_stack? !ENV['BS_BROWSER'].nil? || (!ENV['BS'].nil? && !ENV['BS'].strip.empty?) end |