How to use launch method of Selenium.WebDriver Package

Best Selenium code snippet using Selenium.WebDriver.launch

web_driver_utils.rb

Source:web_driver_utils.rb Github

copy

Full Screen

1class WebDriverUtils2 include ClassLogger3 def self.launch_browser4 # Sometimes browser does not launch successfully, so try twice5 tries ||= 26 logger.info('Launching browser')7 case Settings.ui_selenium.web_driver8 when 'firefox'9 driver = Selenium::WebDriver.for :firefox10 driver.manage.window.maximize11 driver12 when 'chrome'13 Selenium::WebDriver.for :chrome14 when 'safari'15 Selenium::WebDriver.for :safari16 else17 logger.error 'Unsupported webdriver'18 end19 rescue => e20 logger.error('Browser failed to launch')21 logger.error e.message + "\n" + e.backtrace.join("\n")22 retry unless (tries -= 1).zero?23 end24 def self.quit_browser(driver)25 logger.info 'Quitting the browser'26 # If the browser did not start successfully, the quit method will fail.27 driver.quit rescue NoMethodError28 # Pause after quitting the browser to make sure it shuts down completely before the next test relaunches it29 sleep 230 end31 def self.base_url32 Settings.ui_selenium.base_url33 end34 def self.cal_net_url35 Settings.ui_selenium.cal_net_url36 end37 def self.canvas_base_url38 Settings.ui_selenium.canvas_base_url39 end40 def self.canvas_qa_sub_account41 Settings.ui_selenium.canvas_qa_sub_account42 end...

Full Screen

Full Screen

driver_config.rb

Source:driver_config.rb Github

copy

Full Screen

