taf 0.4.4 → 0.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 0501ee31ac5742b113c9e33b359bc324dae96b87e7a2caf82495113d6e6a3222
4
- data.tar.gz: f9021907fd6dec231fe807e0afd32e2879ce44a9789f0bfd89ab62febb326e05
3
+ metadata.gz: 31c202a157c5f26907dacb3a08df58921f03cea0a5eb9bcc75523cdd7b44c148
4
+ data.tar.gz: 22aefc58b15a5b6ea4c0396c82528ff335d9cd1ca05e7dfae6978c44b7d902a2
5
5
  SHA512:
6
- metadata.gz: 527cb4c93cce55d055bf5bb3d28026db1d5733ad8ba11c9bd91e2b091e1cedc3851169f889a2a6f4dc8ea6f932bbeb7f9fd23eb87e1f819c296ce76b106d8596
7
- data.tar.gz: 16061dd456c4449a343261651e50b1c9de3509ef982acb965f9778a4f5f3d3bcd4a9abd9f1abeb757bcbdfb5921da21c92418939a898c60632a6ce1125c20d47
6
+ metadata.gz: db6b224929133960d7adebe1a6069773f97bb170a0a7a620d9320a04d74e4736be1dfe4c53f56ffb67e94d343e1c839aad043ba9acc790a3c14915826259f893
7
+ data.tar.gz: 95ee60dfb7b653b4110d8c8652e84c8eb4bce57b2cb4a7432901fe40308dc6d12e61561532ae1c52eb7eb5e24adc39ea94604cf6701bd1e1742c4c99e180b7f3
@@ -9,7 +9,7 @@
9
9
  module Taf
10
10
  # browser_setup.rb - a browser functions
11
11
  module Browser
12
- # Suppoerted Browser names
12
+ # Supported Browser names
13
13
  @chrome_name = 'chrome'
14
14
  @chrome_headless_name = 'chrome-headless'
15
15
  @firefox_name = 'firefox'
@@ -17,61 +17,46 @@ module Taf
17
17
 
18
18
  # open_browser function
19
19
  def self.open_browser
20
- browser = Taf::CMDLine.browser_type.downcase
21
- case browser
22
- when @chrome_name then chrome
23
- when @chrome_headless_name then chrome_headless
24
- when @firefox_name then firefox
25
- when @firefox_headless_name then firefox_headless
20
+ @browser_name = Taf::CMDLine.browser_type.downcase
21
+ case @browser_name
22
+ when @chrome_name, @chrome_headless_name then chrome
23
+ when @firefox_name, @firefox_headless_name then firefox
26
24
  else
27
25
  raise Taf::BrowserFailedOpen,
28
- "unable to open selected browser: #{browser}"
26
+ "unable to open selected browser: #{@browser_name}"
29
27
  end
30
28
  end
31
29
 
32
30
  # chrome browser details
33
31
  def self.chrome
34
- @browser = Watir::Browser.new :chrome, switches: %w[
35
- --acceptInsecureCerts-true --start-maximized --window-size=1920,1080
36
- ]
37
- end
38
-
39
- # chrome headless browser details
40
- def self.chrome_headless
41
- @browser = Watir::Browser.new :chrome, switches: %w[
42
- --start-maximized --disable-gpu --headless --acceptInsecureCerts-true
43
- --no-sandbox --window-size=1920,1080
44
- ]
32
+ case @browser_name
33
+ when @chrome_name
34
+ chrome_values = %w[
35
+ --acceptInsecureCerts-true --start-maximized --window-size=1920,1080
36
+ ]
37
+ when @chrome_headless_name
38
+ chrome_values = %w[
39
+ --start-maximized --disable-gpu --headless --acceptInsecureCerts-true
40
+ --no-sandbox --window-size=1920,1080
41
+ ]
42
+ end
43
+ @browser = Watir::Browser.new :chrome, switches: chrome_values
45
44
  end
46
45
 
47
46
  # firefox browser details
48
47
  def self.firefox
49
48
  caps = Selenium::WebDriver::Remote::Capabilities.firefox
50
49
  caps['acceptInsecureCerts'] = true
51
- driver = Selenium::WebDriver.for(:firefox, desired_capabilities: caps)
52
- @browser = Watir::Browser.new(driver)
53
- browser_full_screen
54
- end
55
-
56
- # firefox headless browser details
57
- def self.firefox_headless
58
- caps = Selenium::WebDriver::Remote::Capabilities.firefox
59
- options = Selenium::WebDriver::Firefox::Options.new(args: ['-headless'])
60
- caps['acceptInsecureCerts'] = true
61
- driver = Selenium::WebDriver.for(:firefox, options: options,
62
- desired_capabilities: caps)
50
+ case @browser_name
51
+ when @firefox_name
52
+ driver = Selenium::WebDriver.for(:firefox, desired_capabilities: caps)
53
+ when @firefox_headless_name
54
+ options = Selenium::WebDriver::Firefox::Options.new(args: ['-headless'])
55
+ driver = Selenium::WebDriver.for(:firefox, options: options,
56
+ desired_capabilities: caps)
57
+ end
63
58
  @browser = Watir::Browser.new(driver)
