Ifd_Automation 2.9 → 2.9.1

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.
Files changed (34) hide show
  1. checksums.yaml +4 -4
  2. data/lib/Ifd_Automation/REST_steps.rb +33 -33
  3. data/lib/Ifd_Automation/SOAP_steps.rb +31 -31
  4. data/lib/Ifd_Automation/assertion_helper.rb +97 -0
  5. data/lib/Ifd_Automation/auto_util.rb +161 -0
  6. data/lib/Ifd_Automation/database_helper.rb +78 -0
  7. data/lib/Ifd_Automation/database_steps.rb +44 -44
  8. data/lib/Ifd_Automation/dynamic_store_value_steps.rb +18 -18
  9. data/lib/Ifd_Automation/email_steps.rb +31 -31
  10. data/lib/Ifd_Automation/file_helper.rb +33 -0
  11. data/lib/Ifd_Automation/file_steps.rb +9 -9
  12. data/lib/Ifd_Automation/mail_helper.rb +56 -0
  13. data/lib/Ifd_Automation/require_libs.rb +9 -9
  14. data/lib/Ifd_Automation/rest_helper.rb +89 -0
  15. data/lib/Ifd_Automation/soap_helper.rb +57 -0
  16. data/lib/Ifd_Automation/ssh_helper.rb +37 -0
  17. data/lib/Ifd_Automation/ssh_steps.rb +15 -15
  18. data/lib/{helper → Ifd_Automation}/step_fallback.rb +0 -0
  19. data/lib/{helper → Ifd_Automation}/tolerance_for_selenium_sync_issues.rb +0 -0
  20. data/lib/Ifd_Automation/version.rb +1 -1
  21. data/lib/{helper → Ifd_Automation}/web_steps_helper.rb +419 -40
  22. data/project/Gemfile +1 -1
  23. data/project/features/TestSuite/WebGUI.feature +4 -4
  24. data/project/features/step_definitions/lib_steps/steps_definition.rb +4 -2
  25. data/project/features/step_definitions/repositories/project_object.yml +2 -1
  26. metadata +13 -13
  27. data/lib/helper/assertion_helper.rb +0 -100
  28. data/lib/helper/auto_util.rb +0 -164
  29. data/lib/helper/database_helper.rb +0 -81
  30. data/lib/helper/file_helper.rb +0 -36
  31. data/lib/helper/mail_helper.rb +0 -58
  32. data/lib/helper/rest_helper.rb +0 -91
  33. data/lib/helper/soap_helper.rb +0 -59
  34. data/lib/helper/ssh_helper.rb +0 -39
@@ -1,36 +1,36 @@
1
- require 'action_mailer'
2
- # Example:
3
- #
4
- # Then I send an email with:
5
- # """
6
- # From: from@example.com
7
- # Reply-To: reply-to@example.com
8
- # To: anh.pham@infodation.vn
9
- # Subject: SUBJECT
10
- # Attachments: globalData.yml
1
+ # require 'action_mailer'
2
+ # # Example:
3
+ # #
4
+ # # Then I send an email with:
5
+ # # """
6
+ # # From: from@example.com
7
+ # # Reply-To: reply-to@example.com
8
+ # # To: anh.pham@infodation.vn
9
+ # # Subject: SUBJECT
10
+ # # Attachments: globalData.yml
11
11
 
12
- # BODY
13
- # """
14
- #
15
- Then /^I send an e?mail with:$/ do |raw_data|
16
- IFD_Email.send_email(raw_data)
17
- end
12
+ # # BODY
13
+ # # """
14
+ # #
15
+ # Then /^I send an e?mail with:$/ do |raw_data|
16
+ # IFD_Email.send_email(raw_data)
17
+ # end
18
18
 
19
- # Example:
20
- #
21
- # Then I should receive an email with:
22
- # """
23
- # From: from@example.com
24
- # Reply-To: reply-to@example.com
25
- # To: anh.pham@infodation.vn
26
- # Subject: SUBJECT
27
- # Attachments: globalData.yml
19
+ # # Example:
20
+ # #
21
+ # # Then I should receive an email with:
22
+ # # """
23
+ # # From: from@example.com
24
+ # # Reply-To: reply-to@example.com
25
+ # # To: anh.pham@infodation.vn
26
+ # # Subject: SUBJECT
27
+ # # Attachments: globalData.yml
28
28
 
29
- # BODY
30
- # """
31
- #
29
+ # # BODY
30
+ # # """
31
+ # #
32
32
 
