watir_helper 0.1.2 → 1.0.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 +15 -0
- data/README +58 -110
- data/lib/watir_helper.rb +2 -9
- data/lib/watir_helper/browser_helper.rb +42 -30
- data/lib/watir_helper/button_helper.rb +17 -20
- data/lib/watir_helper/checkbox_helper.rb +14 -16
- data/lib/watir_helper/common_helpers.rb +7 -6
- data/lib/watir_helper/data_type_validations.rb +36 -0
- data/lib/watir_helper/div_helper.rb +16 -19
- data/lib/watir_helper/frame_helper.rb +134 -55
- data/lib/watir_helper/image_helper.rb +16 -19
- data/lib/watir_helper/include_other_helpers.rb +44 -0
- data/lib/watir_helper/link_helper.rb +12 -13
- data/lib/watir_helper/login_helper.rb +16 -19
- data/lib/watir_helper/popup_handling_helper.rb +63 -67
- data/lib/watir_helper/radio_button_helper.rb +14 -16
- data/lib/watir_helper/select_list_helper.rb +16 -19
- data/lib/watir_helper/span_helper.rb +8 -7
- data/lib/watir_helper/table_helper.rb +11 -11
- data/lib/watir_helper/textfield_helper.rb +22 -30
- data/lib/watir_helper/validations_helper.rb +106 -101
- data/test/test_watir_helper.rb +17 -0
- metadata +17 -20
- data/lib/watir_helper/include_all_helpers.rb +0 -51
- data/test/testing_watir_helper.rb +0 -37
- data/test/testing_watir_helper_spec.rb +0 -25
@@ -1,140 +1,145 @@
|
|
1
|
-
|
1
|
+
#******************************************************
|
2
|
+
#Validation methods
|
3
|
+
#******************************************************
|
4
|
+
require File.expand_path('common_helpers', File.dirname(__FILE__))
|
2
5
|
|
3
6
|
module ValidationsHelper
|
4
7
|
|
5
|
-
#
|
6
|
-
def
|
7
|
-
|
8
|
-
|
9
|
-
else
|
10
|
-
puts "Error!!! :-Please input a valid range"
|
11
|
-
end
|
8
|
+
#Invalid date format message
|
9
|
+
def invalid_date_error_type(err_type, obj_type)
|
10
|
+
(err_type == "format") ? (puts "Invalid #{obj_type.downcase} format.") : (puts "#{obj_type} should be a String.")
|
11
|
+
return false
|
12
12
|
end
|
13
13
|
|
14
|
-
#
|
15
|
-
def
|
16
|
-
|
14
|
+
#String contains regular expression or not.
|
15
|
+
def string_contains_reg_exp?(char_string, reg_exp)
|
16
|
+
(char_string =~ reg_exp).nil?
|
17
17
|
end
|
18
18
|
|
19
|
-
#
|
20
|
-
def
|
21
|
-
|
22
|
-
puts "Invalid Date(mmddyyyy) Format"
|
23
|
-
else
|
24
|
-
puts "Valid Date(mmddyyyy) Format"
|
25
|
-
end
|
19
|
+
#Data passed is in valid format or not.
|
20
|
+
def is_valid_data_with_format?(date, reg_ex_date, obj_type)
|
21
|
+
is_string?(date) ? (string_contains_reg_exp?(date, reg_ex_date) ? invalid_date_error_type("format", obj_type) : true) : invalid_date_error_type("data type", obj_type)
|
26
22
|
end
|
27
23
|
|
28
|
-
#Check whether a date is in
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
24
|
+
#Check whether a date is in mmddyyyy format or not.
|
25
|
+
#Valid date format "02/10/2015", "02-10-2015" and "02.10.2015".
|
26
|
+
#For e.g valid_mmddyyyy_date_format?(02-10-2015) will return false(and
|
27
|
+
#print message 'Date should be a String.')
|
28
|
+
#and valid_mmddyyyy_date_format?("02-10-2015") will return true
|
29
|
+
#and valid_mmddyyyy_date_format?("22-10-2015") will return false(and
|
30
|
+
#print message 'Invalid date format.')
|
31
|
+
def valid_mmddyyyy_date_format?(date)
|
32
|
+
is_valid_data_with_format?(date, /^(0[1-9]|1[012])[- \/.](0[1-9]|[12][0-9]|3[01])[- \/.](19|20)\d\d$/, "Date")
|
35
33
|
end
|
36
34
|
|
37
|
-
#Check whether
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
35
|
+
#Check whether a date is in ddmmyyyy format or not.
|
36
|
+
#Valid date format "10/02/2015", "10-02-2015" and "10.02.2015".
|
37
|
+
#For e.g valid_ddmmyyyy_date_format?(10-02-2015) will return false(and
|
38
|
+
#print message 'Date should be a String.')
|
39
|
+
#and valid_ddmmyyyy_date_format?("10-02-2015") will return true
|
40
|
+
#and valid_ddmmyyyy_date_format?("42-10-2015") will return false(and
|
41
|
+
#print message 'Invalid date format.')
|
42
|
+
def valid_ddmmyyyy_date_format?(date)
|
43
|
+
is_valid_data_with_format?(date, /^(0[1-9]|[12][0-9]|3[01])[- \/.](0[1-9]|1[012])[- \/.](19|20)\d\d$/, "Date")
|
44
44
|
end
|
45
45
|
|
46
46
|
#Check whether e-mail adress supplied is valid or not.
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
end
|
47
|
+
#For e.g valid_email_id?("abc123@gmail.com") will return true
|
48
|
+
#and valid_email_id?("abc123gmail.com") will return false(and
|
49
|
+
#print message 'Invalid email format.')
|
50
|
+
def valid_email_id?(email_id)
|
51
|
+
is_valid_data_with_format?(email_id, /^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}$/, "Email")
|
53
52
|
end
|
54
53
|
|
55
|
-
#
|
56
|
-
def
|
57
|
-
|
58
|
-
if(mobile_no.length==10)
|
59
|
-
if(mobile_no=~/^([9]{1})([023456789]{1})([0-9]{8})$/).nil?
|
60
|
-
puts "Wrong Mobile number format"
|
61
|
-
else
|
62
|
-
puts "Correct Mobile number format"
|
63
|
-
end
|
64
|
-
elsif(mobile_no.length<10)
|
65
|
-
puts "Error!!!! :- Mobile number length is less than 10 digit"
|
66
|
-
elsif(mobile_no.length>10)
|
67
|
-
puts "Error!!!! :- Mobile number length is more than 10 digit"
|
68
|
-
end
|
69
|
-
else
|
70
|
-
puts "Error!!!! :- Mobile number can't be negative"
|
71
|
-
end
|
54
|
+
#Mobile no. is of 10 digits or not.
|
55
|
+
def valid_mobile_no_length?(mobile_no)
|
56
|
+
(mobile_no.to_s.length == 10) ? true : (puts "Mobile no. should be of 10 digits.")
|
72
57
|
end
|
73
|
-
|
74
|
-
#
|
75
|
-
def
|
76
|
-
|
77
|
-
#Here we will prefix "0" before std code and "-" between std code and the respective landline number
|
78
|
-
if(landline_no=~/^[0]{1}[1-9]{1}[0-9]{1,3}[\-]{1}[1-9]{1}[0-9]{5,7}$/).nil?
|
79
|
-
puts "Wrong Landline number format"
|
80
|
-
else
|
81
|
-
puts "Correct Landline number format"
|
82
|
-
end
|
83
|
-
else
|
84
|
-
puts "Error!!!! :- Wrong Landline number format"
|
85
|
-
end
|
58
|
+
|
59
|
+
#Mobile no. is valid or not.
|
60
|
+
def is_valid_mobile_no?(mobile_no)
|
61
|
+
(mobile_no.to_i > 0) ? valid_mobile_no_length?(mobile_no) : false
|
86
62
|
end
|
87
63
|
|
88
|
-
#Check whether the
|
89
|
-
|
90
|
-
|
64
|
+
#Check whether the indian mobile number entered is valid or not.
|
65
|
+
#Here valid means mobile no. will have the prefix 9, 8 or 7. It will not
|
66
|
+
#tell whether that number exists or not.
|
67
|
+
#For e.g valid_indian_mobile_number?(9123456789) will return false(and
|
68
|
+
#print message 'Mobile no. should be a String.')
|
69
|
+
# puts valid_indian_mobile_number?("9123456789") will return true
|
70
|
+
# puts valid_indian_mobile_number?("91234567890") will return false(and
|
71
|
+
#print message 'Mobile no. should be of 10 digits.')
|
72
|
+
def valid_indian_mobile_number?(mobile_no)
|
73
|
+
is_valid_mobile_no?(mobile_no) ? is_valid_data_with_format?(mobile_no, /^([9]{1}|[8]{1}|[7]{1})([0-9]{9})$/, "Mobile no.") : false
|
91
74
|
end
|
92
75
|
|
93
|
-
#
|
94
|
-
def
|
95
|
-
|
76
|
+
#Valid length of landline no. or not.
|
77
|
+
def is_valid_length_of_landline_no?(landline_no)
|
78
|
+
(landline_no.to_s.length == 12) ? true : (puts "Landline no. should be of 11 digits(for e.g '0130-1234567').")
|
96
79
|
end
|
97
80
|
|
98
|
-
#
|
99
|
-
def
|
100
|
-
|
81
|
+
#Landline no. is valid or not.
|
82
|
+
def is_valid_landline_no?(landline_no)
|
83
|
+
is_string?(landline_no) ? is_valid_length_of_landline_no?(landline_no) : (puts "Landline no. should be a String.")
|
84
|
+
end
|
85
|
+
|
86
|
+
#Check whether the indian landline number entered is valid or not.
|
87
|
+
#For e.g valid_indian_landline_number?(01303030303) will return false(and
|
88
|
+
#print message 'Landline no. should be a String.')
|
89
|
+
#and valid_indian_landline_number?('0130-3030303') will return true
|
90
|
+
#and valid_indian_landline_number?('0130-30303030') will return false(and
|
91
|
+
#print message 'Landline no. should be of 11 digits(for e.g '0130-1234567').')
|
92
|
+
def valid_indian_landline_number?(landline_no)
|
93
|
+
is_valid_landline_no?(landline_no) ? is_valid_data_with_format?(landline_no, /^[0]{1}[1-9]{1}[0-9]{1,3}[\-]{1}[1-9]{1}[0-9]{5,7}$/, "Landline no.") : false
|
101
94
|
end
|
102
95
|
|
103
|
-
#
|
104
|
-
def
|
105
|
-
|
96
|
+
#Age data type format message.
|
97
|
+
def age_data_type_format_msg
|
98
|
+
puts "Age should be an Integer."
|
99
|
+
return false
|
106
100
|
end
|
107
101
|
|
102
|
+
#Age value is between 1 and 100 or not.
|
103
|
+
#For e.g valid_age?(100) will return true
|
104
|
+
#and valid_age?("100") will return false(and print message 'Age should be an Integer.')
|
105
|
+
#and valid_age?(-100) will return false
|
106
|
+
def valid_age?(age)
|
107
|
+
is_integer?(age) ? (age > 0 and age <= 100) : age_data_type_format_msg
|
108
|
+
end
|
108
109
|
|
109
|
-
#
|
110
|
-
def
|
111
|
-
|
110
|
+
#Valid string and regular expression.
|
111
|
+
def valid_string_and_reg_ex?(char_string, reg_exp)
|
112
|
+
str_flag = is_string?(char_string)
|
113
|
+
regex_flag = is_reg_exp?(reg_exp)
|
114
|
+
puts "First argument should be a String." unless(str_flag)
|
115
|
+
puts "Second argument should be a Regular Expression." unless(regex_flag)
|
116
|
+
str_flag && regex_flag
|
112
117
|
end
|
113
118
|
|
114
|
-
#
|
115
|
-
def
|
116
|
-
|
119
|
+
#Valid strings.
|
120
|
+
def valid_strings?(string1, string2)
|
121
|
+
str1_flag = is_string?(string1)
|
122
|
+
str2_flag = is_string?(string2)
|
123
|
+
puts "First argument should be a String." unless(str1_flag)
|
124
|
+
puts "Second argument should be a String." unless(str2_flag)
|
125
|
+
str1_flag && str2_flag
|
117
126
|
end
|
118
127
|
|
119
128
|
#Check whether a string contains a regular expression or not.
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
129
|
+
#For e.g
|
130
|
+
#is_string_contains_reg_exp?("ankurgera@gmail.com", /^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}$/)
|
131
|
+
#will return true
|
132
|
+
#and is_string_contains_reg_exp?("ankurgeragmail.com", /^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}$/)
|
133
|
+
#will return false
|
134
|
+
def is_string_contains_reg_exp?(char_string, reg_exp)
|
135
|
+
(char_string.sub(reg_exp, '**').index('**') ? true : false) if(valid_string_and_reg_ex?(char_string, reg_exp))
|
127
136
|
end
|
128
137
|
|
129
138
|
#Check whether a string contains another string or not.
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
flag=1
|
135
|
-
end
|
136
|
-
end
|
137
|
-
flag==1
|
139
|
+
#For e.g is_string_contains_another_string?("abc123@gmail.com", "123@g") will return true
|
140
|
+
#and is_string_contains_another_string?("abc123@gmail.com", "13@g") will return false
|
141
|
+
def is_string_contains_another_string?(char_string, char_set)
|
142
|
+
(char_string.sub(char_set, '**').index('**') ? true : false) if(valid_strings?(char_string, char_set))
|
138
143
|
end
|
139
144
|
|
140
145
|
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
require '../lib/watir_helper.rb'
|
2
|
+
|
3
|
+
ie = set_browser("ie")
|
4
|
+
goto_page(ie, "http://www.google.com/")
|
5
|
+
get_title(ie)
|
6
|
+
get_url(ie)
|
7
|
+
flash_div(ie, "id", "hplogo")
|
8
|
+
exists_div?(ie, "id", "hplogo")
|
9
|
+
puts is_blank_textfield?(ie, "name", "q")
|
10
|
+
set_textfield(ie, "name", "q", 100)
|
11
|
+
puts is_blank_textfield?(ie, "name", "q")
|
12
|
+
puts textfield_contains_value?(ie, "name", "q", "100")
|
13
|
+
puts textfield_contains_value?(ie, "name", "q", "101")
|
14
|
+
flash_button(ie, "name","btnG")
|
15
|
+
click_button(ie, "name","btnG")
|
16
|
+
close_browser(ie)
|
17
|
+
|
metadata
CHANGED
@@ -1,32 +1,34 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: watir_helper
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
5
|
-
prerelease:
|
4
|
+
version: 1.0.0
|
6
5
|
platform: ruby
|
7
6
|
authors:
|
8
7
|
- Ankur Gera
|
9
8
|
autorequire:
|
10
9
|
bindir: bin
|
11
10
|
cert_chain: []
|
12
|
-
date:
|
13
|
-
default_executable:
|
11
|
+
date: 2015-02-12 00:00:00.000000000 Z
|
14
12
|
dependencies: []
|
15
|
-
description:
|
13
|
+
description: ! "This gem is developed for novice automation tester's to write automation
|
14
|
+
scripts\n fast as it is very easy to use."
|
16
15
|
email: ankurgera@gmail.com
|
17
16
|
executables: []
|
18
17
|
extensions: []
|
19
18
|
extra_rdoc_files:
|
20
19
|
- README
|
21
20
|
files:
|
21
|
+
- README
|
22
|
+
- lib/watir_helper.rb
|
22
23
|
- lib/watir_helper/browser_helper.rb
|
23
24
|
- lib/watir_helper/button_helper.rb
|
24
25
|
- lib/watir_helper/checkbox_helper.rb
|
25
26
|
- lib/watir_helper/common_helpers.rb
|
27
|
+
- lib/watir_helper/data_type_validations.rb
|
26
28
|
- lib/watir_helper/div_helper.rb
|
27
29
|
- lib/watir_helper/frame_helper.rb
|
28
30
|
- lib/watir_helper/image_helper.rb
|
29
|
-
- lib/watir_helper/
|
31
|
+
- lib/watir_helper/include_other_helpers.rb
|
30
32
|
- lib/watir_helper/link_helper.rb
|
31
33
|
- lib/watir_helper/login_helper.rb
|
32
34
|
- lib/watir_helper/popup_handling_helper.rb
|
@@ -36,35 +38,30 @@ files:
|
|
36
38
|
- lib/watir_helper/table_helper.rb
|
37
39
|
- lib/watir_helper/textfield_helper.rb
|
38
40
|
- lib/watir_helper/validations_helper.rb
|
39
|
-
-
|
40
|
-
|
41
|
-
|
42
|
-
-
|
43
|
-
|
44
|
-
homepage:
|
45
|
-
licenses: []
|
41
|
+
- test/test_watir_helper.rb
|
42
|
+
homepage: https://rubygems.org/gems/watir_helper
|
43
|
+
licenses:
|
44
|
+
- MIT
|
45
|
+
metadata: {}
|
46
46
|
post_install_message:
|
47
47
|
rdoc_options: []
|
48
48
|
require_paths:
|
49
49
|
- lib
|
50
50
|
required_ruby_version: !ruby/object:Gem::Requirement
|
51
|
-
none: false
|
52
51
|
requirements:
|
53
52
|
- - ! '>='
|
54
53
|
- !ruby/object:Gem::Version
|
55
54
|
version: '0'
|
56
55
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
57
|
-
none: false
|
58
56
|
requirements:
|
59
57
|
- - ! '>='
|
60
58
|
- !ruby/object:Gem::Version
|
61
59
|
version: '0'
|
62
60
|
requirements: []
|
63
61
|
rubyforge_project:
|
64
|
-
rubygems_version:
|
62
|
+
rubygems_version: 2.4.5
|
65
63
|
signing_key:
|
66
|
-
specification_version:
|
67
|
-
summary:
|
64
|
+
specification_version: 4
|
65
|
+
summary: Watir helper
|
68
66
|
test_files:
|
69
|
-
- test/
|
70
|
-
- test/testing_watir_helper_spec.rb
|
67
|
+
- test/test_watir_helper.rb
|
@@ -1,51 +0,0 @@
|
|
1
|
-
require 'watir_helper/button_helper'
|
2
|
-
include ButtonHelper
|
3
|
-
require 'watir_helper/checkbox_helper'
|
4
|
-
include CheckBoxHelper
|
5
|
-
require 'watir_helper/frame_helper'
|
6
|
-
include FrameHelper
|
7
|
-
require 'watir_helper/image_helper'
|
8
|
-
include ImageHelper
|
9
|
-
require 'watir_helper/link_helper'
|
10
|
-
include LinkHelper
|
11
|
-
|
12
|
-
#Pop Up's Support
|
13
|
-
# Watir now optionally installs AutoIt - http://www.autoitscript.com/
|
14
|
-
# This is the prefered method for dealing wth pop ups, file requesters etc.
|
15
|
-
# To enable the same, execute the following steps on your command prompt
|
16
|
-
# - cd C:\ruby\lib\ruby\gems\1.8\gems\watir-1.6.2\lib\watir
|
17
|
-
# - regsvr32 AutoItX3.dll
|
18
|
-
# - You will get a pop-up of successful registration , press "OK" button on it.
|
19
|
-
# Now,You can easily handle pop-up's.
|
20
|
-
require 'watir_helper/popup_handling_helper'
|
21
|
-
include PopupHelper
|
22
|
-
|
23
|
-
require 'watir_helper/radio_button_helper'
|
24
|
-
include RadioButtonHelper
|
25
|
-
require 'watir_helper/select_list_helper'
|
26
|
-
include SelectListHelper
|
27
|
-
require 'watir_helper/textfield_helper'
|
28
|
-
include TextFieldHelper
|
29
|
-
require 'watir_helper/validations_helper'
|
30
|
-
include ValidationsHelper
|
31
|
-
require 'watir_helper/browser_helper'
|
32
|
-
include BrowserHelper
|
33
|
-
require 'watir_helper/login_helper'
|
34
|
-
include LoginHelper
|
35
|
-
require 'watir_helper/span_helper'
|
36
|
-
include SpanHelper
|
37
|
-
require 'watir_helper/table_helper'
|
38
|
-
include TableHelper
|
39
|
-
require 'watir_helper/div_helper'
|
40
|
-
include DivHelper
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
@@ -1,37 +0,0 @@
|
|
1
|
-
require 'watir_helper'
|
2
|
-
include WatirHelper
|
3
|
-
|
4
|
-
goto_page("http://www.google.com/")
|
5
|
-
puts get_title
|
6
|
-
puts get_url
|
7
|
-
flash_div("id","hplogo")
|
8
|
-
puts exists_div("id","hplogo")
|
9
|
-
set_textfield("name","q","Ruby")
|
10
|
-
flash_button("value","Google Search")
|
11
|
-
click_button("value","Google Search")
|
12
|
-
|
13
|
-
|
14
|
-
#Pop Up's Support
|
15
|
-
# Watir now optionally installs AutoIt - http://www.autoitscript.com/
|
16
|
-
# This is the prefered method for dealing wth pop ups, file requesters etc.
|
17
|
-
# To enable the same, execute the following steps on your command prompt
|
18
|
-
# - cd C:\ruby\lib\ruby\gems\1.8\gems\watir-1.6.2\lib\watir
|
19
|
-
# - regsvr32 AutoItX3.dll
|
20
|
-
# - You will get a pop-up of successful registration , press "OK" button on it.
|
21
|
-
# Now,You can easily handle pop-up's.
|
22
|
-
|
23
|
-
# Note:
|
24
|
-
# The latest version of Watir is 1.6.5 whose close function doesn't work fine if we
|
25
|
-
# handle pop-up's in our scripts.But close function of Watir 1.6.2 works fine with
|
26
|
-
# pop-up handling.
|
27
|
-
|
28
|
-
#goto_page("http://www.autoitscript.com/autoit3/downloads.shtml")
|
29
|
-
#click_image_with_popup("src","download_autoit")
|
30
|
-
#click_save_on_file_dialog_popup("File Download - Security Warning")
|
31
|
-
#click_save_on_save_as_popup("Save As","C:\AutoItV3.exe")
|
32
|
-
#puts get_title
|
33
|
-
#puts get_url
|
34
|
-
|
35
|
-
close_browser()
|
36
|
-
|
37
|
-
|
@@ -1,25 +0,0 @@
|
|
1
|
-
require 'watir_helper'
|
2
|
-
include WatirHelper
|
3
|
-
|
4
|
-
describe "Scenario :- Google page test" do
|
5
|
-
|
6
|
-
before(:all) do
|
7
|
-
goto_page("http://www.google.com/")
|
8
|
-
end
|
9
|
-
|
10
|
-
it "Should verify whether we are on the Landing Page or not" do
|
11
|
-
puts get_title
|
12
|
-
puts get_url
|
13
|
-
flash_image("id","logo")
|
14
|
-
puts exists_image("id","logo")
|
15
|
-
set_textfield("name","q","Ruby")
|
16
|
-
flash_button("value","Google Search")
|
17
|
-
click_button("value","Google Search")
|
18
|
-
end
|
19
|
-
|
20
|
-
after(:all) do
|
21
|
-
close_browser()
|
22
|
-
end
|
23
|
-
|
24
|
-
end
|
25
|
-
|