64
- # makes the browser full screen.
65
- @browser.driver.manage.window.resize_to(1920, 1200)
66
- @browser.driver.manage.window.move_to(0, 0)
67
- end
68
-
69
- # makes the browser full screen.
70
- def self.browser_full_screen
71
- screen_width = @browser.execute_script('return screen.width;')
72
- screen_height = @browser.execute_script('return screen.height;')
73
- @browser.driver.manage.window.resize_to(screen_width, screen_height)
74
- @browser.driver.manage.window.move_to(0, 0)
59
+ @browser.driver.manage.window.maximize
75
60
  end
76
61
 
77
62
  # define browser value
@@ -81,8 +66,7 @@ module Taf
81
66
 
82
67
  # Check browser version
83
68
  def self.browser_version
84
- browser_name = Taf::CMDLine.browser_type.downcase
85
- case browser_name
69
+ case @browser_name
86
70
  when @chrome_name, @chrome_headless_name
87
71
  @browser.driver.capabilities[:version]
88
72
  when @firefox_name, @firefox_headless_name
@@ -94,8 +78,7 @@ module Taf
94
78
 
95
79
  # Check platform
96
80
  def self.browser_platform
97
- browser_name = Taf::CMDLine.browser_type.downcase
98
- case browser_name
81
+ case @browser_name
99
82
  when @chrome_name, @chrome_headless_name
100
83
  @browser.execute_script('return navigator.userAgent;')
101
84
  .split(';')[1].split(')')[0]
@@ -36,7 +36,6 @@ module Taf
36
36
  testvalue: parse_json['value0'],
37
37
  locate: parse_json['value1'] || 'id',
38
38
  testvalue2: parse_json['value2'],
39
- locate2: parse_json['value3'] || 'id',
40
39
  skipTestCase: parse_json['skipTestCase'] == 'yes' }
41
40
 
42
41
  parsed_step
@@ -9,10 +9,7 @@ module Taf
9
9
  def initialize(step_attributes)
10
10
  @value = step_attributes[:testvalue]
11
11
  @value2 = step_attributes[:testvalue2]
12
- @value3 = step_attributes[:testvalue3]
13
12
  @locate = step_attributes[:locate]
14
- @locate2 = step_attributes[:locate2]
15
- @locate3 = step_attributes[:locate3]
16
13
  end
17
14
 
18
15
  def self.register(name)
@@ -28,28 +25,25 @@ module Taf
28
25
  Taf::Browser.b.text_field(id: user_elm).wait_until(&:exists?)
29
26
  .set user
30
27
  Taf::Browser.b.text_field(id: pass_elm).set pass
31
- button = 'Sign in' || 'Log in'
32
- Taf::Browser.b.button(value: button).wait_until(&:exists?).click
28
+ Taf::Browser.b.button(value: 'Sign in').wait_until(&:exists?).click
33
29
  sleep 1
34
30
  else
35
31
  Taf::MyLog.log.warn("User: #{user} has failed to log in.")
36
32
  end
37
33
  end
38
34
 
39
- def login_check(b_title_sucess, user)
40
- if Taf::Browser.b.title.eql?(b_title_sucess)
41
- Taf::MyLog.log.info("User: #{user} has logged in successful.")
35
+ def url_check(url)
36
+ if Taf::Browser.b.url == url
37
+ Taf::MyLog.log.info("URL: #{url} is correct.")
42
38
  true
43
39
  else
44
- Taf::MyLog.log.warn("User: #{user} has failed to log in.")
40
+ Taf::MyLog.log.warn("URL: #{url} is incorrect.")
45
41
  false
46
42
  end
47
43
  end
48
44
 
49
- def mem_word_check(user, b_title_sucess)
50
- if Taf::Browser.b.title.eql?('Memorable word Portal')
51
- portal_mem_word(user, b_title_sucess)
52
- elsif Taf::Browser.b.title.eql?(b_title_sucess)
45
+ def login_check(b_title_success, user)
46
+ if Taf::Browser.b.title.eql?(b_title_success)
53
47
  Taf::MyLog.log.info("User: #{user} has logged in successful.")
54
48
  true
55
49
  else
@@ -58,7 +52,7 @@ module Taf
58
52
  end
59
53
  end
60
54
 
61
- def portal_mem_word(user, b_title_sucess)
55
+ def portal_mem_word(user, b_title_success)
62
56
  password = ENV['PORTAL_MEM']
63
57
  nums = (1..256).to_a
