itms_automation 2.7.0 → 2.7.5

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: dba9f35006766cde92ddcbe9b77d9943b86fbdbbdfdf13f2a8f59b73589aa5da
4
- data.tar.gz: 87c8d32302284a4505a2e56eed6dfe74b863e308aceea85b6bdf1faf5374ca22
3
+ metadata.gz: 9b64bf92d7eea643ea0cfa8fce4ffa9fcbec40c94c410f55304d6478d3a5c217
4
+ data.tar.gz: 366081969d763d1d5035febd1edc5543f43398d7bb8d27fb72eb35eff2c6df64
5
5
  SHA512:
6
- metadata.gz: 77f8c58293b04d7547413a99b7872822d3d0966cf9f42925431e4eeec87fd9415e2e2cb073102a8d52d12c89ad67030229ec1857b23c6cad4a5f65bc0b82bb99
7
- data.tar.gz: d3decc37bd0b053305208cb5cffc559fb37048717d4e978995bd8033bf251cf094e341e32c90742c6d18f6b92dbc9f55082c6adbb7f0f628864fdbfb5763985a
6
+ metadata.gz: fb24cfbbeeaf755cbfff7ae58fc31ac4cac98c7d004063499726aa32a087feff4e2e3287e211bcac139c5f4fb429bd66324ab5a5233e5507e3e1ad4c54c4bc48
7
+ data.tar.gz: 48cf28006a35fe632d99831677b178ed0cd926d1247fd2ff6ca24c4ca28989e9a14ec60d51f59b366515691620be383f954fe2997c47e18a43f3b12cad0c95ee
@@ -7,28 +7,29 @@ require "webdrivers"
7
7
  $browser_type = ENV["BROWSER"] || "firefox"
8
8
 
9
9
  begin
10
+ $vars = {}
10
11
  $driver = case $browser_type
11
- when "chrome"
12
- Selenium::WebDriver.for(:chrome)
13
- when "safari"
14
- Selenium::WebDriver.for(:safari)
15
- when "internet_explorer"
16
- Selenium::WebDriver.for(:internet_explorer)
17
- when "chrome_headless"
18
- Selenium::WebDriver.for(:chrome, :desired_capabilities => Selenium::WebDriver::Remote::Capabilities.chrome(chromeOptions: { args: %w(headless) }))
19
- when "remote"
20
- if ENV['SERVER_URL'].nil? || ENV['REMOTE_BROWSER'].nil?
21
- puts "\nMissing SERVER_URL : SERVER_URL=http//SERVER_URL:4444/wd/hub"
22
- puts "\nMissing REMOTE_BROWSER: REMOTE_BROWSER=browser_name"
23
- Process.exit(0)
24
- else
25
- caps = Selenium::WebDriver::Remote::Capabilities.new
26
- caps["browserName"] = ENV["REMOTE_BROWSER"]
27
- caps["enableVNC"] = true
28
- caps["enableVideo"] = ENV["ENABLE_VIDEO"] == "true"
29
- caps["resolution"] = ENV["resolution"] unless ENV["resolution"]
30
- Selenium::WebDriver.for(:remote, :url => ENV["SERVER_URL"], :desired_capabilities => caps)
31
- end
12
+ when "chrome"
13
+ Selenium::WebDriver.for(:chrome)
14
+ when "safari"
15
+ Selenium::WebDriver.for(:safari)
16
+ when "internet_explorer"
17
+ Selenium::WebDriver.for(:internet_explorer)
18
+ when "chrome_headless"
19
+ Selenium::WebDriver.for(:chrome, :desired_capabilities => Selenium::WebDriver::Remote::Capabilities.chrome(chromeOptions: { args: %w(headless) }))
20
+ when "remote"
21
+ if ENV['SERVER_URL'].nil? || ENV['REMOTE_BROWSER'].nil?
22
+ puts "\nMissing SERVER_URL : SERVER_URL=http//SERVER_URL:4444/wd/hub"
23
+ puts "\nMissing REMOTE_BROWSER: REMOTE_BROWSER=browser_name"
24
+ Process.exit(0)
25
+ else
26
+ caps = Selenium::WebDriver::Remote::Capabilities.new
27
+ caps["browserName"] = ENV["REMOTE_BROWSER"]
28
+ caps["enableVNC"] = false
29
+ caps["enableVideo"] = false
30
+ caps["resolution"] = ENV["resolution"] unless ENV["resolution"]
31
+ Selenium::WebDriver.for(:remote, :url => ENV["SERVER_URL"], :desired_capabilities => caps)
32
+ end
32
33
  else
33
34
  Selenium::WebDriver.for(:firefox)
34
35
  end
@@ -1,228 +1,208 @@
1
1
  require 'net/https'
2
2
  require_relative 'required_files'
3
+ require 'rspec'
3
4
 
4
5
  # This file contains assertion methods which are called from assertion_steps.rb
5
6
 
6
- # Method to return page title
7
- def get_page_title
8
- $driver.title
7
+ # Method to verify title
8
+ # param 1: String : expected title
9
+ def assert_title(title)
10
+ expect($driver.title).to eq(title)
9
11
  end