33
- Then /^I should receive an e?mail with:$/ do |raw_data|
34
- IFD_Email.verify_receive_email(raw_data)
35
- end
33
+ # Then /^I should receive an e?mail with:$/ do |raw_data|
34
+ # IFD_Email.verify_receive_email(raw_data)
35
+ # end
36
36
 
@@ -0,0 +1,33 @@
1
+
2
+ def delete_file(file_name)
3
+ file_path = ($test_data_dir + file_name.gsub(" ", "_"))
4
+ if File.exists?(file_path)
5
+ File.delete(file_path)
6
+ puts "#{file_name} is deleted successfully"
7
+ else
8
+ puts "File #{file_name} does not exists"
9
+ end
10
+ end
11
+
12
+ def read_file(file_name)
13
+ @file_data = ""
14
+ file_path = $test_data_dir + file_name.downcase
15
+ if File.exist?(file_path)
16
+ file = File.open(file_path)
17
+ @file_data += file.read
18
+ file.close
19
+ else
20
+ raise "*** WARNING: File #{file_name} does not exist."
21
+ end
22
+ p @file_data
23
+ end
24
+
25
+ def execute_windows_file(filename, file_location)
26
+ file = file_location + filename
27
+ p file
28
+ if File.exist? file
29
+ system("'"+file+"'")
30
+ else
31
+ raise "*** ERROR: File #{file} is not existed."
32
+ end
33
+ end
@@ -1,11 +1,11 @@
1
- Then /^I delete test file "(.*)"$/ do |file_name|
2
- IFD_File.delete_file(file_name)
3
- end
1
+ # Then /^I delete test file "(.*)"$/ do |file_name|
2
+ # IFD_File.delete_file(file_name)
3
+ # end
4
4
 
5
- Given /^I read data from file "(.*)"$/ do |file_name|
6
- IFD_File.read_file(file_name)
7
- end
5
+ # Given /^I read data from file "(.*)"$/ do |file_name|
6
+ # IFD_File.read_file(file_name)
7
+ # end
8
8
 