64
58
  found_mem_nums = nums.each_with_object([]) do |num_val, mem_word|
@@ -77,7 +71,7 @@ module Taf
77
71
  end
78
72
 
79
73
  Taf::Browser.b.button(value: 'Sign in').wait_until(&:exists?).click
80
- if Taf::Browser.b.title.eql?(b_title_sucess)
74
+ if Taf::Browser.b.title.eql?(b_title_success)
81
75
  Taf::MyLog.log.info("User: #{user} has logged in successful.")
82
76
  return true
83
77
  else
@@ -7,25 +7,21 @@ module Taf
7
7
  class ClickButton < Base
8
8
  register :click_button
9
9
 
10
- def check
11
- @elms = %i[button span a div link image h1 h2 h3 h4]
12
-
13
- found_button = @elms.map do |elm|
14
- Taf::Browser.b.send(elm, "#{@locate}": @value).exists?
15
- end.compact
10
+ def perform
11
+ # Optimisation: if we can immediately find the target in the DOM
12
+ # under a specific tag we should use it.
13
+ @tag = %i[button span a div link image h1 h2 h3 h4].find do |e|
14
+ Taf::Browser.b.send(e, "#{@locate}": @value).exists?
15
+ end
16
16
 
17
- raise 'Multiple matches' if found_button.select { |i| i }.empty?
17
+ # Otherwise, fallback to locating across the entire DOM.
18
+ # This can be necessary for when content rendering is deferred
19
+ # (e.g., a loader in a SPA) or if the user wants to use CSS or XPath.
20
+ @tag ||= :element
18
21
 
19
- index = found_button.index(true)
20
- return unless index
22
+ Taf::Browser.b.send(@tag, "#{@locate}": @value).wait_until(&:exists?)
23
+ .click
21
24
 
22
- index
23
- end
24
-
25
- def perform
26
- index = check
27
- Taf::Browser.b.send(@elms[index], "#{@locate}": @value)
28
- .wait_until(&:exists?).click
29
25
  Taf::MyLog.log.info("Button: #{@value} has been selected")
30
26
  true
31
27
  rescue StandardError
@@ -3,24 +3,25 @@
3
3
  module Taf
4
4
  module TestSteps
5
5
  module Handlers
6
- # Png Test function.
7
- class PingTest < Base
8
- register :ping_test
6
+ # Health Check function to check the status of a web address or ip.
7
+ class HealthCheck < Base
8
+ register :health_check
9
9
 
10
10
  def perform
11
11
  tries ||= 20
12
- Faraday.get(@value)
12
+ res = Faraday.get(@value)
13
+ status = res.status
13
14
  rescue Faraday::Error
14
15
  if (tries -= 1).positive?
15
16
  sleep 1
16
17
  puts "Failed to ping: #{@value} - Retries left: #{tries}"
17
18
  retry
18
19
  else
19
- Taf::MyLog.log.warn("Failed to ping: #{@value}")
20
+ Taf::MyLog.log.warn("Site Error: #{@value} status code: #{status}")
20
21
  false
21
22
  end
22
23
  else
23
- Taf::MyLog.log.info("Pinged successfully: #{@value}")
24
+ Taf::MyLog.log.info("Site: #{@value} status code: #{status}")
24
25
  true
25
26
  end
26
27
  end
@@ -16,9 +16,7 @@ module Taf
16
16
 
17
17
  def login_user(user)
18
18
  case @value.downcase
19
- when 'admin_portal_login' then admin_portal_login(user)
20
19
  when 'portal_login' then portal_login(user)
21
- when 'sint_login' then sint_login(user)
22
20
  when 'sso_login' then sso_login(user)
23
21
  else
24
22
  Taf::MyLog.log.error "unable to find login: #{@value}"
@@ -28,56 +26,53 @@ module Taf
28
26
 
29
27
  private
30
28
 
31
- def admin_portal_login(user)
32
- url = ENV['ADMINL_URL']
33
- pass = ENV['ADMIN_USER_PASS']
34
- b_title = 'Log in Portal Admin'
35
- b_title_sucess = 'Home Admin Portal'
36
- user_elm = 'admin_username'
37
- pass_elm = 'admin_password'
38
-
39
- Taf::Browser.b.goto(url)
40
- login_process(b_title, user_elm, pass_elm, user, pass)
41
- login_check(b_title_sucess, user)
42
- end
43
-
44
29
  def portal_login(user)
45
30
  url = ENV['PORTAL_URL']
46
31
  pass = ENV['PORTAL_USER_PASS']
47
- b_title = 'Log in Portal'
48
- b_title_sucess = 'Home Portal'
32
+ b_title = 'Log in'
33
+ b_title_success = 'Home'
34
+ memorable_word_title = 'Memorable word'
49
35
  user_elm = 'user_email'
