Sha256: 6dbef2f7715130164541fb22d451678dcc27c964b8fa106fda867ba200abbdd3

Contents?: true

Size: 1.75 KB

Versions: 1

Compression:

Stored size: 1.75 KB

Contents

# frozen_string_literal: true

# One file to require gem and set things up, arriving at page to check
require 'generic_test'

# @return [String] Generic Test URL to login before arriving at PAGE_URL to test.
#   Needs GT_USERNAME and GT_PASSWORD to be used
GT_LOGIN_URL = 'GT_LOGIN_URL'
GT_USERNAME = 'GT_USERNAME'
GT_PASSWORD = 'GT_PASSWORD'
GT_PAGE_SETTING_FILE = 'generic_test.page.yml'

ENV['HEADLESS'] ||= 'true'
ENV['PAGE_NUM'] ||= '1'
browser_args = %w[--disable-popup-blocking --no-sandbox --disable-dev-shm-usage]
browser_args << '--headless' if ENV['HEADLESS'] == 'true'

GenericTest.browser = Watir::Browser.new :chrome, args: browser_args

raise 'PAGE_URL environment variable not set' unless ENV['PAGE_URL']

require 'yamler'
if File.exist?(GT_PAGE_SETTING_FILE) && !File.read(GT_PAGE_SETTING_FILE).empty?
  gt_page_settings = Yamler.load 'generic_test.page.yml'
  if gt_page_settings['login']
    ENV[GT_USERNAME] = gt_page_settings['login']['username']
    ENV[GT_PASSWORD] = gt_page_settings['login']['password']
    ENV[GT_LOGIN_URL] = gt_page_settings['login']['url']
  end
end

browser = GenericTest.browser
if ENV[GT_LOGIN_URL] && ENV[GT_USERNAME] && ENV[GT_PASSWORD]
  browser.goto ENV[GT_LOGIN_URL]
  browser.text_field(xpath: "//input[@id=(//label[text()='Username']/@for)]|//input[@*='username']").set ENV[GT_USERNAME]
  browser.text_field(xpath: "//input[@id=(//label[text()='Password']/@for)]|//input[@*='password']").set ENV[GT_PASSWORD]
  login_button = browser.button(xpath: "//*[@type='submit']|//*[@*='Login']")
  login_button.click
  login_button.wait_while(&:present?)
  puts "Login through #{ENV[GT_LOGIN_URL]} successful!"
end

browser.goto ENV['PAGE_URL']
sleep 2.5 # Give a bit of time for page to load
GenericTest.pages << GenericTest::Page.new(browser)

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
generic_test-0.1.11 lib/generic_test/setup.rb