lib/generic_test/setup.rb in generic_test-0.1.11 vs lib/generic_test/setup.rb in generic_test-0.1.12
- old
+ new
@@ -1,17 +1,11 @@
# frozen_string_literal: true
# One file to require gem and set things up, arriving at page to check
require 'generic_test'
+require_relative 'xpath'
-# @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'
@@ -30,16 +24,16 @@
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]
+ browser.text_field(xpath: Xpath.label_or_attribute('username')).set ENV[GT_USERNAME]
+ browser.text_field(xpath: Xpath.label_or_attribute('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)
\ No newline at end of file
+GenericTest.pages << GenericTest::Page.new(browser)