Ifd_Automation 1.4.0 → 1.5.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,87 +1,87 @@
1
- # Error handling methods
2
-
3
- # Method to check browser type
4
- def validate_parameters(platform, browser_type, app_path)
5
- if platform == 'desktop'
6
- if !%w(ff ie chrome safari opera).include? browser_type
7
- print_error_desktop
8
- end
9
- elsif platform == 'android'
10
- print_error_android browser_type, app_path
11
- elsif platform == 'iOS'
12
- puts "Not Implemented..."
13
- # print_error_ios browser_type, app_path
14
- else
15
- print_invalid_platform
16
- end
17
- end
18
-
19
- # print error for desktop
20
- def print_error_desktop
21
- puts "\nInappropraite desktop browser : \"#{ENV['BROWSER']}\""
22
- puts "\nUsage : cucumber BROWSER=browser_name"
23
- puts "\nBrowser Supported :\n"
24
- puts "\n1.ie\n2.chrome\n3.ff\n4.safari\n5.opera"
25
- Process.exit(0)
26
- end
27
-
28
- # print error for android
29
- def print_error_android(browser_type, app_path)
30
- if browser_type=='ff' and app_path==nil
31
- puts "\nOops... not mentioned \"Browser\" or \"App path\""
32
- print_error_android_app
33
- print_error_android_web
34
- Process.exit(0)
35
- elsif browser_type!='ff' and !%w(native chrome).include? browser_type
36
- puts "\nOops... not supported browser"
37
- print_error_android_web
38
- Process.exit(0)
39
- end
40
- end
41
-
42
- # print error for android app
43
- def print_error_android_app
44
- puts "\nTo run test on android app"
45
- puts "\n Usage : cucumber PLATFORM=android APP_PATH=path/to/app"
46
- end
47
-
48
- # print error for android web
49
- def print_error_android_web
50
- puts "\nTo run test on android mobile web"
51
- puts "\n Usage : cucumber PLATFORM=android BROWSER=browser_name"
52
- puts "\n Supported browsers are \"chrome\" and \"native\""
53
- end
54
-
55
- # print error for ios
56
- def print_error_ios
57
- if browser_type=='ff' and app_path==nil
58
- puts "\nOops... not mentioned \"Browser\" or \"App path\""
59
- print_error_ios_app
60
- print_error_ios_web
61
- Process.exit(0)
62
- elsif browser_type!='safari'
63
- puts "\nOops... not supported browser"
64
- print_error_ios_app_web
65
- Process.exit(0)
66
- end
67
- end
68
-
69
- # print error for ios app
70
- def print_error_ios_app
71
- puts "\nTo run test on iOS App"
72
- puts "\n Usage : cucumber PLATFORM=iOS APP_PATH=path/to/app"
73
- end
74
-
75
- # print error for ios web
76
- def print_error_ios_web
77
- puts "\nTo run test on iOS mobile web"
78
- puts "\n Usage : cucumber PLATFORM=iOS BROWSER=safari"
79
- end
80
-
81
- # print error if invalid platform
82
- def print_invalid_platform
83
- puts "\nOops... Invalid Platform"
84
- puts "\nSupported platform are \"android\" and \"iOS\"."
85
- puts "\nTo run on Desktop no need to mention platform."
86
- Process.exit(0)
1
+ # Error handling methods
2
+
3
+ # Method to check browser type
4
+ def validate_parameters(platform, browser_type, app_path)
5
+ if platform == 'desktop'
6
+ if !%w(ff ie chrome safari opera).include? browser_type
7
+ print_error_desktop
8
+ end
9
+ elsif platform == 'android'
10
+ print_error_android browser_type, app_path
11
+ elsif platform == 'iOS'
12
+ puts "Not Implemented..."
13
+ # print_error_ios browser_type, app_path
14
+ else
15
+ print_invalid_platform
16
+ end
17
+ end
18
+
19
+ # print error for desktop
20
+ def print_error_desktop
21
+ puts "\nInappropraite desktop browser : \"#{ENV['BROWSER']}\""
22
+ puts "\nUsage : cucumber BROWSER=browser_name"
23
+ puts "\nBrowser Supported :\n"
24
+ puts "\n1.ie\n2.chrome\n3.ff\n4.safari\n5.opera"
25
+ Process.exit(0)
26
+ end
27
+
28
+ # print error for android
29
+ def print_error_android(browser_type, app_path)
30
+ if browser_type=='ff' and app_path==nil
31
+ puts "\nOops... not mentioned \"Browser\" or \"App path\""
32
+ print_error_android_app
33
+ print_error_android_web
34
+ Process.exit(0)
35
+ elsif browser_type!='ff' and !%w(native chrome).include? browser_type
36
+ puts "\nOops... not supported browser"
37
+ print_error_android_web
38
+ Process.exit(0)
39
+ end
40
+ end
41
+
42
+ # print error for android app
43
+ def print_error_android_app
44
+ puts "\nTo run test on android app"
45
+ puts "\n Usage : cucumber PLATFORM=android APP_PATH=path/to/app"
46
+ end
47
+
48
+ # print error for android web
49
+ def print_error_android_web
50
+ puts "\nTo run test on android mobile web"
51
+ puts "\n Usage : cucumber PLATFORM=android BROWSER=browser_name"
52
+ puts "\n Supported browsers are \"chrome\" and \"native\""
53
+ end
54
+
55
+ # print error for ios
56
+ def print_error_ios
57
+ if browser_type=='ff' and app_path==nil
58
+ puts "\nOops... not mentioned \"Browser\" or \"App path\""
59
+ print_error_ios_app
60
+ print_error_ios_web
61
+ Process.exit(0)
62
+ elsif browser_type!='safari'
63
+ puts "\nOops... not supported browser"
64
+ print_error_ios_app_web
65
+ Process.exit(0)
66
+ end
67
+ end
68
+
69
+ # print error for ios app
70
+ def print_error_ios_app
71
+ puts "\nTo run test on iOS App"
72
+ puts "\n Usage : cucumber PLATFORM=iOS APP_PATH=path/to/app"
73
+ end
74
+
75
+ # print error for ios web
76
+ def print_error_ios_web
77
+ puts "\nTo run test on iOS mobile web"
78
+ puts "\n Usage : cucumber PLATFORM=iOS BROWSER=safari"
79
+ end
80
+
81
+ # print error if invalid platform
82
+ def print_invalid_platform
83
+ puts "\nOops... Invalid Platform"
84
+ puts "\nSupported platform are \"android\" and \"iOS\"."
85
+ puts "\nTo run on Desktop no need to mention platform."
86
+ Process.exit(0)
87
87
  end
