Module: TestNow

Defined in:
lib/testnow.rb,
lib/testnow/opera.rb,
lib/testnow/chrome.rb,
lib/testnow/firefox.rb

Instance Method Summary collapse

Instance Method Details

#get_binary_pathObject



19
20
21
22
23
24
25
26
27
28
# File 'lib/testnow/opera.rb', line 19

def get_binary_path
	case RUBY_PLATFORM
		when /mswin|msys|mingw|cygwin|bccwin|wince|emc/
			return "NEED TO FIND WINDOWS BINARY LOCATION"
		when /darwin|mac os/
			return "/Applications/Opera.app/Contents/MacOS/Opera"
		else
			return "/usr/bin/opera"
	end
end

#get_tmp_dirObject



30
31
32
33
34
35
36
37
38
39
# File 'lib/testnow/firefox.rb', line 30

def get_tmp_dir
  case RUBY_PLATFORM
    when /mswin|msys|mingw|cygwin|bccwin|wince|emc/
      return `echo %TEMP%`
    when /darwin|mac os/
      return "/tmp/"
    else
      return "/tmp/"
  end
end

#initObject



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/testnow.rb', line 8

def init
	ENV['BROWSER'] = "firefox" if ENV['BROWSER'].nil?
	case ENV['BROWSER'].downcase
   		when "chrome"
     			TestNow.launch_driver_chrome
   		when "android"
     			launch_driver_android
   		when "opera"
     			TestNow.launch_driver_opera
   		when "androidchrome"
     			launch_driver_android_chrome  
   		when "ie"
     			launch_driver_ie
   		else
     			TestNow.launch_driver_firefox
 		end
end

#launch_driver_chromeObject

Chrome Browser



5
6
7
8
9
10
11
# File 'lib/testnow/chrome.rb', line 5

def launch_driver_chrome
 		@driver = Selenium::WebDriver.for :chrome
 		@driver.manage.timeouts.implicit_wait = 30
 		@driver.manage.timeouts.page_load = 120
 		@driver.manage.window.maximize
 		return @driver
end

#launch_driver_firefoxObject

Firefox browser



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/testnow/firefox.rb', line 4

def launch_driver_firefox
  ENV['IS_UPA'] = "false" if ENV['IS_UPA'].nil?
  if ENV['IS_UPA']=="true"
    ENV['HAR_DIR'] = get_tmp_dir if ENV['HAR_DIR'].nil?
    profile = Selenium::WebDriver::Firefox::Profile.new
    profile.add_extension("./data/firebug-2.0.13.xpi")
    profile.add_extension("./data/netExport-0.8.xpi")
    profile['extensions.firebug.currentVersion'] = "2.0.13"
    profile['extensions.firebug.allPagesActivation'] = "on"
    profile['extensions.firebug.defaultPanelName'] = "net"
    profile['extensions.firebug.net.enableSites'] = "true"
    profile['extensions.firebug.netexport.alwaysEnableAutoExport'] = "true"
    profile['extensions.firebug.netexport.showPreview'] = "false"
    profile['extensions.firebug.netexport.defaultLogDir'] = ENV['HAR_DIR'].to_s
    profile['extensions.firebug.netexport.defaultFileName'] = "upaReport.har"
    profile['extensions.firebug.netexport.jsonpCallback'] = "jsonCallback"
    @driver = Selenium::WebDriver.for :firefox, :profile => profile
  else
    @driver = Selenium::WebDriver.for :firefox
  end
  @driver.manage.timeouts.implicit_wait = 30
  @driver.manage.timeouts.page_load = 120
  @driver.manage.window.maximize
  @driver
end

#launch_driver_operaObject

Opera browser



5
6
7
8
9
10
11
12
13
14
15
16
# File 'lib/testnow/opera.rb', line 5

def launch_driver_opera
  client = Selenium::WebDriver::Remote::Http::Default.new
  client.timeout = 180 # seconds
  service = Selenium::WebDriver::Chrome::Service.new("/usr/local/bin/operadriver", 48923)
  service.start
  cap = Selenium::WebDriver::Remote::Capabilities.chrome('operaOptions' => {'binary' => "#{get_binary_path}", 'args' => ["--ignore-certificate-errors"]})
  @driver = Selenium::WebDriver.for(:remote, :url => service.uri, :desired_capabilities => cap, :http_client => client)
  @driver.manage.timeouts.implicit_wait = 30
  @driver.manage.window.maximize
  @driver.manage.timeouts.page_load = 120
  return @driver
end