lib/scoutui/commands/strategy.rb in scoutui-2.0.4.2.pre vs lib/scoutui/commands/strategy.rb in scoutui-2.0.5.0
- old
+ new
@@ -3,10 +3,19 @@
module Scoutui::Commands
class Strategy
+ USER_AGENTS = {
+ 'MAC_CHROME' => 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/54.0.2840.98 Safari/537.36',
+ 'WIN81_IE11' => 'Mozilla/5.0 (Windows NT 6.3; Trident/7.0; rv 11.0) like Gecko',
+ 'WIN7_IE10' => 'Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.1; WOW64; Trident/6.0)',
+ 'WIN10_EDGE13' => '#Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/46.0.2486.0 Safari/537.36 Edge/13.10586',
+ 'WIN10_CHROME_BETA' => 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/56.0.2924.21 Safari/537.36',
+ 'YOSE_CHROME_BETA' => 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/54.0.2840.98 Safari/537.36'
+ }
+
attr_accessor :drv
attr_accessor :profile
def getDriver()
@drv
@@ -21,10 +30,26 @@
end
rc
end
+ def isHeadlessBrowser?(browserType)
+ !browserType.match(/(phantom|phantomjs|ghost|ghostdriver)/i).nil?
+ end
+
+ def isHeadlessCap?(caps)
+ !caps.nil? && caps.has_key?(:browser) && isHeadlessBrowser?(caps[:browser])
+ end
+
+ def setViewport()
+ _viewport = Scoutui::Utils::TestUtils.instance.getViewPort()
+ if !_viewport.nil?
+ target_size = Selenium::WebDriver::Dimension.new(_viewport[:width], _viewport[:height])
+ getDriver().manage.window.size = target_size
+ end
+ end
+
def navigate(url)
Scoutui::Logger::LogMgr.instance.debug __FILE__ + (__LINE__).to_s + " [enter]:navigate(#{url})"
rc = false
begin
processCommand('navigate(' + url + ')', nil)
@@ -94,30 +119,19 @@
@profile=nil
browserType = Scoutui::Base::UserVars.instance.getBrowserType()
caps = Scoutui::Utils::TestUtils.instance.getCapabilities()
- if false
- if !browserType.to_s.match(/chrome/i).nil?
- @profile = Selenium::WebDriver::Chrome::Profile.new
- elsif !browserType.to_s.match(/fire/i).nil?
- @profile = Selenium::WebDriver::Firefox::Profile.new
- elsif !browserType.to_s.match(/ie/i).nil?
- @profile = Selenium::WebDriver::IE::Profile.new
- elsif !browserType.to_s.match(/safari/i).nil?
- @profile = Selenium::WebDriver::Safari::Profile.new
- else
- @profile = Selenium::WebDriver::Firefox::Profile.new
- browserType='firefox'
- end
+ ##
+ # If running on Sauce, we need the capabilities.
+ ##
+ if Scoutui::Utils::TestUtils.instance.sauceEnabled?
- Scoutui::Logger::LogMgr.instance.debug __FILE__ + (__LINE__).to_s + " profile => #{@profile}"
- end
+ caps = Scoutui::Utils::TestUtils.instance.getSauceCaps()
- if Scoutui::Utils::TestUtils.instance.sauceEnabled?
+ caps = Scoutui::Utils::TestUtils.instance.getCapabilities() if caps.nil?
- caps = Scoutui::Utils::TestUtils.instance.getCapabilities()
client=nil
proxy=nil
Scoutui::Logger::LogMgr.instance.debug __FILE__ + (__LINE__).to_s + " Capabilities => #{caps.to_s}"
@@ -221,11 +235,11 @@
sauce_endpoint = "http://#{ENV['SAUCE_USERNAME']}:#{ENV['SAUCE_ACCESS_KEY']}@ondemand.saucelabs.com:80/wd/hub"
begin
if client.nil?
- puts __FILE__ + (__LINE__).to_s + " caps => #{caps}"
+ Scoutui::Logger::LogMgr.instance.debug __FILE__ + (__LINE__).to_s + " caps => #{caps}"
@drv=Selenium::WebDriver.for :remote, :url => sauce_endpoint, :desired_capabilities => caps # setup(caps)
else
@drv=Selenium::WebDriver.for :remote, :url => sauce_endpoint, :http_client => client, :desired_capabilities => caps # setup(caps)
end
@@ -237,74 +251,54 @@
# The following print to STDOUT is useful when running on JENKINS with SauceLabs plugin
# Reference:
# https://wiki.saucelabs.com/display/DOCS/Setting+Up+Reporting+between+Sauce+Labs+and+Jenkins
puts "SauceOnDemandSessionID=#{@drv.session_id} job-name=#{caps[:name]}"
- elsif !caps.nil? && caps.has_key?(:browser) && caps[:browser].match(/(phantom|phantomjs|ghost|ghostdriver)/i)
- _YosemiteChromeBeta='Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/54.0.2840.98 Safari/537.36'
- _cap=Selenium::WebDriver::Remote::Capabilities.phantomjs('phantomjs.page.settings.userAgent' => _YosemiteChromeBeta)
+ elsif isHeadlessCap?(caps) || isHeadlessBrowser?(browserType)
- if caps.has_key?(:browser) && caps[:browser].match(/(phantom|phantomjs|ghost|ghostdriver)/i)
- selenium_server=Scoutui::Utils::TestUtils.instance.getSeleniumServer()
- selenium_server='http://localhost:8001' if selenium_server.nil?
+ Scoutui::Logger::LogMgr.instance.debug __FILE__ + (__LINE__).to_s + " Headless browser : <caps, browser>::<#{caps}, #{browserType}>"
- if caps.has_key?(:useragent)
- _cap=Selenium::WebDriver::Remote::Capabilities.phantomjs('phantomjs.page.settings.userAgent' => caps[:useragent])
- end
+ _cap=Selenium::WebDriver::Remote::Capabilities.phantomjs('phantomjs.page.settings.userAgent' => USER_AGENTS['YOSE_CHROME_BETA'])
- @drv=Selenium::WebDriver.for :remote, :url => selenium_server, :desired_capabilities => _cap
- _viewport = Scoutui::Utils::TestUtils.instance.getViewPort()
- if !_viewport.nil?
- target_size = Selenium::WebDriver::Dimension.new(_viewport[:width], _viewport[:height])
- @drv.manage.window.size = target_size
- end
+ selenium_server=Scoutui::Utils::TestUtils.instance.getSeleniumServer()
+ selenium_server='http://localhost:8001' if selenium_server.nil?
+ if isHeadlessCap?(caps) && caps.has_key?(:useragent)
+ _cap=Selenium::WebDriver::Remote::Capabilities.phantomjs('phantomjs.page.settings.userAgent' => caps[:useragent])
end
+ Scoutui::Logger::LogMgr.instance.debug __FILE__ + (__LINE__).to_s + " Headless capabilities : #{_cap}"
- elsif browserType.match(/(phantom|phantomjs|ghost|ghostdriver)/i)
+ _connected=false
+ _tm={:start => Time.now, :end => nil }
+ begin
+ @drv=Selenium::WebDriver.for :remote, :url => selenium_server, :desired_capabilities => _cap
+ _tm[:end]=Time.now
+ _connected=true
+ setViewport()
- puts __FILE__ + (__LINE__).to_s + " => Headless testing"
+ rescue Errno::ECONNREFUSED => ex
+ Scoutui::Logger::LogMgr.instance.fatal __FILE__ + (__LINE__).to_s + " Unable to connect to GhostDriver"
- selenium_server=Scoutui::Utils::TestUtils.instance.getSeleniumServer()
- selenium_server='http://localhost:8001' if selenium_server.nil?
+ Scoutui::Utils::TestUtils.instance.setState(:abort, __FILE__ + (__LINE__).to_s + " Unable to connect to GhostDriver : #{ex.class.to_s}: #{ex}")
- ##
- # caps
- ##
- _useragentChromeOnMac='Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/54.0.2840.98 Safari/537.36'
- _useragentWin81IE11='Mozilla/5.0 (Windows NT 6.3; Trident/7.0; rv 11.0) like Gecko'
+ rescue => ex
+ Scoutui::Utils::TestUtils.instance.setState(:abort, __FILE__ + (__LINE__).to_s + " : #{ex.class.to_s}: #{ex}")
+ Scoutui::Logger::LogMgr.instance.warn __FILE__ + (__LINE__).to_s + " #{ex.class.to_s} Error during processing: #{ex}"
+ Scoutui::Logger::LogMgr.instance.warn ex.backtrace
+ end
- _Win7IE10 = 'Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.1; WOW64; Trident/6.0)'
+ _tm[:end]=Time.now if _tm[:end].nil?
- _Win10Edge13='#Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/46.0.2486.0 Safari/537.36 Edge/13.10586'
+ Testmgr::TestReport.instance.getReq('Execution').tc('Status').add(_connected, "Connect to GhostDriver on #{selenium_server}", _tm[:end] - _tm[:start])
- _Win10ChromeBeta='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/56.0.2924.21 Safari/537.36'
- _YosemiteChromeBeta='Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/54.0.2840.98 Safari/537.36'
- _useragent = _YosemiteChromeBeta
-
- caps=Selenium::WebDriver::Remote::Capabilities.phantomjs('phantomjs.page.settings.userAgent' => _useragent)
- # @drv=Selenium::WebDriver.for :phantomjs, :url => selenium_server, :desired_capabilities => caps
- @drv=Selenium::WebDriver.for :remote, :url => selenium_server, :desired_capabilities => caps
-
- _viewport = Scoutui::Utils::TestUtils.instance.getViewPort()
- if !_viewport.nil?
- target_size = Selenium::WebDriver::Dimension.new(_viewport[:width], _viewport[:height])
- @drv.manage.window.size = target_size
- end
-
else
Scoutui::Logger::LogMgr.instance.debug __FILE__ + (__LINE__).to_s + " Create WebDriver: #{browserType.to_s}"
@drv=Selenium::WebDriver.for browserType.to_sym, :profile => @profile
-
- _viewport = Scoutui::Utils::TestUtils.instance.getViewPort()
- if !_viewport.nil?
- target_size = Selenium::WebDriver::Dimension.new(_viewport[:width], _viewport[:height])
- @drv.manage.window.size = target_size
- end
+ setViewport()
end
end