50
36
  pass_elm = 'user_password'
37
+ max_retry = 2
51
38
 
52
- Taf::Browser.b.goto(url)
53
- login_process(b_title, user_elm, pass_elm, user, pass)
54
- mem_word_check(user, b_title_sucess)
39
+ max_retry.times do
40
+ Taf::Browser.b.goto(url)
41
+ url_check(url)
42
+ login_process(b_title, user_elm, pass_elm, user, pass)
43
+
44
+ begin
45
+ Taf::Browser.b.wait_until(timeout: 30) do |b|
46
+ b.title == b_title_success || b.title == memorable_word_title
47
+ end
48
+ rescue Watir::Wait::TimeoutError
49
+ Taf::MyLog.log.warn('Retrying login process...')
50
+ next
51
+ end
52
+
53
+ success = true
54
+
55
+ if Taf::Browser.b.title.eql?(memorable_word_title)
56
+ success = portal_mem_word(user, b_title_success)
57
+ end
58
+
59
+ return success
60
+ end
61
+
62
+ false
55
63
  end
56
64
 
57
65
  def sso_login(user)
58
66
  pass = ENV['SSO_USER_PASS']
59
- # b_title = 'Log in to rh-sso'
60
- # b_title_sucess = 'RHS-SSO Admin Console'
61
67
  b_title = ''
62
- b_title_sucess = ''
68
+ b_title_success = ''
63
69
  user_elm = 'username'
64
70
  pass_elm = 'password'
65
71
 
66
- login_process(b_title, user_elm, pass_elm, user, pass)
67
- login_check(b_title_sucess, user)
68
- end
69
-
70
- def sint_login(user)
71
- url = ENV['SINT_URL']
72
- pass = ENV['SINT_USER_PASS']
73
- b_title = 'SINT'
74
- b_title_sucess = 'SINT'
75
- user_elm = 'user_username'
76
- pass_elm = 'user_password'
77
-
78
72
  Taf::Browser.b.goto(url)
73
+ url_check(url)
79
74
  login_process(b_title, user_elm, pass_elm, user, pass)
80
- login_check(b_title_sucess, user)
75
+ login_check(b_title_success, user)
81
76
  end
82
77
  end
83
78
  end
@@ -8,14 +8,11 @@ module Taf
8
8
  register :radio_button
9
9
 
10
10
  def perform
11
- Taf::Browser.b.radio("#{@locate}": @value).wait_until(&:exists?)
12
- Taf::Browser.b
13
- .radio("#{@locate}": @value, "#{@locate2}": @value2.to_s)
14
- .set
15
- Taf::MyLog.log.info("Radio button: #{@value2} has been selected")
11
+ Taf::Browser.b.radio("#{@locate}": @value).wait_until(&:exists?).set
12
+ Taf::MyLog.log.info("Radio button: #{@value} has been selected")
16
13
  true
17
14
  rescue StandardError
18
- Taf::MyLog.log.warn("Radio button: #{@value2} does not exist")
15
+ Taf::MyLog.log.warn("Radio button: #{@value} does not exist")
19
16
  false
20
17
  end
21
18
  end
@@ -10,8 +10,7 @@ module Taf
10
10
  def perform
11
11
  ele = Taf::Browser.b.select_list("#{@locate}": @value)
12
12
 
13
- ele.wait_until(&:exists?)
14
- ele.option("#{@locate2}": @value2.to_s).select
13
+ ele.wait_until(&:exists?).select @value2.to_s
15
14
  Taf::MyLog.log.info("Dropdown item: #{@value2} has been selected")
16
15
  true
17
16
  rescue StandardError
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Taf
4
- VERSION = '0.4.4'
4
+ VERSION = '0.5.0'
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: taf
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.4
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andy Perrett
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-08-15 00:00:00.000000000 Z
11
+ date: 2019-09-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -204,11 +204,11 @@ files:
204
204
  - lib/taf/test_steps/handlers/base/execute_system_command.rb
205
205
  - lib/taf/test_steps/handlers/base/generate_token.rb
206
206
  - lib/taf/test_steps/handlers/base/handle_browser_window.rb
207
+ - lib/taf/test_steps/handlers/base/health_check.rb
207
208
  - lib/taf/test_steps/handlers/base/ipause.rb
208
209
  - lib/taf/test_steps/handlers/base/list_all_dropdowns_values.rb
209
210
  - lib/taf/test_steps/handlers/base/login.rb
210
211
  - lib/taf/test_steps/handlers/base/open_url.rb
211
- - lib/taf/test_steps/handlers/base/ping_test.rb
212
212
  - lib/taf/test_steps/handlers/base/radio_button.rb
213
213
  - lib/taf/test_steps/handlers/base/select_dropdown.rb
214
214
  - lib/taf/test_steps/handlers/base/send_special_keys.rb