Scripting - Open Container Based Web Session (Selenium)

The following script can be used to open a web browser session:

Selenium:
browser = Selenium::WebDriver.for :chrome

Watir (with some options):
opts = Selenium::WebDriver::Chrome::Options.new
opts.add_option('useAutomationExtension', false)
opts.add_argument('--disable-infobars')
opts.add_argument('--disable-notifications')
browser = Watir::Browser.new :chrome, options: opts

In case of a container based web application session, the following can be used (where $path_container is the path to the container executable):

Selenium:
opts = Selenium::WebDriver::Chrome::Options.new
opts.add_option('binary', $path_container)
browser = Selenium::WebDriver.for :chrome, options: opts

Watir:
opts = Selenium::WebDriver::Chrome::Options.new
opts.add_option('useAutomationExtension', false)
opts.add_argument('--disable-infobars')
opts.add_argument('--disable-notifications')
opts.add_option('binary', $path_container)
browser = Watir::Browser.new :chrome, options: opts

Combined into a function (where $use_container is the Boolean switch):

Selenium:
def open_browser()
  if $use_container
    opts = Selenium::WebDriver::Chrome::Options.new
    opts.add_option('binary', $path_container)
    browser = Selenium::WebDriver.for :chrome, options: opts
  else
    browser = Selenium::WebDriver.for :chrome
  end
  return browser
end

Watir:
def open_browser()
  opts = Selenium::WebDriver::Chrome::Options.new
  opts.add_option('useAutomationExtension', false)
  opts.add_argument('--disable-infobars')
  opts.add_argument('--disable-notifications')
  if $use_container
    opts.add_option('binary', $path_container)
  end
  browser = Watir::Browser.new :chrome, options: opts
  return browser
end





No comments:

Followers

About Xman

Basking Ridge, New Jersey, United States