10
12
 
11
- # Method to verify title
12
- # param 1 : String : expected title
13
- # param 2 : Boolean : test case [true or flase]
14
- def check_title(title, test_case)
15
- page_title = get_page_title
16
- if test_case
17
- if page_title != "#{title}"
18
- raise TestCaseFailed, "Page Title Not Matched, Actual Page Title : #{page_title}"
19
- end
20
- else
21
- if page_title == "#{title}"
22
- raise TestCaseFailed, "Page Title Matched, Actual Page Title:#{page_title}"
23
- end
24
- end
13
+ # Method to check element text
14
+ # param 1 : String : Element
15
+ # param 2 : String : Expected element text
16
+ def assert_text(element, expected_value)
17
+ found_element = find_object(element)
18
+ element_text = found_element.text
19
+ expect(element_text).to eq(expected_value)
25
20
  end
26
21
 
27
- # Method to verify partial title
28
- # param 1 : String : partial title string
29
- # param 2 : Boolean : test case [true or flase]
30
- def check_partial_title(partial_text_title, test_case)
31
- page_title = get_page_title
32
- if test_case
33
- if not page_title.include? "#{partial_text_title}"
34
- raise TestCaseFailed, 'Partial Page Title Not Present'
35
- end
36
- else
37
- if page_title.include? "#{partial_text_title}"
38
- raise TestCaseFailed, 'Page Title Matched'
39
- end
40
- end
22
+ # method to check element presence
23
+ # param 1: String: Element
24
+ def assert_element_present(element)
25
+ found_element = find_object(element)
26
+ expect(found_element.length).to be > 0
41
27
  end
42
28
 
43
- # Method to get element text
44
- # param : String
45
- def get_element_text(element)
46
- WAIT.until { find_object(element) }.text
29
+ # method to check element not presence
30
+ # param 1: String: Element
31
+ def assert_element_not_present(element)
32
+ found_element = find_object(element)
33
+ expect(found_element.length).to eq(0)
47
34
  end
48
35
 
49
- # Method to check element text
36
+ # method to assert checkbox check
50
37
  # param 1 : String : Element
51
- # param 2 : String : Expected element text
52
- # param 3 : Boolean : test case [true or flase]
53
- def check_element_text(element, expected_value, test_case)
54
- element_text = get_element_text(element)
38
+ def assert_checked(element)
39
+ checkbox = find_object(element)
40
+ expect(checkbox.selected?).to be_truthy
41
+ end
55
42
 
56
- if test_case
57
- if element_text != expected_value
58
- raise TestCaseFailed, "Text Not Matched. Actual Value :#{expected_value}"
59
- end
60
- else
61
- if element_text == expected_value
62
- raise TestCaseFailed, "Text Matched. Actual Value :#{expected_value}"
63
- end
64
- end
43
+ def assert_not_checked(element)
44
+ checkbox = find_object(element)
45
+ expect(checkbox.selected?).to be_falsey
65
46
  end
66
47
 
67
- # Method to check partial element text
68
- # param 1 : String : Element
69
- # param 2 : String : Expected element partial text
70
- # param 3 : Boolean : test case [true or flase]
71
- def check_element_partial_text(element, expected_value, test_case)
72
- element_text = get_element_text(element)
73
-
74
- if test_case
75
- if not element_text.include? "#{expected_value}"
76
- raise TestCaseFailed, "Text Not Matched. Actual Value :#{expected_value}"
77
- end
78
- else
79
- if element_text.include? "#{expected_value}"
80
- raise TestCaseFailed, "Text Matched. Actual Value :#{expected_value}"
81
- end
82
- end
48
+ # method to check javascript pop-up alert text
49
+ def assert_alert(text)
50
+ alert_text = $driver.switch_to.alert.text
51
+ expect(alert_text).to eq(text)
83
52
  end
84
53
 
85
- # method to return element status - enabled?
86
- # param : String : Element
87
- def is_element_enabled(element)
88
- WAIT.until{ find_object(element) }.enabled?
54
+ # method to check javascript pop-up alert text
55
+ def assert_confirmation(text)
56
+ alert_text = $driver.switch_to.alert.text
57
+ expect(alert_text).to eq(text)
89
58
  end
90
59
 
91
- # method to check element status - enabled?
92
- # param 1 : String : Element
93
- # param 2 : Boolean : test case [true or flase]
94
- def check_element_enable(element, test_case)
95
- result = is_element_enabled(element)
60
+ def assert_editable(element)
61
+ found_element = find_object(element)
62
+ expect(found_element.enabled?).to be_truthy
63
+ end
96
64
 
97
- if test_case
98
- raise TestCaseFailed, 'Element Not Enabled' unless result
99
- else
100
- raise TestCaseFailed, 'Element Enabled' unless !result
101
- end
65
+ def assert_not_editable
66
+ found_element = find_object(element)
67
+ expect(found_element.enabled?).to be_falsey
102
68
  end
103
69
 