1module URLTest2 # Firefox browser3 def launch_driver_firefox4 #puts "Launching driver for firefox.........................."5 ENV['IS_UPA'] = "false" if ENV['IS_UPA'].nil? 6 if ENV['IS_UPA']=="true" 7 profile = Selenium::WebDriver::Firefox::Profile.new8 profile.add_extension("./harexport/firebug-2.0.13.xpi")9 profile.add_extension("./harexport/netExport-0.8.xpi")10 profile['extensions.firebug.allPagesActivation'] = "on"11 profile['extensions.firebug.defaultPanelName'] = "net"12 profile['extensions.firebug.net.enableSites'] = "true"13 profile['extensions.firebug.showFirstRunPage'] = "false"14 profile['extensions.firebug.netexport.alwaysEnableAutoExport'] = "true"15 profile['extensions.firebug.netexport.showPreview'] = "false"16 profile['extensions.firebug.netexport.defaultLogDir'] = File.absolute_path("./report/upa")17 profile['extensions.firebug.netexport.defaultFileName'] = "upaReport.har"18 profile['extensions.firebug.netexport.jsonpCallback'] = "jsonCallback";19 caps = Selenium::WebDriver::Remote::Capabilities.firefox20 caps['acceptInsecureCerts'] = true21 @driver = Selenium::WebDriver.for(:firefox, profile: profile, marionette: false)22 else23 caps = Selenium::WebDriver::Remote::Capabilities.firefox24 caps['acceptInsecureCerts'] = true25 @driver = Selenium::WebDriver.for(:firefox, desired_capabilities: caps, port: 5555)26 end27 @driver.manage.timeouts.implicit_wait = 3028 #@driver.manage.timeouts.page_load = 12029 @driver.manage.window.maximize30 end31 32 def launch_driver_safari33 #puts "Launching driver for firefox.........................."34 @driver = Selenium::WebDriver.for :safari35 @driver.manage.timeouts.implicit_wait = 6036 @driver.manage.window.maximize37 end38 # Chrome browser39 def launch_driver_chrome40 #puts "Launching driver for chrome.........................."41 @driver = Selenium::WebDriver.for :chrome42 @driver.manage.timeouts.implicit_wait = 6043 target_size = Selenium::WebDriver::Dimension.new(1024, 768)44 @driver.manage.window.size = target_size45 end46 def launch_driver_device47 #puts "Launching driver for chrome.........................."48 # @driver = Selenium::WebDriver.for :chrome49 # @driver.manage.timeouts.implicit_wait = 6050 # @driver.manage.window.maximize51 deviceName = ENV['VERSION']52 deviceName = deviceName.gsub("_", " ")53 mobile_emulation = { "deviceName" => deviceName }54 caps = Selenium::WebDriver::Remote::Capabilities.chrome(55 "chromeOptions" => { "mobileEmulation" => mobile_emulation })56 @driver = Selenium::WebDriver.for :chrome, desired_capabilities: caps57 end58 def launch_driver_opera59 service = Selenium::WebDriver::Chrome::Service.new("/usr/bin/operadriver",48923)60 service.start61 sleep(10)62 begin63 @driver = Selenium::WebDriver.for :remote,:url => service.uri, :desired_capabilities => Selenium::WebDriver::Remote::Capabilities.opera('opera.binary' => "/usr/bin/opera",'operaOptions'=> {'binary' => '/usr/bin/opera'} )64 @driver.manage.timeouts.implicit_wait = 6065 @driver.manage.window.maximize66 rescue67 @driver = Selenium::WebDriver.for :remote,:url => service.uri, :desired_capabilities => Selenium::WebDriver::Remote::Capabilities.opera('opera.binary' => "/usr/bin/opera",'operaOptions'=> {'binary' => '/usr/bin/opera'} )68 @driver.manage.timeouts.implicit_wait = 6069 @driver.manage.window.maximize70 end71 72 end73 def launch_driver_ie74 client = Selenium::WebDriver::Remote::Http::Default.new75 client.timeout = 12076 caps = Selenium::WebDriver::Remote::Capabilities.ie(:javascript_enabled => true, :native_events => false, :ignore_protected_mode_settings => true)77 @driver = Selenium::WebDriver.for(:remote, :http_client => client, :url => "http://localhost:5555", :desired_capabilities => caps)78 @driver.manage.timeouts.implicit_wait = 6079 #@driver.manage.window.maximize80 target_size = Selenium::WebDriver::Dimension.new(1366, 768)81 @driver.manage.window.size = target_size82 end83 def launch_driver_android84 client = Selenium::WebDriver::Remote::Http::Default.new85 client.timeout = 999986 @driver = Selenium::WebDriver.for(:remote, :http_client => client, :desired_capabilities => :android)87 end88 def launch_driver_android_chrome89 client = Selenium::WebDriver::Remote::Http::Default.new90 client.timeout = 12091 caps = {'chromeOptions'=> {'androidPackage' => 'com.android.chrome'}}92 @driver = Selenium::WebDriver.for(:remote, :http_client => client, :url => "http://localhost:9515", :desired_capabilities => caps)93 @driver.manage.timeouts.implicit_wait = 6094 end95 def driver96 @driver97 end98 def quit_driver99 driver.quit100 end101end...

Full Screen

Full Screen

browser.rb

Source:browser.rb Github

copy

Full Screen

