Ifd_Automation 2.6 → 2.7

Sign up to get free protection for your applications and to get access to all the features.
Files changed (47) hide show
  1. checksums.yaml +4 -4
  2. data/bin/generate.rb +21 -3
  3. data/bin/helper.rb +5 -4
  4. data/lib/Ifd_Automation/require_libs.rb +9 -6
  5. data/lib/Ifd_Automation/version.rb +1 -1
  6. data/lib/helper/{assertion_helpers.rb → assertion_helper.rb} +5 -5
  7. data/lib/helper/auto_util.rb +164 -0
  8. data/lib/helper/database_helper.rb +81 -0
  9. data/lib/helper/file_helper.rb +36 -0
  10. data/lib/helper/mail_helper.rb +58 -0
  11. data/lib/helper/rest_helper.rb +91 -0
  12. data/lib/helper/soap_helper.rb +59 -0
  13. data/lib/helper/ssh_helper.rb +39 -0
  14. data/lib/helper/web_steps_helper.rb +447 -0
  15. data/project/Dockerfile +20 -0
  16. data/project/Gemfile.lock +176 -0
  17. data/project/README.md +60 -0
  18. data/project/cucumber.yml +6 -0
  19. data/project/docker-compose.yml +7 -0
  20. data/project/features/TestData/globalData.yml +3 -1
  21. data/project/features/TestSuite/WebGUI.feature +16 -2
  22. data/project/features/step_definitions/IFD_Libraries/REST_steps.rb +34 -0
  23. data/project/features/step_definitions/IFD_Libraries/SOAP_steps.rb +38 -0
  24. data/project/features/step_definitions/IFD_Libraries/database_steps.rb +44 -0
  25. data/{lib/Ifd_Automation/dynamic_store_vavue_steps.rb → project/features/step_definitions/IFD_Libraries/dynamic_store_value_steps.rb} +8 -10
  26. data/project/features/step_definitions/IFD_Libraries/email_steps.rb +36 -0
  27. data/project/features/step_definitions/IFD_Libraries/file_steps.rb +11 -0
  28. data/project/features/step_definitions/IFD_Libraries/ssh_steps.rb +20 -0
  29. data/{lib/Ifd_Automation → project/features/step_definitions/IFD_Libraries}/web_steps.rb +18 -8
  30. data/project/features/step_definitions/lib_steps/actionwords.rb +14 -10
  31. data/project/features/step_definitions/lib_steps/steps.rb +6 -0
  32. data/project/features/step_definitions/repositories/project_object.yml +2 -6
  33. data/project/features/support/env.rb +18 -18
  34. data/project/features/support/hooks.rb +22 -59
  35. metadata +45 -17
  36. data/lib/Ifd_Automation/REST_steps.rb +0 -90
  37. data/lib/Ifd_Automation/SOAP_steps.rb +0 -68
  38. data/lib/Ifd_Automation/database_steps.rb +0 -80
  39. data/lib/Ifd_Automation/email_steps.rb +0 -72
  40. data/lib/Ifd_Automation/file_steps.rb +0 -24
  41. data/lib/Ifd_Automation/ssh_steps.rb +0 -38
  42. data/lib/helper/auto_utils.rb +0 -67
  43. data/lib/helper/connection_helpers.rb +0 -15
  44. data/lib/helper/core.rb +0 -646
  45. data/lib/helper/mail_helpers.rb +0 -17
  46. data/lib/helper/web_steps_helpers.rb +0 -176
  47. data/project/features/step_definitions/lib_steps/test.rb +0 -6
