itms_automation 1.0 → 1.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f5369eaf7be36672e2fccdf1ba400a8cb807b4a09c043c741b04d16fdec9c4a5
4
- data.tar.gz: 0f16ce745b0b433fe0171510da26d56a199cd867b03bd55fa2d824e5223a958d
3
+ metadata.gz: 2481f496f80a331329c1a1929a81b9020e439c115b13361aa1bdb0028c13bbe5
4
+ data.tar.gz: 6e4e510b6601947670f59cf5ccfb88dae5e5e6f6aa6bf45dcc71e146ea27c039
5
5
  SHA512:
6
- metadata.gz: 752628884608cdff4e59ad467be586f28d6b1f29d6fb867c9cd5cff444362c7666cc15b309382a1e4f517f311674c6b8b60c4d66f52025ad4214b47d2530ba72
7
- data.tar.gz: cbe8237a0a30a988671aa44f44b780178286c70559294ee2922a0d9d9e7a3724ab24f9549ae490f22cafff036157aa70c18247aa9577448445f820ac82ca6cdd
6
+ metadata.gz: 0a8428f49bf58f222861f188227fe0a70f77d348c401f437054e9a5d6b1229cc666869f7896cb4da7f25cbf749b78e2dffcd66ad8ffc096b679fce30e783644c
7
+ data.tar.gz: 1b7963dd421b3dec632ab47726709eaa22199e74e119ecd67e8fd168148805ff93bd5c416b75bb3610a031235d53107b8762304cf860aae5aa0c0b08f53cb04f
@@ -0,0 +1,29 @@
1
+ def do_assertion_json expected_obj, actual_obj
2
+ if expected_obj.kind_of? Array
3
+ is_contain = true
4
+ expected_obj.each_with_index do |expected, index|
5
+ is_contain = do_assertion_json(expected, actual_obj)
6
+ @expected.shift if is_contain == true
7
+ return is_contain if is_contain == false || index == expected_obj.length - 1
8
+ end
9
+ elsif expected_obj.kind_of? Hash
10
+ is_contain = true
11
+ expected_obj_keys = expected_obj.keys
12
+ expected_obj_keys.each_with_index do |key, index|
13
+ if actual_obj[key].nil?
14
+ raise "[%s] expected [%s] but actual value was nil." % [key, expected_obj[key].to_s]
15
+ else
16
+ is_contain = expected_obj[key] == actual_obj[key]
17
+ return is_contain if is_contain == false || index == expected_obj_keys.length - 1
18
+ end
19
+ end
20
+ elsif [Integer, String, Float].include? expected_obj.class
21
+ return assert_string_equal(expected_obj, actual_obj)
22
+ else
23
+ raise "Verify sql result error: Not support expected type #{expected_obj.class} yet"
24
+ end
25
+ end
26
+
27
+ def assert_string_equal expected, actual
28
+ actual.to_s == expected.to_s
29
+ end
@@ -0,0 +1,83 @@
1
+ require 'active_record'
2
+
3
+ def create_database_connection config
4
+ begin
5
+ if config.class === "String"
6
+ config = JSON.parse config
7
+ else
8
+ unless config.hashes.empty?
9
+ config = config.hashes[0]
10
+ config = JSON.parse(config) unless config.is_a? Hash
11
+ config.each_pair do |k, v|
12
+ config[k] = v
13
+ end
14
+ end
15
+ end
16
+
17
+ @connection = ActiveRecord::Base.establish_connection(config)
18
+ ActiveRecord::Base.connection.active?
19
+
20
+ if !@connection.connected?
21
+ raise "Error: Can't connect to database"
22
+ end
23
+ rescue Exception => e
24
+ raise "Create database connection error: #{e.message}"
25
+ end
26
+ end
27
+
28
+ def close_database_connection
29
+ begin
30
+ @connection.disconnect!
31
+ rescue Exception => e
32
+ raise "Close database connection error: #{e.message}"
33
+ end
34
+ end
35
+
36
+ def execute_query query
37
+ begin
38
+ if @connection.connected?
39
+ @result = @connection.connection.exec_query(query).to_a
40
+ else
41
+ raise "Error: Create connection to database first!"
42
+ end
43
+ rescue Exception => e
44
+ raise "Execute query error: #{e.message}"
45
+ end
46
+ end
47
+
48
+ def print_sql_result
49
+ if @result.present?
50
+ p "SQL result:"
51
+ p @result.to_json
52
+ else
53
+ p "WARNING: No result from SQL statement"
54
+ end
55
+ end
56
+
57
+ def verify_sql_result_contain expected_string
58
+ @expected = JSON.parse(expected_string)
59
+ is_contain = false
60
+ if @expected.kind_of?(Array) && @expected.length > @result.length
61
+ raise "Expected: #{@expected}\nGot: #{@result}\nQuery result not includes your expected"
62
+ end
63
+ @result.each do |row|
64
+ is_contain = do_assertion_json(@expected, row)
65
+ break if !@expected.kind_of?(Array) && is_contain == true
66
+ end
67
+ unless is_contain
68
+ raise "Expected: #{@expected}\nGot: #{@result}\nQuery result not includes your expected"
69
+ end
70
+ end
71
+
72
+ def verify_sql_result_equal expected_string
73
+ @expected = JSON.parse(expected_string)
74
+ if !@expected.kind_of?(Array) || @expected.length != @result.length
75
+ raise "Expected: #{@expected}\nGot: #{@result}\nQuery result not equal with your expected"
76
+ end
77
+ @result.each_with_index do |row, index|
78
+ is_contain = row.to_s == @expected[index].to_s
79
+ unless is_contain
80
+ raise "Expected: #{@expected}\nGot: #{@result}\nQuery result not equal with your expected"
81
+ end
82
+ end
83
+ end
@@ -1,3 +1,3 @@
1
1
  module ItmsAutomation