...9 @name = name10 @device = device11 @listener = NavigationListener.new12 end13 def launch_remote_browser()14 $logger.info "Starting remote #{@browser} browser at #{@host}"15 caps = get_caps_for_browser16 Selenium::WebDriver.for :remote, :url => remote_endpoint, :desired_capabilities => caps, :listener=>@listener17 end18 def launch_local_browser()19 $logger.info "Starting local #{@browser} browser"20 Selenium::WebDriver.for(@browser.to_sym,:listener=>@listener)21 end22 def launch_sauce_browser()23 $logger.info "Starting SauceLabs #{@browser} browser"24 caps = get_caps_for_browser25 Selenium::WebDriver.for :remote, :url => sauce_endpoint, :desired_capabilities => caps, :listener=>@listener26 end27 def launch_browserstack_browser()28 $logger.info "Starting BrowserStack Browser: #{@browser} #{@browser_version} on os: #{@os} version: #{@os_version}"29 start_browserstack_local30 caps = Selenium::WebDriver::Remote::Capabilities.new31 caps['browser'] = @browser32 caps['browser_version'] = @browser_version33 caps['os'] = @os34 caps['os_version'] = @os_version35 caps['name'] = @name36 caps['resolution'] = '1600x1200'37 caps['browserstack.local'] = true38 Selenium::WebDriver.for :remote, :url => browserstack_endpoint, :desired_capabilities => caps, :listener=>@listener39 end40 def launch_browserstack_device41 $logger.info "Starting BrowserStack Device: #{@device}"42 caps = Selenium::WebDriver::Remote::Capabilities.new43 caps[:browserName] = 'iPhone'44 caps[:platform] = 'MAC'45 caps['device'] = 'iPhone 5'46 caps['os_version'] = '8.3'47 Selenium::WebDriver.for :remote, :url => browserstack_endpoint, :desired_capabilities => caps, :listener=>@listener48 end49 def launch_browser()50 if @host == "sauce"51 @driver = launch_sauce_browser52 elsif @host == "browserstack"53 if @device == ''54 @driver = launch_browserstack_browser55 else56 @driver = launch_browserstack_device57 end58 elsif @host != "localhost"59 @driver = launch_remote_browser60 else61 @driver = launch_local_browser62 end63 resize_browser64 @driver.manage.timeouts.implicit_wait = 165 @driver.manage.timeouts.page_load = $page_timeout66 @driver67 end68 def resize_browser69 $logger.info "Resizing browser to #{$size} size"70 case $size71 when 'mobile'72 @driver.resize_viewport(327, 600)73 when 'phablet'74 @driver.resize_viewport(600, 900)75 when 'tablet'...

Full Screen

Full Screen

page_object_spec.rb

Source:page_object_spec.rb Github

copy

Full Screen

1require 'spec_helper'2describe SeleniumFury::SeleniumWebDriver::CreateSeleniumWebDriver do3 it "should go to a page using launch_web_driver" do4 launch_web_driver TEST_PAGE_URL5 driver.current_url.should include "/spec/test_page/test_page.html"6 driver.title.should == "SeleniumFury Test Page"7 end8end9describe PageObject do10 after(:each) do11 Object.instance_eval { remove_const :TestPage } if Object.const_defined? :TestPage12 end13 specify "has Selenium::WebDriver::Elements defined with the element method" do14 launch_web_driver TEST_PAGE_URL15 test_page = TestPage.new(driver)16 test_page.should_not be_nil17 test_page.textarea.should be_a(Selenium::WebDriver::Element)18 end19 specify "allows a page object class can be linked to another page object class using the page method for sub pages" do20 class ComponentPage < PageObject21 end22 TestPage.page(:component_page, ComponentPage)23 TestPage.new().component_page.should be_a(ComponentPage)24 end25 it "should have an error if a non page object class is passed to the page method" do26 TestPage.page(:not_a_page, String)27 expect { TestPage.new().not_a_page }.to(raise_exception(RuntimeError, "String does not inherit from PageObject"))28 end29 it "should call methods on Selenium::WebDriver::Elements defined in the TestPage class" do30 launch_web_driver TEST_PAGE_URL31 test_page = TestPage.new(driver)32 test_page.input_message.send_keys "this is awesome"33 test_page.input_msg_button.click34 driver.find_element(:id => "message").text.should == "this is awesome"35 end36 specify "PageObject provides a method to return all Selenium::WebDriver::Element defined in the class" do37 launch_web_driver TEST_PAGE_URL38 test_page = TestPage.new(driver)39 test_page.class.elements.should_not be_nil40 test_page.class.elements.should have(40).elements41 test_page.method(test_page.class.elements[0]).call.class.should == Selenium::WebDriver::Element42 end43 it "should raise an exception when the element can't be found'" do44 launch_web_driver TEST_PAGE_URL45 test_page = TestPage.new(driver)46 TestPage.element :not_a_element, {:id => "not a element"}47 expect { test_page.not_a_element }.to raise_exception RuntimeError, "Could not find element not_a_element"48 end49 describe "#element_list" do50 context 'when there are elements found' do51 it "should return an array of Selenium::WebDriver::Elements" do52 launch_web_driver TEST_PAGE_URL53 test_page = TestPage.new(driver)54 test_page.listings.should be_an Array55 end56 end57 context 'when there are not elements found' do58 it "should i dunno" do59 launch_web_driver TEST_PAGE_URL60 test_page = TestPage.new(driver)61 TestPage.element_list :cats, { id: 'meow' }62 expect { test_page.cats }.to raise_error RuntimeError63 end64 end65 end66end...