104
- # method to get attribute value
105
- # param 1 : String : Element
106
- # param 2 : String : atrribute name
107
- def get_element_attribute(element, attribute_name)
108
- WAIT.until{ find_object(element) }.attribute("#{attribute_name}")
70
+ def assert_not_selected_value(element, text)
71
+ found_element = find_object(element)
72
+ value = found_element.attribute("value")
73
+ expect(value).not_to eq(text)
109
74
  end
110
75
 
111
- # method to check attribute value
112
- # param 1 : String : Element
113
- # param 2 : String : atrribute name
114
- # param 3 : String : atrribute value
115
- # param 4 : Boolean : test case [true or flase]
116
- def check_element_attribute(element, attribute_name, attribute_value, test_case)
76
+ def assert_not_text(element, text)
77
+ found_element = find_object(element)
78
+ expect(found_element.text).not_to eq(text)
79
+ end
117
80
 
118
- attr_val = get_element_attribute(element, attribute_name)
81
+ def assert_prompt(text)
82
+ alert_text = $driver.switch_to.alert.text
83
+ expect(alert_text).to eq(text)
84
+ end
119
85
 
120
- if test_case
121
- if attr_val != attribute_value
122
- raise TestCaseFailed, "Attribute Value Not Matched. Actual Value :#{attr_val}"
123
- end
124
- else
125
- if attr_val == attribute_value
126
- raise TestCaseFailed, "Attribute Value Matched. Actual Value :#{attr_val}"
127
- end
128
- end
86
+ def assert_selected_label(element, text)
87
+ found_element = find_object(element)
88
+ locator = "option[@value='#{found_element.attribute('value')}']"
89
+ selected_text = found_element.find_element(:xpath, locator).text
90
+ expect(selected_text).to eq(text)
129
91
  end
130
92
 
131
- # method to get element status - displayed?
132
- # param : String : Element
133
- def is_element_displayed(element)
134
- WAIT.until{ find_object(element) }.displayed?
93
+ def assert_value(element, text)
94
+ found_element = find_object(element)
95
+ value = found_element.attribute("value")
96
+ expect(value).to eq(text)
135
97
  end
136
98
 