2
- VERSION = "1.0"
2
+ VERSION = "1.1"
3
3
  end
@@ -8,7 +8,7 @@ def execute_openbrowser(url_site)
8
8
  end
9
9
  visit(url_site)
10
10
  rescue StandardError => e
11
- raise "❌ Error: #{e}"
11
+ raise "❌ Error: #{e.message}"
12
12
  end
13
13
  end
14
14
 
@@ -18,7 +18,7 @@ def execute_click(element)
18
18
  begin
19
19
  foundElement.click
20
20
  rescue StandardError => e
21
- raise "❌ Error: #{e}"
21
+ raise "❌ Error: #{e.message}"
22
22
  end
23
23
  else
24
24
  raise "❌ Error >> Not found object: #{element}"
@@ -32,7 +32,7 @@ def execute_click_offset(element, x, y)
32
32
  page.driver.browser.mouse.move_to(foundElement.native,x.to_i,y.to_i)
33
33
  page.driver.browser.mouse.click()
34
34
  rescue Exception => e
35
- raise "❌ Error: #{e}"
35
+ raise "❌ Error: #{e.message}"
36
36
  end
37
37
  else
38
38
  raise "❌ Error: Not found object: #{element}"
@@ -244,14 +244,22 @@ def resize_window_screen(x, y)
244
244
  end
245
245
  end
246
246
 
247
- def switch_to_frame(element)
247
+ def switch_to_iframe(element)
248
+ foundElement = find_object(element)
248
249
  begin
249
- page.driver.browser.switch_to.frame element
250
+ page.driver.browser.switch_to.frame(foundElement)
251
+ rescue Exception => e
252
+ raise "❌ Error: #{e}"
253
+ end
254
+ end
255
+ def switch_out_frame
256
+ begin
257
+ browser = page.driver.browser
258
+ browser.switch_to.default_content
250
259
  rescue Exception => e
251
260
  raise "❌ Error: #{e}"
252
261
  end
253
262
  end
254
-
255
263
  def get_computed_style(element, style)
256
264
  foundElement = get_object_value(element)
257
265
  computedStyle = ""
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: itms_automation
3
3
  version: !ruby/object:Gem::Version
4
- version: '1.0'
4
+ version: '1.1'
5
5
  platform: ruby
6
6
  authors:
7
7
  - Anh Pham
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-11-05 00:00:00.000000000 Z
11
+ date: 2019-12-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: selenium-webdriver
@@ -149,7 +149,9 @@ files:
149
149
  - bin/setup
150
150
  - lib/itms_automation.rb
151
151
  - lib/itms_automation/all_steps.rb
152
+ - lib/itms_automation/assertion_helper.rb
152
153
  - lib/itms_automation/auto_util.rb
154
+ - lib/itms_automation/database_steps_helper.rb
153
155
  - lib/itms_automation/version.rb
154
156
  - lib/itms_automation/web_steps_helper.rb
155
157
  - project/Gemfile