Full Screen

Full Screen

ie.rb

Source:ie.rb Github

copy

Full Screen

...21 res = ENV['RESOLUTION'].split('x')22 driver.manage.window.size = Selenium::WebDriver::Dimension.new(res.first.to_i, res.last.to_i)23 end24 end25 def launch_driver_ie26 self.ie_config27 driver = Selenium::WebDriver.for(:ie,28 :desired_capabilities => @caps,29 :http_client => @client)30 self.set_ie_config(driver)31 return driver32 end33 def launch_watir_ie34 self.ie_config35 browser = Watir::Browser.new(:ie,36 :desired_capabilities => @caps,37 :http_client => @client)38 self.set_ie_config(browser.driver)39 return browser40 end41end...

Full Screen

Full Screen

opera.rb

Source:opera.rb Github

copy

Full Screen

...13 driver.manage.window.maximize14 driver.manage.timeouts.page_load = 12015 end16 # Opera browser17 def launch_driver_opera18 self.pre_config19 driver = Selenium::WebDriver.for(:remote, :url => @service.uri, :desired_capabilities => @cap, :http_client => @client)20 self.post_config(driver)21 return driver22 end23 # Opera browser24 def launch_watir_opera25 self.pre_config26 browser = Watir::Browser.new(:remote, :url => @service.uri, :desired_capabilities => @cap, :http_client => @client)27 self.post_config(browser.driver)28 return browser29 end30 @private31 def get_binary_path32 case RUBY_PLATFORM33 when /mswin|msys|mingw|cygwin|bccwin|wince|emc/34 return "NEED TO FIND WINDOWS BINARY LOCATION"35 when /darwin|mac os/36 return "/Applications/Opera.app/Contents/MacOS/Opera"37 else38 return "/usr/bin/opera"...

Full Screen

Full Screen

chrome.rb

Source:chrome.rb Github

copy

Full Screen

...5 driver.manage.timeouts.page_load = 1206 driver.manage.window.maximize7 end8 # Chrome Browser9 def launch_driver_chrome10 driver = Selenium::WebDriver.for :chrome11 self.post_config(driver)12 return driver13 end14 def launch_watir_chrome15 browser = Watir::Browser.new :chrome16 self.post_config(browser.driver)17 return browser18 end19 @private20 def pre_mobile_chrome_config21 device_name = ENV['DEVICE'].gsub("_"," ")22 mobile_emulation = { "deviceName" => device_name }23 caps = Selenium::WebDriver::Remote::Capabilities.chrome(24 "chromeOptions" => { "mobileEmulation" => mobile_emulation })25 return caps26 end27 def launch_driver_chrome_mobile28 caps = self.pre_mobile_chrome_config29 driver = Selenium::WebDriver.for(:chrome,30 :desired_capabilities => caps)31 self.post_config(driver)32 return driver33 end34 def launch_watir_chrome_mobile35 caps = self.pre_mobile_chrome_config36 browser = Watir::Browser.new(:chrome,37 :desired_capabilities => caps)38 self.post_config(browser.driver)39 return browser40 end41end

Full Screen

Full Screen

android_chrome.rb

Source:android_chrome.rb Github

copy

Full Screen

...6 @service = Selenium::WebDriver::Chrome::Service.new("/usr/local/bin/chromedriver", 9515, {})7 @service.start8 @caps = Selenium::WebDriver::Remote::Capabilities.chrome('chromeOptions'=> {'androidPackage' => 'com.android.chrome'})9 end10 def launch_driver_android_chrome11 self.android_chrome_config12 driver = Selenium::WebDriver.for(:remote, :http_client => @client, :url => @service.uri, :desired_capabilities => @caps)13 driver.manage.timeouts.implicit_wait = 6014 return driver15 end16 def launch_watir_android_chrome17 self.android_chrome_config18 browser = Watir::Browser.new(:remote, :url => @service.uri, :desired_capabilities => @caps, :http_client => @client)19 browser.driver.manage.timeouts.implicit_wait = 6020 return browser21 end22end...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run Selenium automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Most used method in

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful