taf 0.4.8 → 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 768dc5f49d4e43dfe0fa2204332c6aa4f6381fb5f9f0f5deebd4000a34b243d6
4
- data.tar.gz: f6c53a43233dfea0a02c2028e3e43de390bb8cee239033b80aa53088ee88fe4f
3
+ metadata.gz: 31c202a157c5f26907dacb3a08df58921f03cea0a5eb9bcc75523cdd7b44c148
4
+ data.tar.gz: 22aefc58b15a5b6ea4c0396c82528ff335d9cd1ca05e7dfae6978c44b7d902a2
5
5
  SHA512:
6
- metadata.gz: c7931a9595ec40c9be46342a0d2600a7e3da1441e2e3466a84611255b372c2f85514b9d635c2c6226e3ce1ccee91f2b6a316106814394074e54c42011e3f1bc0
7
- data.tar.gz: a46d04a04fe0f1ae8c2e2d65517914019729dcde9d18b34b994504999dd28139a2a76c140d1fe0085a4f56e30c03e6b21724ffc774faf48821e6ef5866f9ab71
6
+ metadata.gz: db6b224929133960d7adebe1a6069773f97bb170a0a7a620d9320a04d74e4736be1dfe4c53f56ffb67e94d343e1c839aad043ba9acc790a3c14915826259f893
7
+ data.tar.gz: 95ee60dfb7b653b4110d8c8652e84c8eb4bce57b2cb4a7432901fe40308dc6d12e61561532ae1c52eb7eb5e24adc39ea94604cf6701bd1e1742c4c99e180b7f3
@@ -25,28 +25,25 @@ module Taf
25
25
  Taf::Browser.b.text_field(id: user_elm).wait_until(&:exists?)
26
26
  .set user
27
27
  Taf::Browser.b.text_field(id: pass_elm).set pass
28
- button = 'Sign in' || 'Log in'
29
- Taf::Browser.b.button(value: button).wait_until(&:exists?).click
28
+ Taf::Browser.b.button(value: 'Sign in').wait_until(&:exists?).click
30
29
  sleep 1
31
30
  else
32
31
  Taf::MyLog.log.warn("User: #{user} has failed to log in.")
33
32
  end
34
33
  end
35
34
 
36
- def login_check(b_title_sucess, user)
37
- if Taf::Browser.b.title.eql?(b_title_sucess)
38
- 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.")
39
38
  true
40
39
  else
41
- Taf::MyLog.log.warn("User: #{user} has failed to log in.")
40
+ Taf::MyLog.log.warn("URL: #{url} is incorrect.")
42
41
  false
43
42
  end
44
43
  end
45
44
 
46
- def mem_word_check(user, b_title_sucess)
47
- if Taf::Browser.b.title.eql?('Memorable word Portal')
48
- portal_mem_word(user, b_title_sucess)
49
- 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)
50
47
  Taf::MyLog.log.info("User: #{user} has logged in successful.")
51
48
  true
52
49
  else
@@ -55,7 +52,7 @@ module Taf
55
52
  end
56
53
  end
57
54
 
58
- def portal_mem_word(user, b_title_sucess)
55
+ def portal_mem_word(user, b_title_success)
59
56
  password = ENV['PORTAL_MEM']
60
57
  nums = (1..256).to_a
61
58
  found_mem_nums = nums.each_with_object([]) do |num_val, mem_word|
@@ -74,7 +71,7 @@ module Taf
74
71
  end
75
72
 
76
73
  Taf::Browser.b.button(value: 'Sign in').wait_until(&:exists?).click
77
- if Taf::Browser.b.title.eql?(b_title_sucess)
74
+ if Taf::Browser.b.title.eql?(b_title_success)
78
75
  Taf::MyLog.log.info("User: #{user} has logged in successful.")
79
76
  return true
80
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
@@ -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
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Taf
4
- VERSION = '0.4.8'
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.8
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-30 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