Ifd_Automation 2.2 → 2.3

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
  SHA1:
3
- metadata.gz: 217a54f881fc45b75ceb8b53bdb16ad36f5b9c68
4
- data.tar.gz: e31a760f2a7368b58615f6eade99c7aa36831e19
3
+ metadata.gz: 53904b49fcb6b5c053dea1040b8aa2c48e110be7
4
+ data.tar.gz: cc7f0b2f3a1f8dec98bab1dcdf9b40bcd998de3a
5
5
  SHA512:
6
- metadata.gz: a87e826fe4ca543164f6ca7f518766165602763701dc1364c9563e3280f30ba17dc389ce2468ea37b81e928bff483a1585b2d5cdaa0e20726373cb3f4210fcb8
7
- data.tar.gz: e50cbcf7b604cf43065c0c0ed673ec2121b7c0dc078edc1e38f3af81d0ba317542c2a27711269d9fdbe53a9a77d6b1ea4fdd659724643f794916a8d6c7421c2d
6
+ metadata.gz: 417b97c43287525ac30ef2ac0bf2da2161cd9d62452ebbc62fe38a292754f00a89e121f21b8a40f3ed90b94ab345e63d67689394b39555e88d8b8671cefb532e
7
+ data.tar.gz: d5144b28aa8e82422525dc49092ed265582d47cf129842aede166a68f1a46f1603d7b758c1559768cb7b561def11773ab5aea86a4a154cf7fc1e261454a573e3
@@ -1,105 +1,90 @@
1
1
  require_relative 'require_libs'
2
2
  require 'httparty'
3
- When /^I send a REST GET request to "([^\"]*)"$/ do |url|
4
- url = check_dynamic_value(url)
5
- puts "\n REST url: #{url}"
6
- $RESTresult = HTTParty.get url, timeout: 180_000
7
- end
8
-
9
- When /^I send a REST POST request to "([^"]*)"$/ do |url|
10
- url = check_dynamic_value(url)
11
- puts "\n url: #{url}"
12
- $RESTresult = HTTParty.post url, timeout: 180_000
13
- end
14
-
15
- When /^I send a REST POST request to "(.*?)" with file "(.*?)"$/ do |url, file|
16
- url = check_dynamic_value(url)
17
- file = bind_with_dyn_vars(file)
18
- puts "\n POST url: #{url}"
19
- data = File.read($test_data_dir + file)
20
- $RESTresult = HTTParty.post url, {:body => data, :timeout => 180000}
21
- # puts $result.response.body.to_s
22
- end
3
+ require 'jsonpath'
23
4
 
24
- When /^I send a REST PUT request to "([^\"]*)"$/ do |url|
25
- url = check_dynamic_value(url)
26
- puts "\n PUT url: #{url}"
27
- $RESTresult = HTTParty.put url, timeout: 180_000
28
- # puts $result.response.body.to_s
29
- end
30
-
31
- When /^I send a REST PUT request to "(.*?)" with file "(.*?)"$/ do |url, file|
32
- url = check_dynamic_value(url)
33
- file = bind_with_dyn_vars(file)
34
- puts "\n url: #{url}"
35
- data = File.read($test_data_dir + file)
36
- $RESTresult = HTTParty.put url, body: data, timeout: 180_000
37
- # puts $result.response.body.to_s
38
- end
5
+ Given /^I set headers:$/ do |data|
6
+ unless data.hashes.empty?
7
+ data = data.hashes[0]
8
+ data = JSON.parse(data) unless data.is_a? Hash
39
9
 
40
- When /^I print the result of REST request$/ do
41
- puts "\n PUT Rest result: #{$RESTresult}"
10
+ data.each_pair do |k, v|
11
+ data[k] = check_dynamic_value(v)
12
+ end
13
+ @header = data
14
+ end
15
+ p "HEADER: #{@header}"
42
16
  end
43
17
 
44
- # """
45
- # {
46
- # "test" : "anh pham"
47
- # }
48
- # """
49
- When /^I send a REST PUT request to "(.*?)" with json:$/ do |url, data|
50
- url = check_dynamic_value(url)
51
- data = data.raw[0][0]
52
- data = JSON.parse(data) unless data.is_a? Hash
53
-
54
- data.each_pair do |k, v|
55
- data[k] = bind_with_dyn_vars(v)
18
+ When /^I send a REST (GET|PUT|POST|DELETE) request (?:for|to) "([^"]*)"(?: with the following:)?$/ do |*args|
19
+ request_type = args.shift.downcase
20
+ url = check_dynamic_value(args.shift)
21
+ put_log "Request URL: #{url}"
22
+ json_payload = args.shift
23
+ if json_payload
24
+ payload = Hash.new
25
+ JSON.parse(json_payload).each do |k1, v1|
26
+ payload[check_dynamic_value(k1)] = check_dynamic_value(v1)
27
+ end
28
+ payload = payload.to_json
56
29
  end
