Ifd_Automation 1.9.2 → 2.0
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 +4 -4
- data/bin/documentation_generator.rb +1 -1
- data/lib/Ifd_Automation/REST_steps.rb +105 -0
- data/lib/Ifd_Automation/SOAP_steps.rb +54 -0
- data/lib/Ifd_Automation/database_steps.rb +17 -47
- data/lib/Ifd_Automation/dynamic_store_vavue_steps.rb +25 -0
- data/lib/Ifd_Automation/email_steps.rb +32 -36
- data/lib/Ifd_Automation/file_steps.rb +7 -58
- data/lib/Ifd_Automation/require_libs.rb +6 -0
- data/lib/Ifd_Automation/ssh_steps.rb +14 -23
- data/lib/Ifd_Automation/version.rb +1 -1
- data/lib/Ifd_Automation/web_steps.rb +58 -293
- data/lib/helper/assertion_helpers.rb +100 -0
- data/lib/helper/auto_utils.rb +67 -0
- data/lib/{Ifd_Automation_support → helper}/connection_helpers.rb +2 -2
- data/lib/{Ifd_Automation_support → helper}/core.rb +154 -60
- data/lib/{Ifd_Automation_support → helper}/mail_helpers.rb +2 -2
- data/lib/helper/web_steps_helpers.rb +123 -0
- data/project/Gemfile +1 -2
- data/project/features/Screenshot/failed_sample.png +0 -0
- data/project/features/TestData/globalData.yml +4 -1
- data/project/features/TestSuite/test.feature +1 -4
- data/project/features/step_definitions/lib_steps/test.rb +5 -3
- data/project/features/step_definitions/repositories/project_object.yml +2 -2
- data/project/features/support/env.rb +53 -52
- data/project/features/support/hooks.rb +2 -0
- data/project/features/support/project_config.yml +6 -6
- metadata +36 -148
- data/lib/Ifd_Automation/javascript_steps.rb +0 -33
- data/lib/Ifd_Automation/required_libs.rb +0 -7
- data/lib/Ifd_Automation/response.rb +0 -105
- data/lib/Ifd_Automation/webservice_steps.rb +0 -281
- data/lib/Ifd_Automation_support/assertion_helpers.rb +0 -205
- data/lib/Ifd_Automation_support/javascript_helpers.rb +0 -45
- data/lib/Ifd_Automation_support/selenium_sync_issues.rb +0 -62
- data/lib/Ifd_Automation_support/web_steps_helpers.rb +0 -296
- data/project/Gemfile.lock +0 -203
- data/project/Rakefile +0 -46
@@ -0,0 +1,67 @@
|
|
1
|
+
#-----------------------------------------------------
|
2
|
+
# support define and bind variable dynamically
|
3
|
+
#-----------------------------------------------------
|
4
|
+
$dyn_vars = nil
|
5
|
+
|
6
|
+
# set value to a variable
|
7
|
+
def set_var(var_name, var_value)
|
8
|
+
if $dyn_vars == nil
|
9
|
+
$dyn_vars = binding
|
10
|
+
end
|
11
|
+
|
12
|
+
strEval = var_name + "=" + var_value
|
13
|
+
eval strEval, $dyn_vars
|
14
|
+
end
|
15
|
+
|
16
|
+
# bind string with $dyn_vars context
|
17
|
+
def bind_with_dyn_vars(str)
|
18
|
+
if $dyn_vars == nil
|
19
|
+
$dyn_vars = binding
|
20
|
+
end
|
21
|
+
|
22
|
+
strEval = '"' + str + '"'
|
23
|
+
return eval strEval, $dyn_vars
|
24
|
+
end
|
25
|
+
|
26
|
+
# evaluate operation/statement with $dyn_vars context
|
27
|
+
def eval_with_dyn_vars(operation)
|
28
|
+
if $dyn_vars == nil
|
29
|
+
$dyn_vars = binding
|
30
|
+
end
|
31
|
+
|
32
|
+
eval operation, $dyn_vars
|
33
|
+
end
|
34
|
+
|
35
|
+
def bind_with_dyn_json_vars(json, bind_json)
|
36
|
+
if json.kind_of? Hash
|
37
|
+
json.each_pair do |k, v|
|
38
|
+
if v.kind_of? String
|
39
|
+
bind_json[bind_with_dyn_vars(k)] = bind_with_dyn_json_vars(v, bind_json)
|
40
|
+
elsif v.kind_of? Hash
|
41
|
+
temp = Hash.new
|
42
|
+
v.each_pair do |k1, v1|
|
43
|
+
temp[bind_with_dyn_vars(k1)] = bind_with_dyn_json_vars(v1, temp)
|
44
|
+
end
|
45
|
+
bind_json[bind_with_dyn_vars(k)] = temp
|
46
|
+
elsif v.kind_of? Array
|
47
|
+
temp1 = Array.new
|
48
|
+
v.each {|item|
|
49
|
+
temp2 = Hash.new
|
50
|
+
bind_with_dyn_json_vars(item, temp2)
|
51
|
+
temp1 << temp2
|
52
|
+
}
|
53
|
+
bind_json[bind_with_dyn_vars(k)] = temp1
|
54
|
+
end
|
55
|
+
end
|
56
|
+
elsif json.kind_of? Array
|
57
|
+
temp1 = Array.new
|
58
|
+
json.each {|item|
|
59
|
+
temp2 = Hash.new
|
60
|
+
bind_with_dyn_json_vars(item, temp2)
|
61
|
+
temp1 << temp2
|
62
|
+
}
|
63
|
+
return temp1
|
64
|
+
else
|
65
|
+
return bind_with_dyn_vars(json)
|
66
|
+
end
|
67
|
+
end
|
@@ -1,10 +1,10 @@
|
|
1
|
-
require 'mysql2'
|
1
|
+
# require 'mysql2'
|
2
2
|
require 'active_record'
|
3
3
|
|
4
4
|
module Connection
|
5
5
|
def self.new(connection_params)
|
6
6
|
begin
|
7
|
-
puts ("Connecting to
|
7
|
+
puts ("Connecting to MYSql database...")
|
8
8
|
return ActiveRecord::Base.establish_connection(connection_params)
|
9
9
|
rescue Exception => e
|
10
10
|
raise e.message
|
@@ -1,69 +1,82 @@
|
|
1
|
-
def
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
resolve_ws_url url
|
7
|
-
when /stored=/
|
8
|
-
resolve_script url
|
9
|
-
else
|
10
|
-
url
|
1
|
+
def check_dynamic_value value
|
2
|
+
if value.include? "params="
|
3
|
+
resolve_params value
|
4
|
+
else
|
5
|
+
bind_with_dyn_vars value
|
11
6
|
end
|
12
7
|
end
|
13
8
|
|
14
|
-
def resolve_params url
|
15
|
-
condition = url.match(/params='([^']*)'/)[0]
|
16
|
-
if condition
|
17
|
-
params_name = url.match(/params='([^']*)'/)[1]
|
18
|
-
params_value = $PARAMS["#{params_name.downcase}"]
|
19
|
-
if params_value
|
20
|
-
url = url.gsub(condition, params_value)
|
21
|
-
else
|
22
|
-
raise "ERROR: no data found with given params #{params_name}"
|
23
|
-
end
|
24
9
|
|
10
|
+
def resolve_params url
|
11
|
+
condition = url.match(/params='([^']*)'/)[0]
|
12
|
+
if condition
|
13
|
+
params_name = url.match(/params='([^']*)'/)[1]
|
14
|
+
params_value = $PARAMS["#{params_name.downcase}"]
|
15
|
+
if params_value
|
16
|
+
url = url.gsub(condition, params_value)
|
17
|
+
else
|
18
|
+
raise "ERROR: no data found with given params #{params_name}"
|
25
19
|
end
|
26
|
-
url
|
27
|
-
end
|
28
|
-
|
29
|
-
# Bind grabbed values into placeholders in given URL
|
30
|
-
# Ex: http://example.com?id={id} with {id => 1} becomes http://example.com?id=1
|
31
|
-
# @param url [String] parameterized URL with placeholders
|
32
|
-
# @return [String] binded URL or original URL if no placeholders
|
33
|
-
def resolve_ws_url url
|
34
|
-
unless @grabbed.nil?
|
35
|
-
matched = url.match(/grabbed='([^']*)'/)[0]
|
36
|
-
@grabbed.each { |key, value| url = url.gsub(matched, %/#{value}/) }
|
37
20
|
end
|
38
21
|
url
|
39
22
|
end
|
40
23
|
|
41
|
-
def resolve_script script
|
42
|
-
unless @stored.nil?
|
43
|
-
matched = script.match(/stored='([^']*)'/)[0]
|
44
|
-
@stored.each { |key, value| script = script.gsub(matched, %/#{value}/) }
|
45
|
-
end
|
46
|
-
script
|
47
|
-
end
|
48
|
-
|
49
24
|
#Print script log to console
|
50
25
|
def put_log str
|
51
26
|
puts str if $_CFWEB['Print Log'] == true
|
52
27
|
end
|
53
28
|
|
54
|
-
|
55
|
-
def
|
56
|
-
|
57
|
-
|
29
|
+
|
30
|
+
def get_xpath_value_from_object_file string_object
|
31
|
+
string_object = string_object.gsub(/"/, "'")
|
32
|
+
# puts "String_object: #{string_object}"
|
33
|
+
locator_matching = /(.*?)(\{.*?\})/.match(string_object)
|
34
|
+
# puts "locator_matching : #{locator_matching}"
|
35
|
+
dyn_pros = {}
|
36
|
+
if locator_matching != nil
|
37
|
+
string_object = locator_matching[1]
|
38
|
+
eval(locator_matching[2].gsub(/['][\s,\t]*?:[\s,\t]*?[']?/, "'=>'")).each { |k, v|
|
39
|
+
dyn_pros[k.to_s.upcase] = v
|
40
|
+
}
|
41
|
+
end
|
42
|
+
|
43
|
+
hash_object = $OBJECT[string_object]
|
44
|
+
if hash_object == nil
|
45
|
+
put_log ">>> OBJECT NAME MAYBE NOT FOUND!!!"
|
46
|
+
# true.should eq false
|
47
|
+
expect(true).to eq(false)
|
48
|
+
end
|
49
|
+
xpath_value = ""
|
50
|
+
upcase_attrb = {}
|
51
|
+
if hash_object != nil
|
52
|
+
hash_object.each { |k, v|
|
53
|
+
k = k.to_s.upcase
|
54
|
+
# put_log "\n#{k} =~ /ph_/i and dyn_pros[#{k}]: #{k =~ /ph_/i and dyn_pros[k] != nil}"
|
55
|
+
if k =~ /ph_/i
|
56
|
+
if dyn_pros[k] != nil
|
57
|
+
# Assign place holder value to place holder property, also remove prefix ph_ from property key,
|
58
|
+
# also remove this pl from dyn_pros <= should be consider to continue transfer into inner object in relation
|
59
|
+
if v =~ /<ph_value>/i
|
60
|
+
upcase_attrb[k[3..k.size-1]] = v.gsub(/<ph_value>/i, dyn_pros[k])
|
61
|
+
else
|
62
|
+
upcase_attrb[k[3..k.size-1]] = dyn_pros[k]
|
63
|
+
end
|
64
|
+
dyn_pros.delete(k)
|
65
|
+
end
|
66
|
+
else
|
67
|
+
upcase_attrb[k.to_s.upcase] = v
|
68
|
+
end
|
69
|
+
xpath_value = v
|
70
|
+
}
|
71
|
+
end
|
72
|
+
xpath_value
|
58
73
|
end
|
59
74
|
|
60
75
|
# Find object by Xpath
|
61
76
|
def find_object string_object
|
62
77
|
startTime = Time.new.to_i
|
63
78
|
string_object = string_object.gsub(/"/, "'")
|
64
|
-
# puts "String_object: #{string_object}"
|
65
79
|
locator_matching = /(.*?)(\{.*?\})/.match(string_object)
|
66
|
-
# puts "locator_matching : #{locator_matching}"
|
67
80
|
dyn_pros = {}
|
68
81
|
if locator_matching != nil
|
69
82
|
string_object = locator_matching[1]
|
@@ -72,7 +85,6 @@ def find_object string_object
|
|
72
85
|
}
|
73
86
|
end
|
74
87
|
|
75
|
-
# put_log "\n---dyn_pros: #{dyn_pros}"
|
76
88
|
hash_object = $OBJECT[string_object]
|
77
89
|
if hash_object == nil
|
78
90
|
put_log ">>> OBJECT NAME MAYBE NOT FOUND!!!"
|
@@ -117,11 +129,11 @@ def find_object string_object
|
|
117
129
|
strXpathSelector = value
|
118
130
|
end
|
119
131
|
}
|
120
|
-
continue_run = true
|
132
|
+
continue_run = true
|
121
133
|
|
122
134
|
if continue_run == true
|
123
135
|
begin
|
124
|
-
if strXpathSelector != nil and strXpathSelector.
|
136
|
+
if strXpathSelector != nil and strXpathSelector.size > 0
|
125
137
|
foundElements = get_objects_by_XpathSelector(strXpathSelector)
|
126
138
|
else
|
127
139
|
#Generate Selector
|
@@ -132,7 +144,7 @@ def find_object string_object
|
|
132
144
|
end
|
133
145
|
end
|
134
146
|
|
135
|
-
if foundElements == nil or foundElements.
|
147
|
+
if foundElements == nil or foundElements.size == 0
|
136
148
|
currentTime = Time.new.to_i
|
137
149
|
else
|
138
150
|
# put_log "\nBREAK!!!"
|
@@ -143,7 +155,7 @@ def find_object string_object
|
|
143
155
|
sleep(0.5)
|
144
156
|
end while (currentTime - startTime) < $_CFWEB['Wait Time']
|
145
157
|
|
146
|
-
if foundElements != nil or foundElements.
|
158
|
+
if foundElements != nil or foundElements.size != 0
|
147
159
|
if index != nil and index.to_i >= 0
|
148
160
|
matched_index = 0;
|
149
161
|
return_element = nil
|
@@ -251,7 +263,7 @@ def execute_checkproperty element, property, negate, value, isSpecialChar=false
|
|
251
263
|
# check.should eq true
|
252
264
|
expect(check).to eq true
|
253
265
|
else
|
254
|
-
put_log "\n\n\t>>> execute_checkproperty: finish to found element"
|
266
|
+
# put_log "\n\n\t>>> execute_checkproperty: finish to found element"
|
255
267
|
if foundElement != nil
|
256
268
|
if property.upcase == 'VALUE'
|
257
269
|
actual_value = foundElement.value()
|
@@ -314,22 +326,94 @@ def execute_checkproperty element, property, negate, value, isSpecialChar=false
|
|
314
326
|
config.ignore_hidden_elements = true
|
315
327
|
end
|
316
328
|
|
317
|
-
if
|
329
|
+
if Assertion.reg_compare(actual_value, value, isSpecialChar)
|
318
330
|
check = true
|
319
331
|
end
|
320
332
|
|
321
|
-
put_log "\n#{property} :: Actual result is '#{actual_value}' -- Expected result is '#{value}'"
|
333
|
+
put_log "\n#{property} :: Actual result is: '#{actual_value}' -- Expected result is: '#{value}'"
|
322
334
|
|
323
335
|
if negate == " not"
|
324
336
|
# check.should_not eq true
|
325
|
-
expect(check).not_to eql true
|
337
|
+
# expect(check).not_to eql true
|
338
|
+
!Assertion.assert_string_not_equal(actual_value,value)
|
326
339
|
elsif
|
327
340
|
# check.should eq true
|
328
|
-
|
341
|
+
# expect(check).to eq true
|
342
|
+
Assertion.assert_string_equal(actual_value,value)
|
329
343
|
end
|
330
344
|
end
|
331
345
|
end
|
332
346
|
|
347
|
+
def execute_getproperty element, property
|
348
|
+
Capybara.configure do |config|
|
349
|
+
config.ignore_hidden_elements = false
|
350
|
+
end
|
351
|
+
foundElement = find_object(element)
|
352
|
+
|
353
|
+
check = false
|
354
|
+
if foundElement == nil and value == ""
|
355
|
+
check = true
|
356
|
+
# check.should eq true
|
357
|
+
expect(check).to eq true
|
358
|
+
else
|
359
|
+
# put_log "\n\n\t>>> execute_getproperty: finish to found element"
|
360
|
+
if foundElement != nil
|
361
|
+
if property.upcase == 'VALUE'
|
362
|
+
actual_value = foundElement.value()
|
363
|
+
|
364
|
+
elsif property.upcase == 'TEXT'
|
365
|
+
actual_value = foundElement.text()
|
366
|
+
|
367
|
+
elsif property.upcase == 'TAGNAME'
|
368
|
+
actual_value = foundElement.tag_name()
|
369
|
+
|
370
|
+
elsif property.upcase == 'STYLE'
|
371
|
+
actual_value = foundElement[:style]
|
372
|
+
|
373
|
+
elsif property.upcase == 'DISABLED'
|
374
|
+
actual_value = foundElement[:disabled]
|
375
|
+
|
376
|
+
elsif property.upcase == 'WIDTH'
|
377
|
+
actual_value = foundElement[:width]
|
378
|
+
|
379
|
+
elsif property.upcase == 'HEIGHT'
|
380
|
+
actual_value = foundElement[:height]
|
381
|
+
|
382
|
+
elsif property.upcase == 'ID'
|
383
|
+
actual_value = foundElement[:id]
|
384
|
+
|
385
|
+
elsif property.upcase == 'NAME'
|
386
|
+
actual_value = foundElement[:name]
|
387
|
+
|
388
|
+
elsif property.upcase == 'CLASS'
|
389
|
+
actual_value = foundElement[:class]
|
390
|
+
|
391
|
+
elsif property.upcase == 'HREF'
|
392
|
+
actual_value = foundElement[:href]
|
393
|
+
|
394
|
+
elsif property.upcase == 'TITLE'
|
395
|
+
actual_value = foundElement[:title]
|
396
|
+
|
397
|
+
elsif property.upcase == 'TYPE'
|
398
|
+
actual_value = foundElement[:type]
|
399
|
+
|
400
|
+
else
|
401
|
+
actual_value = foundElement["#{property}"]
|
402
|
+
end
|
403
|
+
|
404
|
+
if actual_value == nil
|
405
|
+
actual_value = ''
|
406
|
+
end
|
407
|
+
else
|
408
|
+
put_log "\nError >> Not found object: #{element}"
|
409
|
+
end
|
410
|
+
|
411
|
+
Capybara.configure do |config|
|
412
|
+
config.ignore_hidden_elements = true
|
413
|
+
end
|
414
|
+
actual_value
|
415
|
+
end
|
416
|
+
end
|
333
417
|
# Get text from web element
|
334
418
|
def execute_gettext element
|
335
419
|
foundElement = find_object(element)
|
@@ -353,11 +437,6 @@ def execute_gettext element
|
|
353
437
|
end
|
354
438
|
end
|
355
439
|
|
356
|
-
def set_time_out(timeout)
|
357
|
-
$_CFWEB['Wait Time'] = timeout
|
358
|
-
Capybara.default_wait_time = $_CFWEB['Wait Time']
|
359
|
-
end
|
360
|
-
|
361
440
|
def var_collect string_var
|
362
441
|
if string_var =~ /^.*{year}.*$/
|
363
442
|
string_var = replace_year(string_var)
|
@@ -412,3 +491,18 @@ def replace_pipe str_pipe
|
|
412
491
|
end
|
413
492
|
return str_pipe
|
414
493
|
end
|
494
|
+
|
495
|
+
# Select
|
496
|
+
def execute_select element, text
|
497
|
+
#select(text, :xpath => element)
|
498
|
+
foundElement = find_object(element)
|
499
|
+
|
500
|
+
if foundElement != nil
|
501
|
+
option_value = page.evaluate_script("$(\"##{foundElement[:id]} option:contains('#{text}')\").val()")
|
502
|
+
page.execute_script("$('##{foundElement[:id]}').val('#{option_value}')")
|
503
|
+
page.execute_script("$('##{foundElement[:id]}').trigger('liszt:updated').trigger('change')")
|
504
|
+
else
|
505
|
+
put_log "\nError >> Not found object: #{element}"
|
506
|
+
exit
|
507
|
+
end
|
508
|
+
end
|
@@ -2,12 +2,12 @@ require 'mail'
|
|
2
2
|
# require 'email_spec'
|
3
3
|
# include EmailSpec::Helpers
|
4
4
|
# include EmailSpec::Matcher
|
5
|
-
class
|
5
|
+
class Email
|
6
6
|
def self.send_email(to_address, subject, body_email, attachments)
|
7
7
|
include Mail::Matchers
|
8
8
|
# Mail::TestMailer.deliveries.clear
|
9
9
|
Mail.deliver do
|
10
|
-
from "
|
10
|
+
from "abc@gmail.com"
|
11
11
|
to to_address if to_address
|
12
12
|
subject subject if subject
|
13
13
|
body body_email if body_email
|
@@ -0,0 +1,123 @@
|
|
1
|
+
require 'net/https'
|
2
|
+
|
3
|
+
# Open Browser with config-able maximize browser option
|
4
|
+
def execute_openbrowser url_site #, redirect
|
5
|
+
begin
|
6
|
+
if $_CFWEB['Maximize Browser'] == true
|
7
|
+
page.driver.browser.manage.window.maximize
|
8
|
+
end
|
9
|
+
rescue StandardError => myStandardError
|
10
|
+
raise "\n>>> Error: #{myStandardError}"
|
11
|
+
end
|
12
|
+
|
13
|
+
if url_site == ""
|
14
|
+
raise "\n>>> Error: Null web page URL."
|
15
|
+
else
|
16
|
+
visit(url_site)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
# Click on element
|
21
|
+
def execute_click element
|
22
|
+
foundElement = find_object(element)
|
23
|
+
if foundElement != nil
|
24
|
+
page.driver.execute_script('window.focus();')
|
25
|
+
startTime = Time.new.to_i
|
26
|
+
begin
|
27
|
+
sleep(0.5)
|
28
|
+
currentTime = Time.new.to_i
|
29
|
+
end while (foundElement.native.enabled? == false and (currentTime - startTime) < $_CFWEB['Wait Time'])
|
30
|
+
page.driver.browser.execute_script("arguments[0].scrollIntoView(true);", foundElement.native)
|
31
|
+
page.driver.browser.action.click(foundElement.native)
|
32
|
+
foundElement.native.send_keys(:return)
|
33
|
+
else
|
34
|
+
raise "\nError >> Not found object: #{element}"
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
def double_click(element)
|
39
|
+
foundElement = find_object(element)
|
40
|
+
if foundElement != nil
|
41
|
+
begin
|
42
|
+
page.driver.browser.action.double_click(foundElement.native)
|
43
|
+
rescue StandardError => myStandardError
|
44
|
+
raise "\n>>> Error: #{myStandardError}"
|
45
|
+
end
|
46
|
+
else
|
47
|
+
raise "\nError >> Not found object: #{element}"
|
48
|
+
exit
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
#Enter text to element
|
53
|
+
def execute_settext element, text
|
54
|
+
foundElement = find_object(element)
|
55
|
+
if foundElement != nil
|
56
|
+
begin
|
57
|
+
foundElement.set(text)
|
58
|
+
rescue StandardError => myStandardError
|
59
|
+
raise "\n>>> Error: #{myStandardError}"
|
60
|
+
end
|
61
|
+
else
|
62
|
+
raise "\nError >> Not found object: #{element}"
|
63
|
+
exit
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
# Method to maximize browser
|
68
|
+
def maximize_browser
|
69
|
+
page.driver.browser.manage.window.maximize
|
70
|
+
end
|
71
|
+
|
72
|
+
# Method to switch to window by title
|
73
|
+
def switch_to_window_by_title window_title
|
74
|
+
$previous_window = page.driver.browser.window_handle
|
75
|
+
window_found = false
|
76
|
+
page.driver.browser.window_handles.each{ |handle|
|
77
|
+
page.driver.browser.switch_to.window handle
|
78
|
+
if page.title == window_title
|
79
|
+
window_found = true
|
80
|
+
break
|
81
|
+
end
|
82
|
+
}
|
83
|
+
raise "Window having title \"#{window_title}\" not found" if not window_found
|
84
|
+
end
|
85
|
+
|
86
|
+
# method to scroll page to top or end
|
87
|
+
def scroll_page(to)
|
88
|
+
if to == 'end'
|
89
|
+
page.driver.execute_script('window.scrollTo(0,Math.max(document.documentElement.scrollHeight,document.body.scrollHeight,document.documentElement.clientHeight));')
|
90
|
+
elsif to == 'top'
|
91
|
+
page.driver.execute_script('window.scrollTo(Math.max(document.documentElement.scrollHeight,document.body.scrollHeight,document.documentElement.clientHeight),0);')
|
92
|
+
else
|
93
|
+
raise "Exception : Invalid Direction (only scroll \"top\" or \"end\")"
|
94
|
+
end
|
95
|
+
end
|
96
|
+
|
97
|
+
Then /^I should( not)? see page title as (.*)$/ do |present, title|
|
98
|
+
check_title(title, present.empty?)
|
99
|
+
end
|
100
|
+
|
101
|
+
# Method to verify title
|
102
|
+
# param 1 : String : expected title
|
103
|
+
# param 2 : Boolean : test case [true or flase]
|
104
|
+
def check_title(title, test_case)
|
105
|
+
page_title = page.title
|
106
|
+
if test_case
|
107
|
+
if page_title != "#{title}"
|
108
|
+
raise "Page Title Not Matched, Actual Page Title : #{page_title}, Expected Page Title : #{title}"
|
109
|
+
end
|
110
|
+
else
|
111
|
+
if page_title == "#{title}"
|
112
|
+
raise "Page Title Matched, Actual Page Title: #{page_title}"
|
113
|
+
end
|
114
|
+
end
|
115
|
+
end
|
116
|
+
|
117
|
+
# method to check javascript pop-up alert text
|
118
|
+
def check_alert_text(text)
|
119
|
+
alert = page.driver.browser.switch_to.alert.text
|
120
|
+
if alert != text
|
121
|
+
raise "Text on alert pop up not matched, Actual Text : #{alert}, Expected Text : #{text}"
|
122
|
+
end
|
123
|
+
end
|