@@ -1,33 +1,33 @@
1
- # custome exception class
2
- class TestCaseFailed < Exception
3
- end
4
- #
5
- # # WAIT instance for explicit wait
6
- # WAIT = Selenium::WebDriver::Wait.new(:timeout => 30)
7
- #
8
- # # method to validate locator
9
- # def valid_locator_type? type
10
- # %w(id class css name xpath).include? type
11
- # end
12
- #
13
- # def validate_locator type
14
- # raise "Invalid locator type - #{type}" unless valid_locator_type? type
15
- # end
16
- #
17
- # # method to validate dropdown selector
18
- # def valid_option_by? option_by
19
- # %w(text value index).include? option_by
20
- # end
21
- #
22
- # def validate_option_by option_by
23
- # raise "Invalid option by - #{option_by}" unless valid_option_by? option_by
24
- # end
25
- #
26
- # # Return android device name and android version using adb command
27
- # def get_device_info
28
- # IO.popen('adb shell getprop ro.product.brand') { |f| $device = f.gets.chomp.upcase}
29
- # $device += ' '
30
- # IO.popen('adb shell getprop ro.product.model') { |f| $device += f.gets.chomp.upcase}
31
- # IO.popen('adb shell getprop ro.build.version.release') { |f| $os_version = f.gets.chomp.upcase}
32
- # return $device, $os_version
33
- # end
1
+ # custome exception class
2
+ class TestCaseFailed < Exception
3
+ end
4
+ #
5
+ # # WAIT instance for explicit wait
6
+ # WAIT = Selenium::WebDriver::Wait.new(:timeout => 30)
7
+ #
8
+ # # method to validate locator
9
+ # def valid_locator_type? type
10
+ # %w(id class css name xpath).include? type
11
+ # end
12
+ #
13
+ # def validate_locator type
14
+ # raise "Invalid locator type - #{type}" unless valid_locator_type? type
15
+ # end
16
+ #
17
+ # # method to validate dropdown selector
18
+ # def valid_option_by? option_by
19
+ # %w(text value index).include? option_by
20
+ # end
21
+ #
22
+ # def validate_option_by option_by
23
+ # raise "Invalid option by - #{option_by}" unless valid_option_by? option_by
24
+ # end
25
+ #
26
+ # # Return android device name and android version using adb command
27
+ # def get_device_info
28
+ # IO.popen('adb shell getprop ro.product.brand') { |f| $device = f.gets.chomp.upcase}
29
+ # $device += ' '
30
+ # IO.popen('adb shell getprop ro.product.model') { |f| $device += f.gets.chomp.upcase}
31
+ # IO.popen('adb shell getprop ro.build.version.release') { |f| $os_version = f.gets.chomp.upcase}
32
+ # return $device, $os_version
33
+ # end
@@ -1,33 +1,33 @@
1
- require 'rubygems'
2
- require 'selenium-webdriver'
3
- require 'chunky_png'
4
- require 'open-uri'
5
- require 'rbconfig'
6
- require 'appium_lib'
7
- require 'rubygems'
8
- require 'yaml'
9
- require 'cucumber'
10
- require 'mysql2'
11
- require 'httparty'
12
- require 'csv'
13
- require 'rack/utf8_sanitizer'
14
- require 'rautomation'
15
- require 'net/https'
16
- include RbConfig
17
-
18
- require_relative 'misc_methods'
19
- require_relative 'error_handling_methods'
20
- require_relative 'core'
21
- require_relative 'database_methods'
22
- require_relative 'db_utils'
23
- require_relative 'IFD_Assertion_methods'
24
- require_relative 'IFD_Connection'
25
- require_relative 'IFD_email_methods'
26
- require_relative 'IFD_webservice'
27
- require_relative 'javascript_handling_methods'
28
- require_relative 'lib_var'
29
- require_relative 'util'
30
- require_relative 'web_methods'
31
- require_relative 'web_service_methods'
32
-
33
-
1
+ require 'rubygems'
2
+ require 'selenium-webdriver'
3
+ require 'chunky_png'
4
+ require 'open-uri'
5
+ require 'rbconfig'
6
+ require 'appium_lib'
7
+ require 'rubygems'
8
+ require 'yaml'
9
+ require 'cucumber'
10
+ require 'mysql2'
11
+ require 'httparty'
12
+ require 'csv'
13
+ require 'rack/utf8_sanitizer'
14
+ require 'rautomation'
15
+ require 'net/https'
16
+ include RbConfig
17
+
18
+ require_relative 'misc_methods'
19
+ require_relative 'error_handling_methods'
20
+ require_relative 'core'
21
+ require_relative 'database_methods'
22
+ require_relative 'db_utils'
23
+ require_relative 'IFD_Assertion_methods'
24
+ require_relative 'IFD_Connection'
25
+ require_relative 'IFD_email_methods'
26
+ require_relative 'IFD_webservice'
27
+ require_relative 'javascript_handling_methods'
28
+ require_relative 'lib_var'
29
+ require_relative 'util'
30
+ require_relative 'web_methods'
31
+ require_relative 'web_service_methods'
32
+
33
+
@@ -1,291 +1,291 @@
1
- require 'net/https'
2
- require_relative 'required_files'
3
-
4
- # This file contains assertion methods which are called from assertion_steps.rb
5
-
6
- # Method to return page title
7
- def get_page_title
8
- page.title
9
- end
10
-
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}, Expected Page Title : #{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
25
- end
26
-
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
41
- end
42
-
43
-
44
- # Open Browser with config-able maximize browser option
45
- def execute_openbrowser url_site #, redirect
46
- begin
47
- if $_CFWEB['Maximize Browser'] == true
48
- page.driver.browser.manage.window.maximize
49
- end
50
- rescue StandardError => myStandardError
51
- put_log "\n>>> Error: #{myStandardError}"
52
- end
53
-
54
- if url_site == ""
55
- visit("")
56
- else
57
- visit(url_site)
58
- end
59
- end
60
-
61
- # Click on element
62
- def execute_click element
63
- foundElement = find_object(element)
64
- if foundElement != nil
65
- page.driver.execute_script('window.focus();')
66
- startTime = Time.new.to_i
67
- begin
68
- sleep(0.5)
69
- currentTime = Time.new.to_i
70
- end while (foundElement.native.enabled? == false and (currentTime - startTime) < $_CFWEB['Wait Time'])
71
- page.driver.browser.execute_script("arguments[0].scrollIntoView(true);", foundElement.native)
72
- page.driver.browser.mouse.click(foundElement.native)
73
- else
74
- put_log "\nError >> Not found object: #{element}"
75
- end
76
- end
77
-
78
- # Set option state with state value True/False
79
- def execute_setstate element, state
80
- foundElement = find_object(element)
81
- if foundElement != nil
82
- if state.upcase == "TRUE"
83
- foundElement.set(true)
84
- else
85
- foundElement.set(false)
86
- end
87
- else
88
- put_log "\nError >> Not found object: #{element}"
89
- exit
90
- end
91
- end
92
-
93
- #Enter text to element
94
- def execute_settext element, text
95
- foundElement = find_object(element)
96
- if foundElement != nil
97
- begin
98
- foundElement.set(text)
99
- #page.driver.browser.mouse.click(foundElement.native)
100
- #foundElement.native.send_keys(text)
101
- # put_log "\nfoundElement.value: #{foundElement.value}"
102
- #foundElement.native.send_keys([:tab])
103
- rescue StandardError => myStandardError
104
- put_log "\n>>> Error: #{myStandardError}"
105
- end
106
- else
107
- put_log "\nError >> Not found object: #{element}"
108
- exit
109
- end
110
- end
111
-
112
- # Move mouse to element then click
113
- def execute_mousehoverandclick element
114
- foundElement = find_object(element)
115
- if foundElement != nil
116
- page.driver.browser.mouse.move_to(foundElement.native, element)
117
- page.driver.browser.mouse.click(foundElement.native)
118
- sleep(2)
119
- else
120
- put_log "\nError >> Not found object: #{element}"
121
- end
122
- end
123
-
124
- def execute_drag_to_new_object from_element, element
125
- found_from_element = find_object(from_element)
126
- foundElement = find_object(element)
127
- if foundElement != nil and found_from_element != nil
128
- found_from_element.drag_to(foundElement)
129
- end
130
- end
131
-
132
- def execute_hover_mouse_on element
133
- foundElement = find_object(element)
134
- if foundElement != nil
135
- page.driver.browser.mouse.move_to(foundElement.native, element)
136
- sleep 1
137
- else
138
- put_log "\nError >> Not found object: #{element}"
139
- end
140
- end
141
-
142
- def execute_click_to_upload object, file_name
143
- upload_file = ($test_data_dir + file_name).gsub!(/\//, "\\")
144
- foundElement = find_object(object)
145
- if foundElement != nil
146
- call_step("I click on \"#{object}\"")
147
- window = RAutomation::Window.new(:title => /File Upload/)
148
- window.text_field(:class => "Edit").set(upload_file)
149
- window.button(:value => "&Open").click
150
- else
151
- raise "Error >> Object #{object} not found.!"
152
- end
153
- end
154
-
155
- # Check exists
156
- def execute_checkexists negate, element, timeout
157
- origin_timeout = $_CFWEB['Wait Time']
158
- set_time_out(timeout)
159
- foundElement = find_object(element)
160
- set_time_out(origin_timeout)
161
- #put_log "\nexecute_checkexists : #{foundElement}"
162
- check = false
163
- if foundElement != nil
164
- check = true
165
- end
166
-
167
- negate = negate.strip if negate != nil
168
- #puts "---------->#{negate}"
169
- if negate == "not"
170
- # check.should_not eq true
171
- expect(check).not_to eql true
172
- elsif check.should eq true
173
- expect(check).to eq true
174
- end
175
- end
176
-
177
- # Send Key
178
- def execute_sendkeys element, text
179
- foundElement = find_object(element)
180
- if foundElement != nil
181
- if foundElement[:disabled] == ''
182
- if text == ":down"
183
- foundElement.native.send_keys([:down])
184
- elsif text == ":enter"
185
- foundElement.native.send_keys([:enter])
186
- elsif text == ":tab"
187
- foundElement.native.send_keys([:tab])
188
- else
189
- foundElement.native.send_keys(text)
190
- end
191
- end
192
- else
193
- put_log "\nError >> Not found object: #{element}"
194
- exit
195
- end
196
- end
197
-
198
- # method to scroll page to top or end
199
- def scroll_page(to)
200
- if to == 'end'
201
- page.driver.execute_script('window.scrollTo(0,Math.max(document.documentElement.scrollHeight,document.body.scrollHeight,document.documentElement.clientHeight));')
202
- elsif to == 'top'
203
- page.driver.execute_script('window.scrollTo(Math.max(document.documentElement.scrollHeight,document.body.scrollHeight,document.documentElement.clientHeight),0);')
204
- else
205
- raise "Exception : Invalid Direction (only scroll \"top\" or \"end\")"
206
- end
207
- end
208
-
209
- # Method to return element status - enabled?
210
- # param 1 : String : Locator type (id, name, class, xpath, css)
211
- # param 2 : String : Locator value
212
- def is_element_enabled(element)
213
- foundElement = find_object(element)
214
- expect(foundElement).to be_visible
215
- end
216
-
217
- # Element enabled checking
218
- # param 1 : String : Expected element text
219
- # param 2 : Boolean : test case [true or flase]
220
- def check_element_enable(element, test_case)
221
- result = is_element_enabled(element)
222
-
223
- if test_case
224
- raise TestCaseFailed, 'Element Not Enabled' unless result
225
- else
226
- raise TestCaseFailed, 'Element Enabled' unless !result
227
- end
228
- end
229
-
230
-
231
- # method to assert checkbox check/uncheck
232
- # param 1 : String : Locator value
233
- # param 2 : Boolean : test case [true or flase]
234
- def is_checkbox_checked(element, should_be_checked = true)
235
- foundElement = find_object(element)
236
- checkbox = expect(foundElement).to be_checked
237
-
238
- if !checkbox && should_be_checked
239
- raise TestCaseFailed, 'Checkbox is not checked'
240
- elsif checkbox && !should_be_checked
241
- raise TestCaseFailed, 'Checkbox is checked'
242
- end
243
- end
244
-
245
- # method to assert radio button selected/unselected
246
- # param 1 : String : Locator value
247
- # param 2 : Boolean : test case [true or flase]
248
- def is_radio_button_selected(element, should_be_selected = true)
249
- foundElement = find_object(element)
250
- radio = expect(foundElement).to be_checked
251
-
252
- if !radio && should_be_selected
253
- raise TestCaseFailed, 'Radio Button not selected'
254
- elsif radio && !should_be_selected
255
- raise TestCaseFailed, 'Radio Button is selected'
256
- end
257
- end
258
-
259
- def double_click(element)
260
- foundElement = find_object(element)
261
- page.driver.browser.mouse.double_click(foundElement.native)
262
- end
263
-
264
- # Method to maximize browser
265
- def maximize_browser
266
- page.driver.browser.manage.window.maximize
267
- end
268
-
269
- # Method to switch to window by title
270
- def switch_to_window_by_title window_title
271
- $previous_window = page.driver.browser.window_handle
272
- window_found = false
273
- page.driver.browser.window_handles.each{ |handle|
274
- page.driver.browser.switch_to.window handle
275
- if page.title == window_title
276
- window_found = true
277
- break
278
- end
279
- }
280
- raise "Window having title \"#{window_title}\" not found" if not window_found
281
- end
282
-
283
- # Method to resize browser
284
- def resize_browser(width, heigth)
285
- page.driver.browser.manage.window.resize_to(width, heigth)
286
- end
287
-
288
- def take_screenshot
289
- cur_time = Time.now.strftime('%Y%m%d%H%M%S%L')
290
- page.driver.browser.save_screenshot($test_data_dir + '/screenshots/screenshot' + cur_time + '.png')
291
- end
1
+ require 'net/https'
2
+ require_relative 'required_files'
3
+
4
+ # This file contains assertion methods which are called from assertion_steps.rb
5
+
6
+ # Method to return page title
7
+ def get_page_title
8
+ page.title
9
+ end
10
+
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}, Expected Page Title : #{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
25
+ end
26
+
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
41
+ end
42
+
43
+
44
+ # Open Browser with config-able maximize browser option
45
+ def execute_openbrowser url_site #, redirect
46
+ begin
47
+ if $_CFWEB['Maximize Browser'] == true
48
+ page.driver.browser.manage.window.maximize
49
+ end
50
+ rescue StandardError => myStandardError
51
+ put_log "\n>>> Error: #{myStandardError}"
52
+ end
53
+
54
+ if url_site == ""
55
+ visit("")
56
+ else
57
+ visit(url_site)
58
+ end
59
+ end
60
+
61
+ # Click on element
62
+ def execute_click element
63
+ foundElement = find_object(element)
64
+ if foundElement != nil
65
+ page.driver.execute_script('window.focus();')
66
+ startTime = Time.new.to_i
67
+ begin
68
+ sleep(0.5)
69
+ currentTime = Time.new.to_i
70
+ end while (foundElement.native.enabled? == false and (currentTime - startTime) < $_CFWEB['Wait Time'])
71
+ page.driver.browser.execute_script("arguments[0].scrollIntoView(true);", foundElement.native)
72
+ page.driver.browser.mouse.click(foundElement.native)
73
+ else
74
+ put_log "\nError >> Not found object: #{element}"
75
+ end
76
+ end
77
+
78
+ # Set option state with state value True/False
79
+ def execute_setstate element, state
80
+ foundElement = find_object(element)
81
+ if foundElement != nil
82
+ if state.upcase == "TRUE"
83
+ foundElement.set(true)
84
+ else
85
+ foundElement.set(false)
86
+ end
87
+ else
88
+ put_log "\nError >> Not found object: #{element}"
89
+ exit
90
+ end
91
+ end
92
+
93
+ #Enter text to element
94
+ def execute_settext element, text
95
+ foundElement = find_object(element)
96
+ if foundElement != nil
97
+ begin
98
+ foundElement.set(text)
99
+ #page.driver.browser.mouse.click(foundElement.native)
100
+ #foundElement.native.send_keys(text)
101
+ # put_log "\nfoundElement.value: #{foundElement.value}"
102
+ #foundElement.native.send_keys([:tab])
103
+ rescue StandardError => myStandardError
104
+ put_log "\n>>> Error: #{myStandardError}"
105
+ end
106
+ else
107
+ put_log "\nError >> Not found object: #{element}"
108
+ exit
109
+ end
110
+ end
111
+
112
+ # Move mouse to element then click
113
+ def execute_mousehoverandclick element
114
+ foundElement = find_object(element)
115
+ if foundElement != nil
116
+ page.driver.browser.mouse.move_to(foundElement.native, element)
117
+ page.driver.browser.mouse.click(foundElement.native)
118
+ sleep(2)
119
+ else
120
+ put_log "\nError >> Not found object: #{element}"
121
+ end
122
+ end
123
+
124
+ def execute_drag_to_new_object from_element, element
125
+ found_from_element = find_object(from_element)
126
+ foundElement = find_object(element)
127
+ if foundElement != nil and found_from_element != nil
128
+ found_from_element.drag_to(foundElement)
129
+ end
130
+ end
131
+
132
+ def execute_hover_mouse_on element
133
+ foundElement = find_object(element)
134
+ if foundElement != nil
135
+ page.driver.browser.mouse.move_to(foundElement.native, element)
136
+ sleep 1
137
+ else
138
+ put_log "\nError >> Not found object: #{element}"
139
+ end
140
+ end
141
+
142
+ def execute_click_to_upload object, file_name
143
+ upload_file = ($test_data_dir + file_name).gsub!(/\//, "\\")
144
+ foundElement = find_object(object)
145
+ if foundElement != nil
146
+ call_step("I click on \"#{object}\"")
147
+ window = RAutomation::Window.new(:title => /File Upload/)
148
+ window.text_field(:class => "Edit").set(upload_file)
149
+ window.button(:value => "&Open").click
150
+ else
151
+ raise "Error >> Object #{object} not found.!"
152
+ end
153
+ end
154
+
155
+ # Check exists
156
+ def execute_checkexists negate, element, timeout
157
+ origin_timeout = $_CFWEB['Wait Time']
158
+ set_time_out(timeout)
159
+ foundElement = find_object(element)
160
+ set_time_out(origin_timeout)
161
+ #put_log "\nexecute_checkexists : #{foundElement}"
162
+ check = false
163
+ if foundElement != nil
164
+ check = true
165
+ end
166
+
167
+ negate = negate.strip if negate != nil
168
+ #puts "---------->#{negate}"
169
+ if negate == "not"
170
+ # check.should_not eq true
171
+ expect(check).not_to eql true
172
+ elsif check.should eq true
173
+ expect(check).to eq true
174
+ end
175
+ end
176
+
177
+ # Send Key
178
+ def execute_sendkeys element, text
179
+ foundElement = find_object(element)
180
+ if foundElement != nil
181
+ if foundElement[:disabled] == ''
182
+ if text == ":down"
183
+ foundElement.native.send_keys([:down])
184
+ elsif text == ":enter"
185
+ foundElement.native.send_keys([:enter])
186
+ elsif text == ":tab"
187
+ foundElement.native.send_keys([:tab])
188
+ else
189
+ foundElement.native.send_keys(text)
190
+ end
191
+ end
192
+ else
193
+ put_log "\nError >> Not found object: #{element}"
194
+ exit
195
+ end
196
+ end
197
+
198
+ # method to scroll page to top or end
199
+ def scroll_page(to)
200
+ if to == 'end'
201
+ page.driver.execute_script('window.scrollTo(0,Math.max(document.documentElement.scrollHeight,document.body.scrollHeight,document.documentElement.clientHeight));')
202
+ elsif to == 'top'
203
+ page.driver.execute_script('window.scrollTo(Math.max(document.documentElement.scrollHeight,document.body.scrollHeight,document.documentElement.clientHeight),0);')
204
+ else
205
+ raise "Exception : Invalid Direction (only scroll \"top\" or \"end\")"
206
+ end
207
+ end
208
+
209
+ # Method to return element status - enabled?
210
+ # param 1 : String : Locator type (id, name, class, xpath, css)
211
+ # param 2 : String : Locator value
212
+ def is_element_enabled(element)
213
+ foundElement = find_object(element)
214
+ expect(foundElement).to be_visible
215
+ end
216
+
217
+ # Element enabled checking
218
+ # param 1 : String : Expected element text
219
+ # param 2 : Boolean : test case [true or flase]
220
+ def check_element_enable(element, test_case)
221
+ result = is_element_enabled(element)
222
+
223
+ if test_case
224
+ raise TestCaseFailed, 'Element Not Enabled' unless result
225
+ else
226
+ raise TestCaseFailed, 'Element Enabled' unless !result
227
+ end
228
+ end
229
+
230
+
231
+ # method to assert checkbox check/uncheck
232
+ # param 1 : String : Locator value
233
+ # param 2 : Boolean : test case [true or flase]
234
+ def is_checkbox_checked(element, should_be_checked = true)
235
+ foundElement = find_object(element)
236
+ checkbox = expect(foundElement).to be_checked
237
+
238
+ if !checkbox && should_be_checked
239
+ raise TestCaseFailed, 'Checkbox is not checked'
240
+ elsif checkbox && !should_be_checked
241
+ raise TestCaseFailed, 'Checkbox is checked'
242
+ end
243
+ end
244
+
245
+ # method to assert radio button selected/unselected
246
+ # param 1 : String : Locator value
247
+ # param 2 : Boolean : test case [true or flase]
248
+ def is_radio_button_selected(element, should_be_selected = true)
249
+ foundElement = find_object(element)
250
+ radio = expect(foundElement).to be_checked
251
+
252
+ if !radio && should_be_selected
253
+ raise TestCaseFailed, 'Radio Button not selected'
254
+ elsif radio && !should_be_selected
255
+ raise TestCaseFailed, 'Radio Button is selected'
256
+ end
257
+ end
258
+
259
+ def double_click(element)
260
+ foundElement = find_object(element)
261
+ page.driver.browser.mouse.double_click(foundElement.native)
262
+ end
263
+
264
+ # Method to maximize browser
265
+ def maximize_browser
266
+ page.driver.browser.manage.window.maximize
267
+ end
268
+
269
+ # Method to switch to window by title
270
+ def switch_to_window_by_title window_title
271
+ $previous_window = page.driver.browser.window_handle
272
+ window_found = false
273
+ page.driver.browser.window_handles.each{ |handle|
274
+ page.driver.browser.switch_to.window handle
275
+ if page.title == window_title
276
+ window_found = true
277
+ break
278
+ end
279
+ }
280
+ raise "Window having title \"#{window_title}\" not found" if not window_found
281
+ end
282
+
283
+ # Method to resize browser
284
+ def resize_browser(width, heigth)
285
+ page.driver.browser.manage.window.resize_to(width, heigth)
286
+ end
287
+
288
+ def take_screenshot
289
+ cur_time = Time.now.strftime('%Y%m%d%H%M%S%L')
290
+ page.driver.browser.save_screenshot($test_data_dir + '/screenshots/screenshot' + cur_time + '.png')
291
+ end