137
- # method to check element presence
138
- # param 1 : String : Element
139
- # param 2 : Boolean : test case [true or flase]
140
- def check_element_presence(element, test_case)
141
- if test_case
142
- if !is_element_displayed(element)
143
- raise TestCaseFailed, 'Element Not Present'
144
- end
145
- else
146
- begin
147
- if is_element_displayed(element)
148
- raise 'Present' # since it is negative test and we found element
149
- end
150
- rescue Exception => e
151
- if e.message == 'Present' # only raise if it present
152
- raise TestCaseFailed, 'Element Present'
153
- end
154
- end
99
+ def assert_selected_value
100
+ found_element = find_object(element)
101
+ value = found_element.attribute("value")
102
+ expect(value).to eq(text)
103
+ end
104
+
105
+ def assert(var_name, value)
106
+ if (value == "true" || value == "false")
107
+ _value = value
108
+ else elseif (value == '0' || !!number_or_nil(value)) {
109
+ _value = value
155
110
  end
111
+ result = _value
112
+ ? expect($vars[var_name]).to eq(_value)
113
+ : expect($vars[var_name]).to eq(value)
114
+ end
115
+
116
+ # Method to verify title
117
+ # param 1: String : expected title
118
+ def verify_title(title)
119
+ expect($driver.title).to eq(title)
156
120
  end
157
121
 
158
- # method to assert checkbox check/uncheck
122
+ # Method to check element text
159
123
  # param 1 : String : Element
160
- # param 2 : Boolean : test case [true or flase]
161
- def is_checkbox_checked(element, should_be_checked = true)
162
- checkbox = WAIT.until{ find_object(element) }
163
-
164
- if !checkbox.selected? && should_be_checked
165
- raise TestCaseFailed, 'Checkbox is not checked'
166
- elsif checkbox.selected? && !should_be_checked
167
- raise TestCaseFailed, 'Checkbox is checked'
168
- end
124
+ # param 2 : String : Expected element text
125
+ def verify_text(element, expected_value)
126
+ found_element = find_object(element)
127
+ element_text = found_element.text
128
+ expect(element_text).to eq(expected_value)
169
129
  end
170
130
 
171
- # method to assert radio button selected/unselected
131
+ # method to check element presence
132
+ # param 1: String: Element
133
+ def verify_element_present(element)
134
+ found_element = find_object(element)
135
+ expect(found_element.length).to be > 0
136
+ end
137
+
138
+ # method to check element not presence
139
+ # param 1: String: Element
140
+ def verify_element_not_present(element)
141
+ found_element = find_object(element)
142
+ expect(found_element.length).to eq(0)
143
+ end
144
+
145
+ # method to assert checkbox check
172
146
  # param 1 : String : Element
173
- # param 2 : Boolean : test case [true or flase]
174
- def is_radio_button_selected(element, should_be_selected = true)
175
- radio_button = WAIT.until{ find_object(element) }
176
-
177
- if !radio_button.selected? && should_be_selected
178
- raise TestCaseFailed, 'Radio Button not selected'
179
- elsif radio_button.selected? && !should_be_selected
180
- raise TestCaseFailed, 'Radio Button is selected'
181
- end
147
+ def verify_checked(element)
148
+ checkbox = find_object(element)
149
+ expect(checkbox.selected?).to be_truthy
182
150
  end
183
151
 
184
- # method to assert option from radio button group is selected/unselected
185
- def is_option_from_radio_button_group_selected(element, by, option, should_be_selected = true)
186
- radio_button_group = WAIT.until{ find_object(element) }
152
+ def verify_not_checked(element)
153
+ checkbox = find_object(element)
154
+ expect(checkbox.selected?).to be_falsey
155
+ end
187
156
 
188
- getter = ->(rb, by) { by == 'value' ? rb.attribute('value') : rb.text }
157
+ def verify_editable(element)
158
+ found_element = find_object(element)
159
+ expect(found_element.enabled?).to be_truthy
160
+ end
189
161
 
190
- ele = radio_button_group.find { |rb| getter.call(rb, by) == option }
162
+ def verify_not_editable
163
+ found_element = find_object(element)
164
+ expect(found_element.enabled?).to be_falsey
165
+ end
191
166
 
192
- if !ele.selected? && should_be_selected
193
- raise TestCaseFailed, 'Radio button is not selected'
194
- elsif ele.selected? && !should_be_selected
195
- raise TestCaseFailed, 'Radio button is selected'
196
- end
167
+ def verify_not_selected_value(element, text)
168
+ found_element = find_object(element)
169
+ value = found_element.attribute("value")
170
+ expect(value).not_to eq(text)
197
171
  end
198
172
 
199
- # method to get javascript pop-up alert text
200
- def get_alert_text
201
- $driver.switch_to.alert.text
173
+ def verify_not_text(element, text)
174
+ found_element = find_object(element)
175
+ expect(found_element.text).not_to eq(text)
202
176
  end
203
177
 
204
- # method to check javascript pop-up alert text
205
- def check_alert_text(text)
206
- if get_alert_text != text
207
- raise TestCaseFailed, "Text on alert pop up not matched. Actual Value :#{get_alert_text}"
208
- end
178
+ def verify_selected_label(element, text)
179
+ found_element = find_object(element)
180
+ locator = "option[@value='#{found_element.attribute('value')}']"
181
+ selected_text = found_element.find_element(:xpath, locator).text
182
+ expect(selected_text).to eq(text)
209
183
  end
210
184
 
211
- def is_option_from_dropdown_selected(element, by, option, should_be_selected=true)
212
- dropdown = WAIT.until { find_object(element) }
213
- select_list = Selenium::WebDriver::Support::Select.new(dropdown)
185
+ def verify_value(element, text)
186
+ found_element = find_object(element)
187
+ value = found_element.attribute("value")
188
+ expect(value).to eq(text)
189
+ end
214
190
 
215
- if by == 'text'
216
- actual_value = select_list.first_selected_option.text
217
- else
218
- actual_value = select_list.first_selected_option.attribute('value')
219
- end
191
+ def verify_selected_value
192
+ found_element = find_object(element)
193
+ value = found_element.attribute("value")
194
+ expect(value).to eq(text)
195
+ end
220
196
 
221
- if !actual_value == option && should_be_selected
222
- raise TestCaseFailed, 'Option Not Selected From Dropwdown'
223
- elsif actual_value == option && !should_be_selected
224
- raise TestCaseFailed, 'Option Selected From Dropwdown'
197
+ def verify(var_name, value)
198
+ if (value == "true" || value == "false")
199
+ _value = value
200
+ else elseif (value == '0' || !!number_or_nil(value)) {
201
+ _value = value
225
202
  end
203
+ result = _value
204
+ ? expect($vars[var_name]).to eq(_value)
205
+ : expect($vars[var_name]).to eq(value)
226
206
  end
227
207
 
228
208
  # Method to find difference between images
@@ -331,3 +311,8 @@ def compare_png_images(expected_img_url, actual_img_url)
331
311
  end
332
312
  true
333
313
  end
314
+
315
+ def number_or_nil(string)
316
+ num = string.to_i
317
+ num if num.to_s == string
318
+ end
@@ -1,20 +1,27 @@
1
1
  require_relative 'required_files'
2
2
 
3
3
  def click(element)
4
- WAIT.until { find_object(element) }.click
4
+ found_element = find_object(element)
5
+ found_element.click
5
6
  end
6
7
 
7
- def click_forcefully(element)
8
- $driver.execute_script('arguments[0].click();', WAIT.until { find_object(element) })
8
+ def click_at(element)
9
+ found_element = find_object(element)
10
+ found_element.click
9
11
  end
10
12
 
11
13
  def double_click(element)
12
- found_element = WAIT.until { find_object(element) }
14
+ found_element = find_object(element)
13
15
  $driver.action.double_click(found_element).perform
14
16
  end
15
17
 
16
- def long_press( element, duration)
17
- found_element = WAIT.until { find_object(element) }
18
+ def double_click_at(element, location)
19
+ found_element = find_object(element)
20
+ $driver.action.double_click(found_element).perform
21
+ end
22
+
23
+ def long_press(element, duration)
24
+ found_element = find_object(element)
18
25
  parameters = { "element" => "#{found_element}", "duration" => "#{duration}" }
19
26
  args = parameters.select { |k, v| [:element, :duration].include? k }
20
27
  args = args_with_ele_ref(args)
@@ -0,0 +1,13 @@
1
+ require_relative 'required_files'
2
+
3
+ def if(condition_script)
4
+ return $driver.execute_script(condition_script)
5
+ end
6
+
7
+ def else_if(condition_script)
8
+ return $driver.execute_script(condition_script)
9
+ end
10
+
11
+ def while(condition_script)
12
+ return $driver.execute_script(condition_script)
13
+ end
@@ -7,9 +7,9 @@ def print_congifugartion
7
7
  puts "Time : #{Time.now.strftime("%I:%M:%S:%p")}"
8
8
 
9
9
  if $platform == 'android' or $platform == 'ios'
10
- print_mobile_configuration
10
+ print_mobile_configuration
11
11
  else
12
- print_desktop_configuration
12
+ print_desktop_configuration
13
13
  end
14
14
  end
15
15
 
@@ -22,14 +22,21 @@ end
22
22
 
23
23
  # method to print mobile configuration
24
24
  def print_mobile_configuration
25
- puts "Platform : #{$platform.upcase}"
26
- puts "OS version : #{$os_version}"
27
- puts "Device : #{$device_name}"
25
+ puts "Platform : #{$platform.upcase}"
26
+ puts "OS version : #{$os_version}"
27
+ puts "Device : #{$device_name}"
28
28
 
29
29
  if $app_path.nil?
30
- puts 'Browser : ' + $driver.capabilities.browser_name.to_s.upcase + " " + $driver.capabilities.version.to_s
30
+ puts 'Browser : ' + $driver.capabilities.browser_name.to_s.upcase + " " + $driver.capabilities.version.to_s
31
31
  else
32
- puts "App Tested : #{$app_path}"
32
+ puts "App Tested : #{$app_path}"
33
33
  end
34
34
  puts ''
35
35
  end
36
+
37
+ def echo(message)
38
+ puts(message)
39
+ end
40
+
41
+ def debugger
42
+ end
@@ -1,15 +1,21 @@
1
1
  require_relative 'required_files'
2
2
 
3
3
  # method to enter text into textfield
4
- def enter_text(element, text)
4
+ def type(element, text)
5
5
  foundElement = find_object(element)
6
- WAIT.until { foundElement }.send_keys(text)
6
+ foundElement.send_keys(text)
7
7
  end
8
8
 
9
- # method to clear text from textfield
10
- def clear_text(element)
9
+ # method to send keys
10
+ def send_keys(element, key)
11
+ keys_support = ["KEY_LEFT", "KEY_UP", "KEY_RIGHT", "KEY_DOWN", "KEY_PAGE_UP", "KEY_PAGE_DOWN", "KEY_BACKSPACE", "KEY_DELETE", "KEY_ENTER", "KEY_TAB"]
11
12
  foundElement = find_object(element)
12
- WAIT.until { foundElement }.clear
13
+ if key
14
+ get_key = key.strip[/^\$\{(.*?)\}$/, 1]
15
+ raise TestCaseFailed, "${get_key} key is not supported. Supported keys: KEY_LEFT, KEY_UP, KEY_RIGHT, KEY_DOWN, KEY_PAGE_UP, KEY_PAGE_DOWN, KEY_BACKSPACE, KEY_DELETE, KEY_ENTER, KEY_TAB" unless keys_support.include?(get_key)
16
+ key_convert = get_key[/^KEY_(.*?)$/, 1].downcase.to_sym
17
+ foundElement.send_keys(key_convert)
18
+ end
13
19
  end
14
20
 
15
21
  # method to select option from dropdwon list
@@ -34,23 +40,20 @@ def unselect_all_option_from_multiselect_dropdown(element)
34
40
  end
35
41
 
36
42
  # method to check checkbox
37
- def check_checkbox(element)
38
- checkbox = WAIT.until { find_object(element) }
43
+ def check(element)
44
+ checkbox = find_object(element)
39
45
  checkbox.click unless checkbox.selected?
40
46
  end
41
47
 
42
48
  # method to uncheck checkbox
43
- def uncheck_checkbox(element)
44
- checkbox = WAIT.until { find_object(element) }
45
-
46
- if checkbox.selected?
47
- checkbox.click
48
- end
49
+ def uncheck(element)
50
+ checkbox = find_object(element)
51
+ checkbox.click if checkbox.selected?
49
52
  end
50
53
 
51
- # method to select radio button
54
+ # method to toggle checkbox checked
52
55
  def toggle_checkbox(element)
53
- WAIT.until { find_object(element) }.click
56
+ find_object(element).click
54
57
  end
55
58
 
56
59
  # method to select radio button
@@ -67,3 +70,43 @@ def select_option_from_radio_button_group(element, by, option)
67
70
  ele = radio_button_group.find { |rb| getter.call(rb, by) == option }
68
71
  ele.click unless ele.selected?
69
72
  end
73
+
74
+ def edit_content(element, text)
75
+ found_element = find_object(element)
76
+ $driver.execute_script("if (arguments[0].contentEditable === 'true') {arguments[0].innerText = '#{text}'}", found_element)
77
+ end
78
+
79
+ def add_selection(label)
80
+ found_element = find_object(element)
81
+ found_element.find_element(:xpath, "//option[. = '#{label}']").click
82
+ end
83
+
84
+ def remove_selection
85
+ found_element = find_object(element)
86
+ found_element.find_element(:xpath, "//option[. = '#{label}']").click
87
+ end
88
+
89
+ def select
90
+ found_element = find_object(element)
91
+ found_element.find_element(:xpath, "//option[. = '#{label}']").click
92
+ end
93
+
94
+ def drag_and_drop_to_object(element, drop_element)
95
+ dragged = find_object(element)
96
+ object_value_regex = /^(class=|css=|id=|name=|xpath=|className=|link=|linkText=|partialLinkText=)/
97
+ object_type_regex = /^(class|css|id|name|xpath|className|link|linkText|partialLinkText)/
98
+ if object_value_regex.match?(drop_element)
99
+ object_value = drop_element.gsub(object_value_regex, "")
100
+ object_type = drop_element.split(object_type_regex)[1].underscore
101
+ dropped = $driver.find_element(object_type.to_sym, object_value)
102
+ $driver.action.drag_and_drop(dragged, dropped).perform
103
+ else
104
+ raise TestCaseFailed, "Option locator not supported"
105
+ end
106
+ end
107
+
108
+ def select_window(element)
109
+ end
110
+
111
+ def select_frame(element)
112
+ end
@@ -4,6 +4,6 @@ def handle_alert(decesion)
4
4
  if decesion == 'accept'
5
5
  $driver.switch_to.alert.accept
6
6
  else
7
- $driver.switch_to.alert.dismiss
7
+ $driver.switch_to.alert.dismiss
8
8
  end
9
9
  end
@@ -59,6 +59,6 @@ def loadYAMLfile(filename)
59
59
  begin
60
60
  return YAML.load_file(filename)
61
61
  rescue Psych::SyntaxError => ex
62
- raise " SyntaxError when reading file: #{ex}"
62
+ raise "Syntax error when reading file: #{ex}"
63
63
  end
64
64
  end
@@ -1,21 +1,25 @@
1
1
  require_relative 'required_files'
2
2
 
3
3
  # method to open link
4
- def navigate_to(link)
4
+ def open(link)
5
5
  $driver.get link
6
6
  end
7
7
 
8
8
  # method to navigate back & forward
9
9
  def navigate(direction)
10
10
  if direction == 'back'
11
- $driver.navigate.back
11
+ $driver.navigate.back
12
12
  else
13
13
  $driver.navigate.forward
14
14
  end
15
15
  end
16
16
 
17
+ def close
18
+ $drive.close
19
+ end
20
+
17
21
  # method to quite webdriver instance
18
- def close_driver
22
+ def quit
19
23
  $driver.quit
20
24
  end
21
25
 
@@ -39,7 +43,7 @@ end
39
43
  # Method to zoom in/out web page until web element dislays
40
44
  def zoom_in_out_till_element_display(element, in_out)
41
45
  while true
42
- if WAIT.until { find_object(element) }.displayed?
46
+ if find_object(element).displayed?
43
47
  break
44
48
  else
45
49
  $driver.action.key_down(:"#{get_key}").send_keys(:"#{in_out}").key_up(:"#{get_key}").perform
@@ -48,8 +52,10 @@ def zoom_in_out_till_element_display(element, in_out)
48
52
  end
49
53
 
50
54
  # Method to resize browser
51
- def resize_browser(width, heigth)
52
- $driver.manage.window.resize_to(width, heigth)
55
+ def set_window_size(resolution)
56
+ raise TestCaseFailed, 'Wrong format of resolution. (e.g., 1280x800)' unless resolution.match(/^\d+x\d+$/)
57
+ width, height = resolution.split("x")
58
+ $driver.manage.resize_to(width, heigth)
53
59
  end
54
60
 
55
61
  # Method to maximize browser
@@ -63,14 +69,50 @@ def refresh_page
63
69
  end
64
70
 
65
71
  # Method to hover on element
66
- def hover_over_element(element)
67
- element = WAIT.until { find_object(element) }
68
- $driver.action.move_to(element).perform
72
+ def mouse_over(element)
73
+ element = find_object(element)
74
+ $driver.action.move_to_element(element).perform
75
+ end
76
+
77
+ # mouse_down
78
+ def mouse_down(element)
79
+ element = find_object(element)
80
+ $driver.action.move_to_element(element).click_and_hold.perform
81
+ end
82
+
83
+ # mouse_down_at
84
+ def mouse_down_at(element, location)
85
+ element = find_object(element)
86
+ $driver.action.move_to_element(element).click_and_hold.perform
87
+ end
88
+
89
+ # mouse_out
90
+ def mouse_out
91
+ element = $driver.find_element(By.CSS_SELECTOR, 'body')
92
+ $driver.action.move_to_element(element, 0, 0).perform
93
+ end
94
+
95
+ #mouse_up
96
+ def mouse_up(element)
97
+ element = find_object(element)
98
+ $driver.action.move_to_element(element).release.perform
99
+ end
100
+
101
+ #mouse_up_at
102
+ def mouse_up_at
103
+ element = find_object(element)
104
+ $driver.action.move_to_element(element).release.perform
105
+ end
106
+
107
+ #mouse_move_at
108
+ def mouse_move_at
109
+ element = find_object(element)
110
+ $driver.action.move_to_element(element).perform
69
111
  end
70
112
 
71
113
  # Method to scroll page to perticular element
72
114
  def scroll_to_element(element)
73
- ele_scroll = WAIT.until { find_object(element) }
115
+ ele_scroll = find_object(element)
74
116
  ele_scroll.location_once_scrolled_into_view
75
117
  end
76
118
 
@@ -84,38 +126,3 @@ def scroll_page(to)
84
126
  raise "Exception : Invalid Direction (only scroll \"top\" or \"end\")"
85
127
  end
86
128
  end
87
-
88
- $old_win = nil
89
-
90
- # Method to switch to new window
91
- def switch_to_new_window
92
- $old_win = $driver.window_handle
93
- $driver.switch_to.window($driver.window_handles[1])
94
- end
95
-
96
- # Method to switch to old window
97
- def switch_to_old_window
98
- $driver.switch_to.window($old_win)
99
- end
100
-
101
- # Method to close new window
102
- def close_new_window
103
- $driver.close
104
- end
105
-
106
- =begin
107
- def switch_to_new_window
108
- win_handles = $driver.window_handles
109
-
110
- puts $driver.title
111
- puts win_handles.length
112
-
113
- $driver.switch_to.window($driver.window_handles[1])
114
- puts $driver.window_handles[1]
115
- puts $driver.title
116
-
117
- $driver.switch_to.window($driver.window_handles[2])
118
- puts $driver.window_handles[2]
119
- puts $driver.title
120
- end
121
- =end
@@ -1,15 +1,82 @@
1
1
  require_relative 'required_files'
2
2
 
3
- def wait(time)
3
+ def pause(time)
4
4
  sleep time.to_i
5
5
  end
6
6
 
7
- def wait_for_element_to_display(element, duration)
8
- wait = Selenium::WebDriver::Wait.new(:timeout => duration.to_i) # seconds
7
+ def wait_for_element_editable(element, duration)
8
+ wait = Selenium::WebDriver::Wait.new(:timeout => duration.to_i / 1000)
9
+ wait.until { find_object(element).enabled? }
10
+ end
11
+
12
+ def wait_for_element_not_editable(element, duration)
13
+ wait = Selenium::WebDriver::Wait.new(:timeout => duration.to_i / 1000)
14
+ wait.until { !find_object(element).enabled? }
15
+ end
16
+
17
+ def wait_for_element_not_present(element, duration)
18
+ wait = Selenium::WebDriver::Wait.new(:timeout => duration.to_i / 1000)
19
+ wait.until do
20
+ begin
21
+ !find_object(element)
22
+ rescue Selenium::WebDriver::Error::NoSuchElementError
23
+ true
24
+ end
25
+ end
26
+ end
27
+
28
+ def wait_for_element_not_visible(element, duration)
29
+ wait = Selenium::WebDriver::Wait.new(:timeout => duration.to_i / 1000)
30
+ wait.until { !find_object(element).displayed? }
31
+ end
32
+
33
+ def wait_for_text(element, text)
34
+ wait = Selenium::WebDriver::Wait.new(:timeout => 30)
35
+ wait.until { find_object(element).text == text }
36
+ end
37
+
38
+ def wait_for_element_visible(element, duration)
39
+ wait = Selenium::WebDriver::Wait.new(:timeout => duration.to_i / 1000)
9
40
  wait.until { find_object(element).displayed? }
10
41
  end
11
42
 
12
- def wait_for_element_to_enable(element, duration)
13
- wait = Selenium::WebDriver::Wait.new(:timeout => duration.to_i) # seconds
14
- wait.until { find_object(element).enabled? }
43
+ def wait_for_element_present(element, duration)
44
+ wait = Selenium::WebDriver::Wait.new(:timeout => duration.to_i / 1000)
45
+ wait.until { find_object(element) }
46
+ end
47
+
48
+ def answer_on_next_prompt(answer)
49
+ alert = $driver.switch_to.alert
50
+ alert.send_keys(answer)
51
+ alert.accept()
52
+ end
53
+
54
+ def choose_cancel_on_next_confirmation
55
+ $driver.switch_to.alert.dismiss
56
+ end
57
+
58
+ def choose_cancel_on_next_prompt
59
+ $driver.switch_to.alert.dismiss
60
+ end
61
+
62
+ def choose_ok_on_next_confirmation
63
+ $driver.switch_to.alert.accept
64
+ end
65
+
66
+ def webdriver_answer_on_visible_prompt
67
+ alert = $driver.switch_to.alert
68
+ alert.send_keys(answer)
69
+ alert.accept()
70
+ end
71
+
72
+ def webdriver_choose_cancel_on_visible_confirmation
73
+ $driver.switch_to.alert.dismiss
74
+ end
75
+
76
+ def webdriver_choose_ok_on_visible_confirmation
77
+ $driver.switch_to.alert.accept
78
+ end
79
+
80
+ def webdriver_choose_cancel_on_visible_prompt
81
+ $driver.switch_to.alert.dismiss
15
82
  end
@@ -0,0 +1,36 @@
1
+ require 'net/https'
2
+ require_relative 'required_files'
3
+ require 'rspec'
4
+
5
+ def store(var_name, value)
6
+ $vars[var_name] = value
7
+ end
8
+
9
+ def store_json(var_name, value)
10
+ $vars[var_name] = JSON.parse(value)
11
+ end
12
+
13
+ def store_text(element, var_name)
14
+ found_element = find_object(element)
15
+ element_text = found_element.text
16
+ $vars[var_name] = element_text
17
+ end
18
+
19
+ def store_title(var_name)
20
+ $vars[var_name] = $driver.title
21
+ end
22
+
23
+ def store_xpath_count(element, var_name)
24
+ found_element = find_object(element)
25
+ $vars[var_name] = found_element.length
26
+ end
27
+
28
+ def store_window_handle(var_name)
29
+ $vars[var_name] = $driver.window_handle
30
+ end
31
+
32
+ def store_attribute(element, attribute, var_name)
33
+ found_element = find_object(element)
34
+ value = found_element.attribute(attribute)
35
+ $vars[var_name] = value
36
+ end
@@ -1,5 +1,5 @@
1
1
  module ITMS
2
2
  module Automation
3
- VERSION = '2.7.0'
3
+ VERSION = '2.7.5'
4
4
  end
5
5
  end
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: 2.7.0
4
+ version: 2.7.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - INFOdation
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-01-29 00:00:00.000000000 Z
11
+ date: 2021-04-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: cucumber
@@ -16,20 +16,20 @@ dependencies:
16
16
  requirements:
17
17
  - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: 5.2.0
19
+ version: 3.1.2
20
20
  - - "~>"
21
21
  - !ruby/object:Gem::Version
22
- version: 5.2.0
22
+ version: 3.1.2
23
23
  type: :runtime
24
24
  prerelease: false
25
25
  version_requirements: !ruby/object:Gem::Requirement
26
26
  requirements:
27
27
  - - ">="
28
28
  - !ruby/object:Gem::Version
29
- version: 5.2.0
29
+ version: 3.1.2
30
30
  - - "~>"
31
31
  - !ruby/object:Gem::Version
32
- version: 5.2.0
32
+ version: 3.1.2
33
33
  - !ruby/object:Gem::Dependency
34
34
  name: webdrivers
35
35
  requirement: !ruby/object:Gem::Requirement
@@ -110,6 +110,26 @@ dependencies:
110
110
  - - "~>"
111
111
  - !ruby/object:Gem::Version
112
112
  version: '1.8'
113
+ - !ruby/object:Gem::Dependency
114
+ name: rspec
115
+ requirement: !ruby/object:Gem::Requirement
116
+ requirements:
117
+ - - ">="
118
+ - !ruby/object:Gem::Version
119
+ version: '3.5'
120
+ - - "~>"
121
+ - !ruby/object:Gem::Version
122
+ version: '3.5'
123
+ type: :runtime
124
+ prerelease: false
125
+ version_requirements: !ruby/object:Gem::Requirement
126
+ requirements:
127
+ - - ">="
128
+ - !ruby/object:Gem::Version
129
+ version: '3.5'
130
+ - - "~>"
131
+ - !ruby/object:Gem::Version
132
+ version: '3.5'
113
133
  description: Behavior driven development (BDD) approach to write automation test script
114
134
  to test Web and Android applications.
115
135
  email: anh.pham@infodation.vn
@@ -149,6 +169,7 @@ files:
149
169
  - lib/itms_automation/javascript_handling_steps.rb
150
170
  - lib/itms_automation/methods/assertion_methods.rb
151
171
  - lib/itms_automation/methods/click_elements_methods.rb
172
+ - lib/itms_automation/methods/condition_methods.rb
152
173
  - lib/itms_automation/methods/configuration_methods.rb
153
174
  - lib/itms_automation/methods/error_handling_methods.rb
154
175
  - lib/itms_automation/methods/input_methods.rb
@@ -158,6 +179,7 @@ files:
158
179
  - lib/itms_automation/methods/progress_methods.rb
159
180
  - lib/itms_automation/methods/required_files.rb
160
181
  - lib/itms_automation/methods/screenshot_methods.rb
182
+ - lib/itms_automation/methods/store_methods.rb
161
183
  - lib/itms_automation/navigation_steps.rb
162
184
  - lib/itms_automation/progress_steps.rb
163
185
  - lib/itms_automation/screenshot_steps.rb