@@ -1,68 +0,0 @@
1
- require 'savon'
2
- require_relative 'require_libs'
3
- require 'jsonpath'
4
-
5
- # Example
6
- # When I get SOAP operations list from 'http://ws.cdyne.com/emailverify/Emailvernotestemail.asmx?wsdl'
7
- When /^I get SOAP operations list from '(.*?)'$/ do |url|
8
- request_url = URI.encode check_dynamic_value url
9
- @SOAPclient = Savon.client(ssl_verify_mode: :none,
10
- wsdl: "#{request_url}",
11
- :open_timeout => 10,
12
- :read_timeout => 10,
13
- :log => false)
14
- p "Operations List: #{@SOAPclient.operations}"
15
- end
16
-
17
- # Example
18
- # When I send SOAP request with operation name "verify_email" and XML file "soap.xml"
19
- When /^I send SOAP request with operation name "(.*)" and XML file "(.*)"$/ do |operation_name,file_name|
20
- xml = File.read($test_data_dir + file_name)
21
- @response = call_and_fail_gracefully(@SOAPclient, operation_name.downcase.to_sym, xml: xml )
22
- end
23
-
24
- # Example
25
- # I send SOAP request with operation name "xr" and following data:
26
- # """
27
- # Sample XML
28
- # """
29
- When /^I send SOAP request with operation name "(.*)" and following data:$/ do |operation_name,raw_data|
30
- @response = call_and_fail_gracefully(@SOAPclient, operation_name.downcase.to_sym, xml: raw_data )
31
- end
32
-
33
- Then /^the status code should be "(.*)"$/ do |status|
34
- Assertion.assert_string_equal(get_soap_response.http.code, status.to_i)
35
- end
36
-
37
-
38
- # Example
39
- # Then the SOAP response node should have "$..response_text" with text "Email Domain Not Found"
40
- Then /^the SOAP response node should have "(.*?)" with text "(.*?)"$/ do |json_path, text|
41
- json = get_soap_response.body.to_json
42
- results = JsonPath.new(json_path).on(json).to_a.map(&:to_s)
43
- Assertion.assert_string_equal(text, results[0])
44
- end
45
-
46
- Then /^I print the SOAP response$/ do
47
- p "SOAP RESPONSE: #{get_soap_response}"
48
- end
49
-
50
- def get_soap_response
51
- soap_response = @response
52
- if soap_response.nil?
53
- raise "ERROR***: MISSING STEPS: Please send SOAP request to get the response first."
54
- else
55
- soap_response
56
- end
57
- soap_response
58
- end
59
-
60
- def call_and_fail_gracefully(client, *args, &block)
61
- if client.nil?
62
- raise "ERROR***: MISSING STEPS: Please run step to get operation list from WSDL first."
63
- else
64
- client.call(*args, &block)
65
- end
66
- rescue Savon::SOAPFault => e
67
- puts e.message
68
- end
@@ -1,80 +0,0 @@
1
- require_relative 'require_libs'
2
- Given /^I create connection to database with:$/ do |data|
3
- unless data.hashes.empty?
4
- data = data.hashes[0]
5
- data = JSON.parse(data) unless data.is_a? Hash
6
-
7
- data.each_pair do |k, v|
8
- data[k] = check_dynamic_value(v)
9
- end
10
- @connection = Connection.new(data)
11
- put_log "Connect to database successfully!" if @connection
12
- end
13
- end
14
- # NEW
15
- When /^I close SQL connection$/ do
16
- @connection.disconnect!
17
- if !@connection.connected?
18
- put_log "Disconnected to Database!"
19
- end
20
- end
21
-
22
-
23
- #NEW
24
- And /^I run sql script:$/ do |raw_data|
25
- begin
26
- script = bind_with_dyn_vars(raw_data)
27
- @result = @connection.connection.execute(script)
28
- rescue Exception => e
29
- raise e.message
30
- end
31
- # end
32
- end
33
-
34
- # Example
35
- # When I run sql script "select * from users where email=#{id}"
36
- And /^I run sql script "(.*)"$/ do |sql|
37
- script = check_dynamic_value sql
38
- if @connection
39
- @result = @connection.connection.execute(script)
40
- else
41
- raise "ERROR: Create connection to database first!"
42
- end
43
- end
44
-
45
- Then /^show me the result of SQL statement$/ do
46
- unless @result.nil?
47
- p result.to_hash
48
- for i in 0..@result
49
- puts "\n SQL Result: #{i}"
50
- end
51
- @result.each(:as => :hash) do |row|
52
- puts "----#{row}===="
53
- end
54
- end
55
- end
56
-
57
- # Example
58
- # Then the result of SQL statement should be:
59
- # """
60
- # {"name": "quoc anh", "email": "anhpq.info@gmail.com"}
61
- # """
62
- Then /^the result of SQL statement should be:$/ do |json|
63
- expected = JSON.parse(json)
64
- @result.each(:as => :hash) do |row|
65
- Assertion.assert_string_equal(expected,row)
66
- end
67
- end
68
-
69
- # Example
70
- # Then the result of SQL statement should have "email" with value "anhpq.info@gmail.com"
71
- Then /^the result of SQL statement should have "(.*)" with value "(.*)"$/ do |json_path, value|
72
- @result.each(:as => :hash) do |row|
73
- results = JsonPath.new(json_path).on(row).to_a.map(&:to_s)
74
- Assertion.assert_string_equal(results[0], value)
75
- end
76
- end
77
-
78
- When /^I store the result of SQL script as "(.*?)"$/ do |var_name|
79
- set_var(var_name, @result)
80
- end
@@ -1,72 +0,0 @@
1
- require 'action_mailer'
2
- require_relative 'require_libs'
3
- # Example:
4
- #
5
- # Then I send an email with:
6
- # """
7
- # From: from@example.com
8
- # Reply-To: reply-to@example.com
9
- # To: anh.pham@infodation.vn
10
- # Subject: SUBJECT
11
- # Attachments: globalData.yml
12
-
13
- # BODY
14
- # """
15
- #
16
- Then /^I send an e?mail with:$/ do |raw_data|
17
- raw_data.strip!
18
- header, body = raw_data.split(/\n\n/, 2) # 2: maximum number of fields
19
- conditions = {}
20
- header.split("\n").each do |row|
21
- if row.lstrip.chop.match(/^[a-z\-]+:/i)
22
- key, value = row.split(":", 2)
23
- conditions[key.gsub(' ','').underscore.to_sym] = value.gsub(' ','')
24
-
25
- end
26
- end
27
- conditions[:body] = body if body
28
- filepath = ($test_data_dir + conditions[:attachments] if conditions[:attachments])
29
- Email.send_email(conditions[:to], conditions[:subject], conditions[:body],filepath)
30
- end
31
-
32
- # Example:
33
- #
34
- # Then I should receive an email with:
35
- # """
36
- # From: from@example.com
37
- # Reply-To: reply-to@example.com
38
- # To: anh.pham@infodation.vn
39
- # Subject: SUBJECT
40
- # Attachments: globalData.yml
41
-
42
- # BODY
43
- # """
44
- #
45
-
46
- Then /^I should receive an e?mail with:$/ do |raw_data|
47
- raw_data.strip!
48
- header, body = raw_data.split(/\n\n/, 2) # 2: maximum number of fields
49
- conditions = {}
50
- header.split("\n").each do |row|
51
- if row.lstrip.chop.match(/^[a-z\-]+:/i)
52
- key, value = row.split(":", 2)
53
- conditions[key.gsub(' ','').underscore.to_sym] = value.gsub(' ','')
54
-
55
- end
56
- end
57
- conditions[:body] = body.squeeze(' ').strip if body
58
- sleep 5
59
- emails = Mail.find(:what => :last, :count => 1)
60
-
61
- if emails.instance_of? Mail::Message
62
- Assertion.assert_string_equal(conditions[:from], emails.from[0].to_s)
63
- Assertion.assert_string_equal(conditions[:subject], emails.subject)
64
- Assertion.assert_string_contain(conditions[:body], emails.body)
65
- emails.attachments.each do |attachment|
66
- Assertion.assert_string_equal(conditions[:attachments], attachment.filename)
67
- end if conditions[:attachments]
68
- else
69
- raise "WARNING: *** No new Email is found"
70
- end
71
- end
72
-
@@ -1,24 +0,0 @@
1
- require_relative 'require_libs'
2
-
3
- Then /^I delete test file "(.*)"$/ do |file_name|
4
- file_path = ($test_data_dir + file_name.gsub(" ", "_"))
5
- if File.exists?(file_path)
6
- File.delete(file_path)
7
- puts "#{file_name} is deleted successfully"
8
- else
9
- puts "File #{file_name} does not exists"
10
- end
11
- end
12
-
13
- Given /^I read data from file "(.*)"$/ do |file_name|
14
- @file_data = ""
15
- file_path = $test_data_dir + file_name.downcase
16
- if File.exist?(file_path)
17
- file = File.open(file_path)
18
- @file_data += file.read
19
- file.close
20
- else
21
- raise "*** WARNING: File #{file_name} does not exist."
22
- end
23
- p @file_data
24
- end
@@ -1,38 +0,0 @@
1
- require 'net/ssh'
2
- require_relative 'require_libs'
3
- When /^I SSH to "([^\"]*)" with the following credentials:$/ do |hostname, table|
4
- hostname = check_dynamic_value hostname
5
- @keys = []
6
- @auth_methods ||= %w(password)
7
- session = table.hashes.first
8
- session_keys = Array.new(@keys)
9
- session_auth_methods = Array.new(@auth_methods)
10
- if session["keyfile"]
11
- session_keys << session["keyfile"]
12
- session_auth_methods << "publickey"
13
- end
14
-
15
- @SSHconnection = Net::SSH.start(hostname, session["username"], :password => session["password"],
16
- :auth_methods => session_auth_methods,
17
- :keys => session_keys)
18
- end
19
-
20
- When /^I run SSH command "([^\"]*)"$/ do |command|
21
- command = check_dynamic_value command
22
- @output = @SSHconnection.exec!(command)
23
- end
24
-
25
-
26
- Then /^show me the SSH output result$/ do
27
- p @output
28
- end
29
-
30
- Then /^I should see "([^\"]*)" in the SSH output$/ do |string|
31
- string = check_dynamic_value string
32
- Assertion.assert_string_equal(string, @output.strip)
33
- end
34
-
35
- When /^I store the result of SSH as "(.*?)"$/ do |var_name|
36
- $context_value = bind_with_dyn_vars(@output)
37
- set_var(var_name, '$context_value')
38
- end
@@ -1,67 +0,0 @@
1
- #-----------------------------------------------------
2
- # support define and bind variable dynamically
3
- #-----------------------------------------------------
4
- $dyn_vars = nil
5
-
6
- # set value to a variable
7
- def set_var(var_name, var_value)
8
- if $dyn_vars == nil
9
- $dyn_vars = binding
10
- end
11
-
12
- strEval = var_name + "=" + var_value
13
- eval strEval, $dyn_vars
14
- end
15
-
16
- # bind string with $dyn_vars context
17
- def bind_with_dyn_vars(str)
18
- if $dyn_vars == nil
19
- $dyn_vars = binding
20
- end
21
-
22
- strEval = '"' + str + '"'
23
- return eval strEval, $dyn_vars
24
- end
25
-
26
- # evaluate operation/statement with $dyn_vars context
27
- def eval_with_dyn_vars(operation)
28
- if $dyn_vars == nil
29
- $dyn_vars = binding
30
- end
31
-
32
- eval operation, $dyn_vars
33
- end
34
-
35
- def bind_with_dyn_json_vars(json, bind_json)
36
- if json.kind_of? Hash
37
- json.each_pair do |k, v|
38
- if v.kind_of? String
39
- bind_json[bind_with_dyn_vars(k)] = bind_with_dyn_json_vars(v, bind_json)
40
- elsif v.kind_of? Hash
41
- temp = Hash.new
42
- v.each_pair do |k1, v1|
43
- temp[bind_with_dyn_vars(k1)] = bind_with_dyn_json_vars(v1, temp)
44
- end
45
- bind_json[bind_with_dyn_vars(k)] = temp
46
- elsif v.kind_of? Array
47
- temp1 = Array.new
48
- v.each {|item|
49
- temp2 = Hash.new
50
- bind_with_dyn_json_vars(item, temp2)
51
- temp1 << temp2
52
- }
53
- bind_json[bind_with_dyn_vars(k)] = temp1
54
- end
55
- end
56
- elsif json.kind_of? Array
57
- temp1 = Array.new
58
- json.each {|item|
59
- temp2 = Hash.new
60
- bind_with_dyn_json_vars(item, temp2)
61
- temp1 << temp2
62
- }
63
- return temp1
64
- else
65
- return bind_with_dyn_vars(json)
66
- end
67
- end
@@ -1,15 +0,0 @@
1
- require 'tiny_tds'
2
- require 'activerecord-sqlserver-adapter'
3
- require 'active_record'
4
-
5
- module Connection
6
- def self.new(connection_params)
7
- begin
8
- put_log ("Connecting to database...")
9
- return ActiveRecord::Base.establish_connection(connection_params)
10
- rescue Exception => e
11
- raise e.message
12
- end
13
- end
14
-
15
- end
@@ -1,646 +0,0 @@
1
- require 'rspec'
2
- def check_dynamic_value value
3
- if !value.is_a? Fixnum
4
- if value.include? "params="
5
- resolve_params value
6
- else
7
- bind_with_dyn_vars value
8
- end
9
- else
10
- value
11
- end
12
- end
13
-
14
-
15
- def resolve_params url
16
- condition = url.match(/params='([^']*)'/)[0]
17
- if condition
18
- params_name = url.match(/params='([^']*)'/)[1]
19
- params_value = $PARAMS["#{params_name.downcase}"]
20
- if params_value
21
- url = url.gsub(condition, params_value)
22
- else
23
- raise "ERROR: no data found with given params #{params_name}"
24
- end
25
- end
26
- url
27
- end
28
-
29
- #Print script log to console
30
- def put_log str
31
- p str if $_CFWEB['Print Log'] == true
32
- end
33
-
34
-
35
- def get_xpath_value_from_object_file string_object
36
- string_object = string_object.gsub(/"/, "'")
37
- puts "String_object: #{string_object}"
38
- locator_matching = /(.*?)(\{.*?\})/.match(string_object)
39
- puts "locator_matching : #{locator_matching}"
40
- dyn_pros = {}
41
- if locator_matching != nil
42
- string_object = locator_matching[1]
43
- eval(locator_matching[2].gsub(/['][\s,\t]*?:[\s,\t]*?[']?/, "'=>'")).each { |k, v|
44
- dyn_pros[k.to_s.upcase] = v
45
- }
46
- end
47
-
48
- hash_object = $OBJECT[string_object]
49
- if hash_object == nil
50
- put_log ">>> OBJECT NAME MAYBE NOT FOUND!!!"
51
- # true.should eq false
52
- expect(true).to eq(false)
53
- end
54
- xpath_value = ""
55
- upcase_attrb = {}
56
- if hash_object != nil
57
- hash_object.each { |k, v|
58
- k = k.to_s.upcase
59
- put_log "\n#{k} =~ /ph_/i and dyn_pros[#{k}]: #{k =~ /ph_/i and dyn_pros[k] != nil}"
60
- if k =~ /ph_/i
61
- if dyn_pros[k] != nil
62
- # Assign place holder value to place holder property, also remove prefix ph_ from property key,
63
- # also remove this pl from dyn_pros <= should be consider to continue transfer into inner object in relation
64
- if v =~ /<ph_value>/i
65
- upcase_attrb[k[3..k.size-1]] = v.gsub(/<ph_value>/i, dyn_pros[k])
66
- else
67
- upcase_attrb[k[3..k.size-1]] = dyn_pros[k]
68
- end
69
- dyn_pros.delete(k)
70
- end
71
- else
72
- upcase_attrb[k.to_s.upcase] = v
73
- end
74
- xpath_value = v
75
- }
76
- end
77
- xpath_value
78
- end
79
-
80
- # Find object by Xpath
81
- # def find_object string_object
82
- # p ":find object--"
83
- # startTime = Time.new.to_i
84
- # string_object = string_object.gsub(/"/, "'")
85
- # locator_matching = /(.*?)(\{.*?\})/.match(string_object)
86
- # dyn_pros = {}
87
- # if locator_matching != nil
88
- # string_object = locator_matching[1]
89
- # eval(locator_matching[2].gsub(/['][\s,\t]*?:[\s,\t]*?[']?/, "'=>'")).each { |k, v|
90
- # dyn_pros[k.to_s.upcase] = v
91
- # }
92
- # end
93
- #
94
- # hash_object = $OBJECT[string_object]
95
- # p "hash_object--------#{hash_object}"
96
- # if hash_object == nil
97
- # put_log ">>> OBJECT NAME MAYBE NOT FOUND!!!"
98
- # # true.should eq false
99
- # expect(true).to eq(false)
100
- # end
101
- # upcase_attrb = {}
102
- # if hash_object != nil
103
- # hash_object.each { |k, v|
104
- # k = k.to_s.upcase
105
- # p "\n#{k} =~ /ph_/i and dyn_pros[#{k}]: #{k =~ /ph_/i and dyn_pros[k] != nil}"
106
- # if k =~ /ph_/i
107
- # if dyn_pros[k] != nil
108
- # # Assign place holder value to place holder property, also remove prefix ph_ from property key,
109
- # # also remove this pl from dyn_pros <= should be consider to continue transfer into inner object in relation
110
- # if v =~ /<ph_value>/i
111
- # upcase_attrb[k[3..k.size-1]] = v.gsub(/<ph_value>/i, dyn_pros[k])
112
- # else
113
- # upcase_attrb[k[3..k.size-1]] = dyn_pros[k]
114
- # end
115
- #
116
- # dyn_pros.delete(k)
117
- # end
118
- # else
119
- # upcase_attrb[k.to_s.upcase] = v
120
- # end
121
- #
122
- # }
123
- # end
124
- # p ":upcase_attrb----#{upcase_attrb}"
125
- # if upcase_attrb.size > 0
126
- # strId = ""
127
- # strClass = ""
128
- # strName = ""
129
- # strTagname = ""
130
- # strXpathSelector = ""
131
- # strText = ""
132
- #
133
- # index = nil
134
- # upcase_attrb.each { |key, value|
135
- # upcase_key = key.to_s.upcase
136
- # if upcase_key == "XPATH_SELECTOR"
137
- # strXpathSelector = value
138
- # end
139
- # }
140
- # continue_run = true
141
- #
142
- # if continue_run == true
143
- # begin
144
- # if strXpathSelector != nil and strXpathSelector.size > 0
145
- # p "---------------------:get_objects_by_XpathSelector"
146
- # foundElements = get_objects_by_XpathSelector(strXpathSelector)
147
- # else
148
- # #Generate Selector
149
- # strGenerateXpathSel = ""
150
- # strGenerateXpathSel = generate_xpath_selector(strId, strClass, strName, strTagname)
151
- # if strGenerateXpathSel.length > 0
152
- # foundElements = get_objects_by_XpathSelector(strGenerateXpathSel)
153
- # end
154
- # end
155
- #
156
- # if foundElements == nil or foundElements.size == 0
157
- # currentTime = Time.new.to_i
158
- # else
159
- # # put_log "\nBREAK!!!"
160
- # break
161
- # end
162
- # test = currentTime - startTime
163
- # # put_log "\n#TIMEOUNT:#{test} < #{$_CFWEB['Wait Time']}"
164
- # sleep(0.5)
165
- # end while (currentTime - startTime) < $_CFWEB['Wait Time']
166
- #
167
- # if foundElements != nil or foundElements.size != 0
168
- # if index != nil and index.to_i >= 0
169
- # matched_index = 0;
170
- # return_element = nil
171
- # foundElements.each { |cur_element|
172
- # passCheck = find_object_check_object(cur_element, strId, strText)
173
- # if passCheck
174
- # if matched_index == index.to_i
175
- # return_element = cur_element
176
- # break
177
- # else
178
- # matched_index = matched_index + 1
179
- # end
180
- # end
181
- # }
182
- # return return_element
183
- # else
184
- # return_element = nil
185
- # foundElements.each { |cur_element|
186
- # passCheck = find_object_check_object(cur_element, strId, strText)
187
- # if passCheck
188
- # return_element = cur_element
189
- # break
190
- # end
191
- # }
192
- # return return_element
193
- # end # if index != nil and index.to_i >= 0
194
- # end #if foundElements != nil or foundElements.length != 0
195
- # end #if continue = true
196
- # end
197
- #
198
- # return nil
199
- # end
200
- def find_object string_object
201
- p ":find object--"
202
- startTime = Time.new.to_i
203
- string_object = string_object.gsub(/"/, "'")
204
- locator_matching = /(.*?)(\{.*?\})/.match(string_object)
205
- dyn_pros = {}
206
- if locator_matching != nil
207
- string_object = locator_matching[1]
208
- eval(locator_matching[2].gsub(/['][\s,\t]*?:[\s,\t]*?[']?/, "'=>'")).each { |k, v|
209
- dyn_pros[k.to_s.upcase] = v
210
- }
211
- end
212
-
213
- hash_object = $OBJECT[string_object]
214
- p "hash_object--------#{hash_object}"
215
- if hash_object == nil
216
- put_log ">>> OBJECT NAME MAYBE NOT FOUND!!!"
217
- # true.should eq false
218
- expect(true).to eq(false)
219
- end
220
- upcase_attrb = {}
221
- if hash_object != nil
222
- hash_object.each { |k, v|
223
- k = k.to_s.upcase
224
- p "\n#{k} =~ /ph_/i and dyn_pros[#{k}]: #{k =~ /ph_/i and dyn_pros[k] != nil}"
225
- if k =~ /ph_/i
226
- if dyn_pros[k] != nil
227
- # Assign place holder value to place holder property, also remove prefix ph_ from property key,
228
- # also remove this pl from dyn_pros <= should be consider to continue transfer into inner object in relation
229
- if v =~ /<ph_value>/i
230
- upcase_attrb[k[3..k.size-1]] = v.gsub(/<ph_value>/i, dyn_pros[k])
231
- else
232
- upcase_attrb[k[3..k.size-1]] = dyn_pros[k]
233
- end
234
-
235
- dyn_pros.delete(k)
236
- end
237
- else
238
- upcase_attrb[k.to_s.upcase] = v
239
- end
240
-
241
- }
242
- end
243
- p ":upcase_attrb----#{upcase_attrb}"
244
- p ":dyn_pros----#{dyn_pros}"
245
- if upcase_attrb.size > 0
246
- strId = ""
247
- strClass = ""
248
- strName = ""
249
- strTagname = ""
250
- strXpathSelector = ""
251
- strCssSelecor = ""
252
- strText = ""
253
-
254
- index = nil
255
- upcase_attrb.each { |key, value|
256
- upcase_key = key.to_s.upcase
257
- case upcase_key
258
- when "XPATH_SELECTOR"
259
- strXpathSelector = value
260
- when "CSS_SELECTOR"
261
- strCssSelecor = value
262
- end
263
- # if upcase_key == "XPATH_SELECTOR"
264
- # strXpathSelector = value
265
- # end
266
- }
267
- continue_run = true
268
-
269
- if continue_run == true
270
- begin
271
- if strXpathSelector != nil and strXpathSelector.size > 0
272
- p "---------------------:get_objects_by_XpathSelector"
273
- foundElements = get_objects_by_XpathSelector(strXpathSelector)
274
- elsif strCssSelecor != nil and strCssSelecor.size > 0
275
- p "---------------------:get_objects_by_CssSelector"
276
- foundElements = get_objects_by_CssSelector(strCssSelecor)
277
- # else
278
- # #Generate Selector
279
- # strGenerateXpathSel = ""
280
- # strGenerateXpathSel = generate_xpath_selector(strId, strClass, strName, strTagname)
281
- # if strGenerateXpathSel.length > 0
282
- # foundElements = get_objects_by_XpathSelector(strGenerateXpathSel)
283
- # end
284
- end
285
-
286
- if foundElements == nil or foundElements.size == 0
287
- currentTime = Time.new.to_i
288
- else
289
- # put_log "\nBREAK!!!"
290
- break
291
- end
292
- test = currentTime - startTime
293
- # put_log "\n#TIMEOUNT:#{test} < #{$_CFWEB['Wait Time']}"
294
- sleep(0.5)
295
- end while (currentTime - startTime) < $_CFWEB['Wait Time']
296
-
297
- if foundElements != nil or foundElements.size != 0
298
- if index != nil and index.to_i >= 0
299
- matched_index = 0
300
- return_element = nil
301
- foundElements.each { |cur_element|
302
- passCheck = find_object_check_object(cur_element, strId, strText)
303
- if passCheck
304
- if matched_index == index.to_i
305
- return_element = cur_element
306
- break
307
- else
308
- matched_index = matched_index + 1
309
- end
310
- end
311
- }
312
- return return_element
313
- else
314
- return_element = nil
315
- foundElements.each { |cur_element|
316
- passCheck = find_object_check_object(cur_element, strId, strText)
317
- if passCheck
318
- return_element = cur_element
319
- break
320
- end
321
- }
322
- return return_element
323
- end # if index != nil and index.to_i >= 0
324
- end #if foundElements != nil or foundElements.length != 0
325
- end #if continue = true
326
- end
327
-
328
- return nil
329
- end
330
- #Generate Xpath Selector
331
- def generate_xpath_selector(strId, strClass, strName, strTagname)
332
- strGenerateXpathSel = ""
333
- if strId != nil and strId.length > 0 and (strId =~ /^#/) == nil
334
- strGenerateXpathSel = "[@id='#{strId}']"
335
- end
336
- if strClass != nil and strClass.length > 0 and (strClass =~ /^#/) == nil
337
- strGenerateXpathSel = "#{strGenerateXpathSel}[@class='#{strClass}']"
338
- end
339
- if strName != nil and strName.length > 0 and (strName =~ /^#/) == nil
340
- strGenerateXpathSel = "#{strGenerateXpathSel}[@name='#{strName}']"
341
- end
342
-
343
- if strGenerateXpathSel.length > 0
344
- if strTagname != nil and strTagname.length > 0
345
- strGenerateXpathSel = "//#{strTagname}#{strGenerateXpathSel}"
346
- else
347
- strGenerateXpathSel = "//*#{strGenerateXpathSel}"
348
- end
349
- end
350
-
351
- return strGenerateXpathSel
352
- end
353
-
354
- #Get object by XpathSelector
355
- def get_objects_by_XpathSelector(strXpathSelector)
356
- p "-----strXpathSelector: #{strXpathSelector}"
357
- foundElements = nil
358
- begin
359
- foundElements = page.all(:xpath, strXpathSelector)
360
- rescue StandardError => myStandardError
361
- put_log "\n>>> Error: #{myStandardError}"
362
- end
363
-
364
- return foundElements
365
- end
366
-
367
- #Get object by CSS Selector
368
- def get_objects_by_CssSelector(strCSSSelector)
369
- p "---strCSSSelector---:#{strCSSSelector}"
370
- foundElements = nil
371
- begin
372
- foundElements = page.all(:css, strCSSSelector)
373
- rescue StandardError => myStandardError
374
- put_log "\n>>> Error: #{myStandardError}"
375
- end
376
-
377
- return foundElements
378
- end
379
-
380
- #Find/Check the object by ID and Text
381
- def find_object_check_object cur_element, strId, strText
382
- passCheck = true
383
- if cur_element != nil
384
-
385
- # Check ID
386
- if strId != nil and strId.length > 0
387
- if strId =~ /^#/
388
- strId = strId[1..-1]
389
- end
390
- end
391
-
392
- # Check Text
393
- if passCheck and strText != nil and strText.length > 0
394
- if (strText =~ /^#/)
395
- strText = strText[1..-1]
396
- end
397
- end
398
- return passCheck
399
- end
400
-
401
- return false
402
- end
403
-
404
- # Check object property
405
- def execute_checkproperty element, property, negate, value, isSpecialChar=false
406
- Capybara.configure do |config|
407
- config.ignore_hidden_elements = false
408
- end
409
- foundElement = find_object(element)
410
-
411
- check = false
412
- if foundElement == nil and value == ""
413
- check = true
414
- # check.should eq true
415
- expect(check).to eq true
416
- else
417
- # put_log "\n\n\t>>> execute_checkproperty: finish to found element"
418
- if foundElement != nil
419
- if property.upcase == 'VALUE'
420
- actual_value = foundElement.value()
421
-
422
- elsif property.upcase == 'TEXT'
423
- actual_value = foundElement.text()
424
-
425
- elsif property.upcase == 'SPECIAL CHAR'
426
- actual_value = foundElement.text()
427
- isSpecialChar = true
428
-
429
- elsif property.upcase == 'TAGNAME'
430
- actual_value = foundElement.tag_name()
431
-
432
- elsif property.upcase == 'STYLE'
433
- actual_value = foundElement[:style]
434
-
435
- elsif property.upcase == 'DISABLED'
436
- actual_value = foundElement[:disabled]
437
-
438
- elsif property.upcase == 'WIDTH'
439
- actual_value = foundElement[:width]
440
-
441
- elsif property.upcase == 'HEIGHT'
442
- actual_value = foundElement[:height]
443
-
444
- elsif property.upcase == 'ID'
445
- actual_value = foundElement[:id]
446
-
447
- elsif property.upcase == 'NAME'
448
- actual_value = foundElement[:name]
449
-
450
- elsif property.upcase == 'CLASS'
451
- actual_value = foundElement[:class]
452
-
453
- elsif property.upcase == 'HREF'
454
- actual_value = foundElement[:href]
455
-
456
- elsif property.upcase == 'TITLE'
457
- actual_value = foundElement[:title]
458
-
459
- elsif property.upcase == 'TYPE'
460
- actual_value = foundElement[:type]
461
-
462
- elsif property.upcase == 'CHECKED'
463
- actual_value = "true" if foundElement.checked? == true
464
- actual_value = "false" if foundElement.checked? == false
465
- else
466
- actual_value = foundElement["#{property}"]
467
- end
468
-
469
- if actual_value == nil
470
- actual_value = ''
471
- end
472
- else
473
- put_log "\nError >> Not found object: #{element}"
474
- end
475
-
476
- Capybara.configure do |config|
477
- config.ignore_hidden_elements = true
478
- end
479
-
480
- if Assertion.reg_compare(actual_value,value, isSpecialChar)
481
- check = true
482
- end
483
-
484
- put_log "\n#{property} :: Actual result is: '#{actual_value}' -- Expected result is: '#{value}'"
485
-
486
- if negate == " not"
487
- # check.should_not eq true
488
- # expect(check).not_to eql true
489
- actual_value.should_not eq value
490
- expect(actual_value).not_to eql value
491
- # !Assertion.assert_string_not_equal(actual_value,value)
492
- elsif
493
- actual_value.should eq value
494
- expect(actual_value).to eq value
495
- # Assertion.assert_string_equal(actual_value,value)
496
- end
497
- end
498
- end
499
-
500
- def execute_getproperty element, property
501
- Capybara.configure do |config|
502
- config.ignore_hidden_elements = false
503
- end
504
- foundElement = find_object(element)
505
-
506
- check = false
507
- if foundElement == nil and value == ""
508
- check = true
509
- # check.should eq true
510
- expect(check).to eq true
511
- else
512
- # put_log "\n\n\t>>> execute_getproperty: finish to found element"
513
- if foundElement != nil
514
- if property.upcase == 'VALUE'
515
- actual_value = foundElement.value()
516
-
517
- elsif property.upcase == 'TEXT'
518
- actual_value = foundElement.text()
519
-
520
- elsif property.upcase == 'TAGNAME'
521
- actual_value = foundElement.tag_name()
522
-
523
- elsif property.upcase == 'STYLE'
524
- actual_value = foundElement[:style]
525
-
526
- elsif property.upcase == 'DISABLED'
527
- actual_value = foundElement[:disabled]
528
-
529
- elsif property.upcase == 'WIDTH'
530
- actual_value = foundElement[:width]
531
-
532
- elsif property.upcase == 'HEIGHT'
533
- actual_value = foundElement[:height]
534
-
535
- elsif property.upcase == 'ID'
536
- actual_value = foundElement[:id]
537
-
538
- elsif property.upcase == 'NAME'
539
- actual_value = foundElement[:name]
540
-
541
- elsif property.upcase == 'CLASS'
542
- actual_value = foundElement[:class]
543
-
544
- elsif property.upcase == 'HREF'
545
- actual_value = foundElement[:href]
546
-
547
- elsif property.upcase == 'TITLE'
548
- actual_value = foundElement[:title]
549
-
550
- elsif property.upcase == 'TYPE'
551
- actual_value = foundElement[:type]
552
-
553
- else
554
- actual_value = foundElement["#{property}"]
555
- end
556
-
557
- if actual_value == nil
558
- actual_value = ''
559
- end
560
- else
561
- put_log "\nError >> Not found object: #{element}"
562
- end
563
-
564
- Capybara.configure do |config|
565
- config.ignore_hidden_elements = true
566
- end
567
- actual_value
568
- end
569
- end
570
- # Get text from web element
571
- def execute_gettext element
572
- foundElement = find_object(element)
573
- if foundElement != nil
574
- tagname = foundElement.tag_name()
575
-
576
- if tagname.upcase == 'SELECT'
577
- #@text = page.evaluate_script("$(\"##{foundElement[:id]}\").text()")
578
- else
579
- actual_text = foundElement.text()
580
- if (actual_text == nil or actual_text.length == 0) and (tagname.upcase == 'INPUT' or tagname.upcase == 'TEXTAREA')
581
- actual_text = foundElement.value()
582
- end
583
- end
584
-
585
- put_log "\nText is '" + actual_text + "' of object '" + element + "'"
586
- $context_value = actual_text
587
- else
588
- put_log "\nError >> Not found object: #{element}"
589
- exit
590
- end
591
- end
592
-
593
- def var_collect string_var
594
- if string_var =~ /^.*{year}.*$/
595
- string_var = replace_year(string_var)
596
- end
597
-
598
- if string_var =~ /^.*{month}.*$/
599
- string_var = replace_month(string_var)
600
- end
601
-
602
- if string_var =~ /^.*{day}.*$/
603
- string_var = replace_day(string_var)
604
- end
605
-
606
- if string_var =~ /^.*{store_value}.*$/
607
- string_var = $context_value
608
- end
609
-
610
- return string_var
611
- end
612
-
613
- def replace_year str
614
- t = Time.now()
615
- return str.gsub("{year}", t.year.to_s)
616
- end
617
-
618
- def replace_month str
619
- t = Time.now()
620
- _month = t.month
621
- if _month < 10
622
- return str.gsub("{month}", "0#{_month.to_s}")
623
- else
624
- return str.gsub("{month}", "#{_month.to_s}")
625
- end
626
- return str
627
- end
628
-
629
- def replace_day str
630
- t = Time.now()
631
- _day = t.day
632
- if _day < 10
633
- return str.gsub("{day}", "0#{_day.to_s}")
634
- else
635
- return str.gsub("{day}", "#{_day.to_s}")
636
- end
637
- return str
638
- end
639
-
640
- def replace_pipe str_pipe
641
- put_log ">>>> #{str_pipe}"
642
- if str_pipe =~ /^.*{pipe}.*$/
643
- return str_pipe.gsub("{pipe}", "|")
644
- end
645
- return str_pipe
646
- end