Class: BrowserStackCucumber::Config
- Inherits:
-
Object
- Object
- BrowserStackCucumber::Config
- Defined in:
- lib/browserstack/browserstack.rb
Instance Attribute Summary collapse
-
#browser ⇒ Object
readonly
Returns the value of attribute browser.
Class Method Summary collapse
- ._scenario_and_feature_name(scenario) ⇒ Object
- .browser ⇒ Object
- .capabilities ⇒ Object
- .close_browser ⇒ Object
- .close_browser_force ⇒ Object
- .init_browser(scenario) ⇒ Object
- .name_from_scenario(scenario) ⇒ Object
- .selenium_apikey ⇒ Object
- .selenium_browser ⇒ Object
- .selenium_browser_version ⇒ Object
- .selenium_os ⇒ Object
- .selenium_os_version ⇒ Object
- .selenium_username ⇒ Object
- .url ⇒ Object
- .wait_till_session_is_available ⇒ Object
Instance Method Summary collapse
Instance Attribute Details
#browser ⇒ Object (readonly)
Returns the value of attribute browser.
9 10 11 |
# File 'lib/browserstack/browserstack.rb', line 9 def browser @browser end |
Class Method Details
._scenario_and_feature_name(scenario) ⇒ Object
30 31 32 33 34 |
# File 'lib/browserstack/browserstack.rb', line 30 def self._scenario_and_feature_name(scenario) scenario_name = scenario.name.split("\n").first feature_name = scenario.feature.short_name return scenario_name, feature_name end |
.browser ⇒ Object
154 155 156 |
# File 'lib/browserstack/browserstack.rb', line 154 def self.browser @browser end |
.capabilities ⇒ Object
70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 |
# File 'lib/browserstack/browserstack.rb', line 70 def self.capabilities capabilities = ::Selenium::WebDriver::Remote::Capabilities.new capabilities[:name] = 'Testing Selenium 2 with Ruby on BrowserStack' capabilities['os'] = selenium_os capabilities['os_version'] = selenium_os_version capabilities['browser'] = selenium_browser capabilities['browser_version'] = selenium_browser_version capabilities['browserstack.user'] = selenium_username capabilities['browserstack.key'] = selenium_apikey capabilities['browserstack.debug'] = 'true' capabilities['acceptSslCerts'] = 'true' capabilities['Idle timeout'] = 30 capabilities['build'] = ENV['BUILD_NUMBER'] capabilities['project'] = ENV['JOB_NAME'] capabilities end |
.close_browser ⇒ Object
158 159 160 161 |
# File 'lib/browserstack/browserstack.rb', line 158 def self.close_browser @browser.quit if !@browser.nil? @browser = nil end |
.close_browser_force ⇒ Object
163 164 165 166 167 168 169 170 |
# File 'lib/browserstack/browserstack.rb', line 163 def self.close_browser_force unless @browser.nil? puts @browser.title STDERR.puts 'Something went wrong and selenium session was not closed. Closing it now.' ::BrowserStackCucumber::Config.close_browser end end |
.init_browser(scenario) ⇒ Object
91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 |
# File 'lib/browserstack/browserstack.rb', line 91 def self.init_browser(scenario) my_capabilities = capabilities() my_url = url() my_capabilities[:name] = name_from_scenario(scenario) @browser = nil count=0 try_count=0 #check for session limit before starting the test wait_till_session_is_available() WaitUntil::wait_until(500) do count+=1 puts "try #{count} to init browser" if count>1 begin try_count+=1 @browser = Selenium::WebDriver.for(:remote, :url => my_url, :desired_capabilities => my_capabilities) @browser.get @test_url raise "Network connection issue. Failed to open #{@test_url} and find '#{@test_substring}' substring" if !@browser.page_source.downcase.include? @test_substring @browser rescue =>e if e..include? 'sessions are currently being used. Please upgrade to add more parallel sessions' puts "Run out of sessions: '#{e.}'" else puts "Exception while initializing Selenium session: #{e.class }#{e}" puts e.backtrace @browser.quit if !@browser.nil? raise if try_count>30 end end end if @browser.nil? puts 'failed to init browser' raise 'failed to initiate remote browser session after 300 seconds' end unless @browser.is_a? ::Selenium::WebDriver::Driver puts 'invalid browser' raise 'invalid browser' end @browser.instance_variable_get(:'@bridge').maximizeWindow #puts my_capabilities['name'] #puts @browser.session_id ENV['browser_session_id'] = @browser.session_id @browser end |
.name_from_scenario(scenario) ⇒ Object
19 20 21 22 23 24 25 26 27 28 |
# File 'lib/browserstack/browserstack.rb', line 19 def self.name_from_scenario(scenario) # Special behavior to handle Scenario Outlines if scenario.instance_of? ::Cucumber::Ast::OutlineTable::ExampleRow table = scenario.instance_variable_get(:@table) outline = table.instance_variable_get(:@scenario_outline) return "#{outline.feature.file} - #{outline.title} - #{table.headers} -> #{scenario.name}" end scenario, feature = _scenario_and_feature_name(scenario) return "#{feature} - #{scenario}" end |
.selenium_apikey ⇒ Object
40 41 42 |
# File 'lib/browserstack/browserstack.rb', line 40 def self.selenium_apikey ENV['BROWSER_STACK_API_KEY'] end |
.selenium_browser ⇒ Object
59 60 61 62 |
# File 'lib/browserstack/browserstack.rb', line 59 def self.selenium_browser #firefox ENV['SELENIUM_BROWSER'] end |
.selenium_browser_version ⇒ Object
64 65 66 67 |
# File 'lib/browserstack/browserstack.rb', line 64 def self.selenium_browser_version #21 ENV['SELENIUM_VERSION'] end |
.selenium_os ⇒ Object
44 45 46 47 48 |
# File 'lib/browserstack/browserstack.rb', line 44 def self.selenium_os #TODO: Windows 8 doesn't match BS #'Windows XP' => Windows ENV['SELENIUM_PLATFORM'].split(' ')[0] end |
.selenium_os_version ⇒ Object
50 51 52 53 54 55 56 57 |
# File 'lib/browserstack/browserstack.rb', line 50 def self.selenium_os_version #'Windows XP' => XP r = ENV['SELENIUM_PLATFORM'].split(' ')[1] return 'XP' if (r=='2003') return '7' if (r=='2008') return '8' if (r=='2012') r end |
.selenium_username ⇒ Object
36 37 38 |
# File 'lib/browserstack/browserstack.rb', line 36 def self.selenium_username ENV['BROWSER_STACK_USER_NAME'] end |
.url ⇒ Object
87 88 89 |
# File 'lib/browserstack/browserstack.rb', line 87 def self.url 'http://hub.browserstack.com/wd/hub' end |
.wait_till_session_is_available ⇒ Object
141 142 143 144 145 146 147 148 149 150 151 152 |
# File 'lib/browserstack/browserstack.rb', line 141 def self.wait_till_session_is_available ::BrowserStackCucumber::WaitUntil::wait_until(500) do url = "https://#{selenium_username}:#{selenium_apikey}@api.browserstack.com/3/status" r = RestClient.get(url) parsed_r = JSON.parse(r.body) puts "no free BrowserStack session available now#{parsed_r}" if (parsed_r['sessions_limit']==parsed_r['running_sessions']) parsed_r['sessions_limit']-parsed_r['running_sessions']>0 end rescue RestClient::Unauthorized=>e puts "Error: Failed to access BrowserStack account, please check username and api key: #{e}" raise end |
Instance Method Details
#test_url=(url) ⇒ Object
15 16 17 |
# File 'lib/browserstack/browserstack.rb', line 15 def test_url=(url) @test_url = url end |