30
+ put_log "Data Body from #{request_type} method: #{payload}"
57
31
 
58
- $RESTresult = HTTParty.put url, body: data, timeout: 180_000
32
+ if (payload.nil? && request_type == 'get' && @header.nil?)
33
+ @response = Request.get(url)
34
+ elsif (payload.nil? && request_type == 'get')
35
+ @response = Request.get(url, {headers: @header})
36
+ elsif (payload.nil? && request_type == 'delete' && @header.nil?)
37
+ @response = Request.delete(url)
38
+ elsif (payload.nil? && request_type == 'delete')
39
+ @response = Request.delete(url, {headers: @header})
40
+ elsif (payload && request_type == 'get' && @header.nil?)
41
+ @response = Request.get(url, {body: payload})
42
+ elsif (payload && request_type == 'get')
43
+ @response = Request.get(url, {body: payload, headers: @header})
44
+ elsif (payload && request_type == 'post' && @header.nil?)
45
+ @response = Request.get(url, {body: payload})
46
+ elsif (payload && request_type == 'post')
47
+ @response = Request.post(url, {body: payload, headers: @header})
48
+ elsif (payload && request_type == 'put' && @header.nil?)
49
+ @response = Request.put(url, {body: payload})
50
+ elsif (payload && request_type == 'put')
51
+ @response = Request.put(url, {body: payload, headers: @header})
52
+ end
59
53
  end
60
54
 
61
- When /^I send a REST DELETE request to "([^\"]*)"$/ do |url|
62
- url = check_dynamic_value(url)
63
- # puts "\n\nurl: #{url}"
64
- $RESTresult = HTTParty.delete url, timeout: 180_000
65
- # puts $result.response.body.to_s
55
+ Then /^I store the REST result at node "(.*)" as "(.*)"$/ do |json_path, var_name|
56
+ $context_value = JsonPath.new(json_path).on(@response.body).to_a.map(&:to_s)[0]
57
+ set_var(var_name, '$context_value')
66
58
  end
67
59
 
68
- Then /^I should see the REST error message "([^"]*)"$/ do |message|
69
- $RESTresult.response.body.to_s.should include message
60
+ When /^I print the result of REST request$/ do
61
+ puts "REST RESULT code: #{getRestResult.code}"
62
+ puts "REST RESULT body: #{getRestResult.body}"
70
63
  end
71
64
 
72
65
  Then /^I should see REST response code "([^"]*)"$/ do |code|
73
- $RESTresult.code.to_s.should == code
66
+ Assertion.assert_string_equal(code, getRestResult.code.to_s)
74
67
  end
75
68
 
76
- # Example
77
- # Then the JSON response should be:
78
- # """
79
- # {
80
- # "test" : "anh pham"
81
- # }
82
- # """
83
69
  Then /^the JSON response should be:$/ do |json|
84
- expected = JSON.parse(json)
85
- actual = JSON.parse($RESTresult.body.to_s)
70
+ Assertion.assert_string_equal(json, getRestResult.body.to_s)
71
+ end
86
72
 
87
- if self.respond_to?(:expect)
88
- # expect(actual).to eq(expected)
89
- Assertion.assert_string_equal(actual, expected)
90
- else
91
- Assertion.assert_string_contain(actual, expected)
92
- # assert_equal actual, response
93
- end
73
+ # Example
74
+ # Then the JSON response at node "$..id" should have "1"
75
+ Then /^the JSON response at node "(.*)" should have "(.*)"$/ do |json_path, expected|
76
+ result = JsonPath.new(json_path).on(getRestResult.body).to_a.map(&:to_s)
77
+ Assertion.assert_string_equal(expected, result[0])
94
78
  end
95
79
 
80
+ class Request
81
+ include HTTParty
82
+ default_options.update(verify: false)
83
+ end
96
84
 
97
- # Example
98
- # Then the JSON response should have "$..id"
99
- Then /^the JSON response should have "(.*)"$/ do |json_path|
100
- json = JSON.parse($RESTresult.body)
101
- results = JsonPath.new(json_path).on(json).to_a.map(&:to_s)
102
- if self.respond_to?(:expect)
103
- expect(results).not_to be_empty
85
+ def getRestResult
86
+ if @response.nil?
87
+ p "WARNING***: MISSING STEPS: Please send a REST request to get response first."
104
88
  end
89
+ @response
105
90
  end
@@ -31,24 +31,38 @@ When /^I send SOAP request with operation name "(.*)" and following data:$/ do |
31
31
  end
32
32
 
33
33
  Then /^the status code should be "(.*)"$/ do |status|
34
- Assertion.assert_string_equal(@response.http.code, status.to_i)
34
+ Assertion.assert_string_equal(get_soap_response.http.code, status.to_i)
35
35
  end
36
36
 
37
37
 
38
38
  # Example
39
39
  # Then the SOAP response node should have "$..response_text" with text "Email Domain Not Found"