9
- Given /I execute file "(.*)" from windows server "(.*)"/ do |filename, file_location|
10
- IFD_File.execute_windows_file(filename, file_location)
11
- end
9
+ # Given /I execute file "(.*)" from windows server "(.*)"/ do |filename, file_location|
10
+ # IFD_File.execute_windows_file(filename, file_location)
11
+ # end
@@ -0,0 +1,56 @@
1
+ require 'mail'
2
+ # require 'email_spec'
3
+ # include EmailSpec::Helpers
4
+ # include EmailSpec::Matcher
5
+
6
+ def send_email(raw_data)
7
+ include Mail::Matchers
8
+ raw_data.strip!
9
+ header, body = raw_data.split(/\n\n/, 2) # 2: maximum number of fields
10
+ conditions = {}
11
+ header.split("\n").each do |row|
12
+ if row.lstrip.chop.match(/^[a-z\-]+:/i)
13
+ key, value = row.split(":", 2)
14
+ conditions[key.gsub(' ','').underscore.to_sym] = value.gsub(' ','')
15
+
16
+ end
17
+ end
18
+ conditions[:body] = body if body
19
+ filepath = ($test_data_dir + conditions[:attachments] if conditions[:attachments])
20
+ # Mail::TestMailer.deliveries.clear
21
+ Mail.deliver do
22
+ from "abc@gmail.com"
23
+ to to_address if conditions[:to]
24
+ subject subject if conditions[:subject]
25
+ body body_email if conditions[:body]
26
+ add_file attachments if filepath
27
+ end
28
+ end
29
+
30
+ def verify_receive_email(raw_data)
31
+ raw_data.strip!
32
+ header, body = raw_data.split(/\n\n/, 2) # 2: maximum number of fields
33
+ conditions = {}
34
+ header.split("\n").each do |row|
35
+ if row.lstrip.chop.match(/^[a-z\-]+:/i)
36
+ key, value = row.split(":", 2)
37
+ conditions[key.gsub(' ','').underscore.to_sym] = value.gsub(' ','')
38
+
39
+ end
40
+ end
41
+ conditions[:body] = body.squeeze(' ').strip if body
42
+ sleep 5
43
+ emails = Mail.find(:what => :last, :count => 1)
44
+
45
+ if emails.instance_of? Mail::Message
46
+ assert_string_equal(conditions[:from], emails.from[0].to_s)
47
+ assert_string_equal(conditions[:subject], emails.subject)
48
+ assert_string_contain(conditions[:body], emails.body)
49
+ emails.attachments.each do |attachment|
50
+ assert_string_equal(conditions[:attachments], attachment.filename)
51
+ end if conditions[:attachments]
52
+ else
53
+ raise "WARNING: *** No new Email is found"
54
+ end
55
+ end
56
+
@@ -1,9 +1,9 @@
1
- require_relative '../helper/web_steps_helper.rb'
2
- require_relative '../helper/auto_util.rb'
3
- require_relative '../helper/mail_helper.rb'
4
- require_relative '../helper/assertion_helper.rb'
5
- require_relative '../helper/database_helper.rb'
6
- require_relative '../helper/file_helper.rb'
7
- require_relative '../helper/rest_helper.rb'
8
- require_relative '../helper/soap_helper.rb'
9
- require_relative '../helper/ssh_helper.rb'
1
+ # require_relative '../helper/web_steps_helper.rb'
2
+ # require_relative '../helper/auto_util.rb'
3
+ # require_relative '../helper/mail_helper.rb'
4
+ # require_relative '../helper/assertion_helper.rb'
5
+ # require_relative '../helper/database_helper.rb'
6
+ # require_relative '../helper/file_helper.rb'
7
+ # require_relative '../helper/rest_helper.rb'
8
+ # require_relative '../helper/soap_helper.rb'
9
+ # require_relative '../helper/ssh_helper.rb'
@@ -0,0 +1,89 @@
1
+ require 'httparty'
2
+ def set_headers(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
+ @header = data
11
+ end
12
+ p "HEADER: #{@header}"
13
+ end
14
+
15
+ def get_rest_result
16
+ if @response.nil?
17
+ p "WARNING***: MISSING STEPS: Please send a REST request to get response first."
18
+ end
19
+ @response
20
+ end
21
+
22
+ def store_json_node_result(json_node,string)
23
+ $context_value = JsonPath.new(json_node).on(get_rest_result.body).to_a.map(&:to_s)[0]
24
+ set_var(string, '$context_value')
25
+ end
26
+
27
+ def print_rest_code
28
+ puts "REST RESULT code: #{get_rest_result.code}"
29
+ end
30
+
31
+ def get_rest_body
32
+ puts "REST RESULT body: #{get_rest_result.body}"
33
+ end
34
+
35
+ def verify_rest_response_code(code)
36
+ assert_string_equal(code, get_rest_result.code.to_s)
37
+ end
38
+
39
+ def verify_response_body_with_json(json)
40
+ assert_string_equal(json, get_rest_result.body.to_s)
41
+ end
42
+
43
+ def verify_response_at_json_node(json_node,string)
44
+ result = JsonPath.new(json_node).on(get_rest_result.body).to_a.map(&:to_s)
45
+ assert_string_equal(string, result[0])
46
+ end
47
+
48
+ def send_request(*args)
49
+ request_type = args.shift.downcase
50
+ url = check_dynamic_value(args.shift)
51
+ put_log "Request URL: #{url}"
52
+ json_payload = args.shift
53
+ if json_payload
54
+ payload = Hash.new
55
+ JSON.parse(json_payload).each do |k1, v1|
56
+ payload[check_dynamic_value(k1)] = check_dynamic_value(v1)
57
+ end
58
+ payload = payload.to_json
59
+ end
60
+ put_log "Data Body from #{request_type} method: #{payload}"
61
+
62
+ if (payload.nil? && request_type == 'get' && @header.nil?)
63
+ @response = Request.get(url)
64
+ elsif (payload.nil? && request_type == 'get')
65
+ @response = Request.get(url, {headers: @header})
66
+ elsif (payload.nil? && request_type == 'delete' && @header.nil?)
67
+ @response = Request.delete(url)
68
+ elsif (payload.nil? && request_type == 'delete')
69
+ @response = Request.delete(url, {headers: @header})
70
+ elsif (payload && request_type == 'get' && @header.nil?)
71
+ @response = Request.get(url, {body: payload})
72
+ elsif (payload && request_type == 'get')
73
+ @response = Request.get(url, {body: payload, headers: @header})
74
+ elsif (payload && request_type == 'post' && @header.nil?)
75
+ @response = Request.post(url, {body: payload})
76
+ elsif (payload && request_type == 'post')
77
+ @response = Request.post(url, {body: payload, headers: @header})
78
+ elsif (payload && request_type == 'put' && @header.nil?)
79
+ @response = Request.put(url, {body: payload})
80
+ elsif (payload && request_type == 'put')
81
+ @response = Request.put(url, {body: payload, headers: @header})
82
+ end
83
+ end
84
+
85
+
86
+ class Request
87
+ include HTTParty
88
+ default_options.update(verify: false)
89
+ end
@@ -0,0 +1,57 @@
1
+ require 'savon'
2
+ require 'jsonpath'
3
+
4
+ def get_soap_operation_list(url)
5
+ request_url = URI.encode check_dynamic_value url
6
+ @SOAPclient = Savon.client(ssl_verify_mode: :none,
7
+ wsdl: "#{request_url}",
8
+ :open_timeout => 10,
9
+ :read_timeout => 10,
10
+ :log => false)
11
+ p "Operations List: #{@SOAPclient.operations}"
12
+ end
13
+
14
+ def call_and_fail_gracefully(client, *args, &block)
15
+ if client.nil?
16
+ raise "ERROR***: MISSING STEPS: Please run step to get operation list from WSDL first."
17
+ else
18
+ client.call(*args, &block)
19
+ end
20
+ rescue Savon::SOAPFault => e
21
+ raise e.message
22
+ end
23
+
24
+ def get_soap_response
25
+ soap_response = @response
26
+ if soap_response.nil?
27
+ raise "ERROR***: MISSING STEPS: Please send SOAP request to get the response first."
28
+ else
29
+ soap_response
30
+ end
31
+ soap_response
32
+ end
33
+
34
+ def send_soap_with_operation_and_xml(operation,file_name)
35
+ xml = File.read($test_data_dir + file_name)
36
+ @response = call_and_fail_gracefully(@SOAPclient, operation.downcase.to_sym, xml: xml )
37
+ end
38
+
39
+ def send_soap_with_operation_and_data(operation,data)
40
+ xml = bind_with_dyn_vars(data)
41
+ @response = call_and_fail_gracefully(@SOAPclient, operation.downcase.to_sym, xml: xml )
42
+ end
43
+
44
+ def verify_response_with_json_node(json_node,string)
45
+ json = get_soap_response.body.to_json
46
+ results = JsonPath.new(json_node).on(json).to_a.map(&:to_s)
47
+ assert_string_equal(string, results[0])
48
+ end
49
+
50
+ def verify_response_code(status_code)
51
+ assert_string_equal(get_soap_response.http.code, status_code.to_i)
52
+ end
53
+
54
+ def print_response
55
+ p "SOAP RESPONSE: #{get_soap_response}"
56
+ end
57
+
@@ -0,0 +1,37 @@
1
+ require 'net/ssh'
2
+
3
+ def connect_to_server_with_credential(host_name,table)
4
+ hostname = check_dynamic_value host_name
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
+ def exec_command(command)
21
+ command = check_dynamic_value command
22
+ @output = @SSHconnection.exec!(command)
23
+ end
24
+
25
+ def print_output
26
+ p @output
27
+ end
28
+
29
+ def verify_output(string)
30
+ string = check_dynamic_value(string)
31
+ assert_string_equal(string, @output.strip)
32
+ end
33
+
34
+ def store_result_string(name)
35
+ $context_value = bind_with_dyn_vars(@output)
36
+ set_var(name, '$context_value')
37
+ end
@@ -1,20 +1,20 @@
1
- When /^I SSH to "([^\"]*)" with the following credentials:$/ do |hostname, table|
2
- IFD_Ssh.connect_to_server_with_credential(hostname, table)
3
- end
1
+ # When /^I SSH to "([^\"]*)" with the following credentials:$/ do |hostname, table|
2
+ # IFD_Ssh.connect_to_server_with_credential(hostname, table)
3
+ # end
4
4
 
5
- When /^I run SSH command "([^\"]*)"$/ do |command|
6
- IFD_Ssh.exec_command(command)
7
- end
5
+ # When /^I run SSH command "([^\"]*)"$/ do |command|
6
+ # IFD_Ssh.exec_command(command)
7
+ # end
8
8
 
9
9
 
10
- Then /^show me the SSH output result$/ do
11
- IFD_Ssh.print_output
12
- end
10
+ # Then /^show me the SSH output result$/ do
11
+ # IFD_Ssh.print_output
12
+ # end
13
13
 
14
- Then /^I should see "([^\"]*)" in the SSH output$/ do |string|
15
- IFD_Ssh.verify_output(string)
16
- end
14
+ # Then /^I should see "([^\"]*)" in the SSH output$/ do |string|
15
+ # IFD_Ssh.verify_output(string)
16
+ # end
17
17
 
18
- When /^I store the result of SSH as "(.*?)"$/ do |var_name|
19
- IFD_Ssh.store_result_string(var_name)
20
- end
18
+ # When /^I store the result of SSH as "(.*?)"$/ do |var_name|
19
+ # IFD_Ssh.store_result_string(var_name)
20
+ # end
File without changes
@@ -1,3 +1,3 @@
1
1
  module IfdAutomation
2
- VERSION = "2.9"
2
+ VERSION = "2.9.1"
3
3
  end