40
40
  Then /^the SOAP response node should have "(.*?)" with text "(.*?)"$/ do |json_path, text|
41
- json = @response.body.to_json
41
+ json = get_soap_response.body.to_json
42
42
  results = JsonPath.new(json_path).on(json).to_a.map(&:to_s)
43
43
  Assertion.assert_string_equal(text, results[0])
44
44
  end
45
45
 
46
46
  Then /^I print the SOAP response$/ do
47
- p "SOAP RESPONSE: #{@response}"
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
48
58
  end
49
59
 
50
60
  def call_and_fail_gracefully(client, *args, &block)
51
- client.call(*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
52
66
  rescue Savon::SOAPFault => e
53
67
  puts e.message
54
68
  end
@@ -13,7 +13,7 @@ When /^I store string "(.*?)" as "(.*?)"$/ do |str, var_name|
13
13
  end
14
14
 
15
15
  Given /^I print the value of "(.*)"$/ do |temp|
16
- puts eval_with_dyn_vars(temp)
16
+ puts "VALUE OF #{temp}: #{eval_with_dyn_vars(temp)}"
17
17
  end
18
18
 
19
19
  # get text for object
@@ -1,3 +1,3 @@
1
1
  module IfdAutomation
2
- VERSION = "2.2"
2
+ VERSION = "2.3"
3
3
  end
@@ -1,8 +1,12 @@
1
1
  def check_dynamic_value value
2
- if value.include? "params="
3
- resolve_params value
2
+ if !value.is_a? Fixnum
3
+ if value.include? "params="
4
+ resolve_params value
5
+ else
6
+ bind_with_dyn_vars value
7
+ end
4
8
  else
5
- bind_with_dyn_vars value
9
+ value
6
10
  end
7
11
  end
8
12
 
@@ -23,7 +27,7 @@ end
23
27
 
24
28
  #Print script log to console
25
29
  def put_log str
26
- puts str if $_CFWEB['Print Log'] == true
30
+ p str if $_CFWEB['Print Log'] == true
27
31
  end
28
32
 
29
33
 
@@ -1,7 +1,7 @@
1
1
  Given "I login to the page {string} with username {string} and password {string}" do |string, string2, string3|
2
2
  steps %Q{
3
- Given I am on the "#{string}" page
4
- When I click on "header.button_cookie"
3
+ * I am on the "#{string}" page
4
+ * I click on "header.button_cookie"
5
5
  * I click on "header.button_login"
6
6
  * I set text on "login.textbox_username" with "#{string2}"
7
7
  * I set text on "login.textbox_password" with "#{string3}"
@@ -12,8 +12,11 @@ require 'capybara/cucumber'
12
12
  require 'cucumber'
13
13
  require 'yaml'
14
14
  require 'selenium-webdriver'
15
- require 'Ifd_Automation'
15
+ # require 'Ifd_Automation'
16
16
 
17
+ require File.expand_path('../lib/Ifd_Automation/REST_steps.rb')
18
+ require File.expand_path('../lib/Ifd_Automation/dynamic_store_vavue_steps.rb')
19
+ require File.expand_path('../lib/Ifd_Automation/web_steps.rb')
17
20
 
18
21
  if ENV["browser"].nil?
19
22
  raise "ERROR***: MISSING BROWSER... Supported Browsers: Chrome/Firefox."
@@ -34,19 +34,19 @@ Before do
34
34
  end
35
35
  end
36
36
 
37
- After do |scenario|
38
- file_name = 'failed_%s.png' % rand(1000).to_s
39
- page.save_screenshot($screenshot+file_name) if scenario.failed?
40
- begin
41
- Capybara.page.driver.quit
42
- Capybara.send(:session_pool).delete_if { |key, value| key =~ /selenium/i }
43
- rescue StandardError => myStandardError
44
- put_log "\n>>> Error: #{myStandardError}"
45
- end
46
- end
47
-
48
- at_exit do
49
- end
37
+ # After do |scenario|
38
+ # file_name = 'failed_%s.png' % rand(1000).to_s
39
+ # page.save_screenshot($screenshot+file_name) if scenario.failed?
40
+ # begin
41
+ # Capybara.page.driver.quit
42
+ # Capybara.send(:session_pool).delete_if { |key, value| key =~ /selenium/i }
43
+ # rescue StandardError => myStandardError
44
+ # put_log "\n>>> Error: #{myStandardError}"
45
+ # end
46
+ # end
47
+ #
48
+ # at_exit do
49
+ # end
50
50
 
51
51
  AfterConfiguration do |config|
52
52
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: Ifd_Automation
3
3
  version: !ruby/object:Gem::Version
4
- version: '2.2'
4
+ version: '2.3'
5
5
  platform: ruby
6
6
  authors:
7
7
  - Anh Pham
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-12-28 00:00:00.000000000 Z
11
+ date: 2018-01-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: selenium-webdriver