watir_helper 0.1.2 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,140 +1,145 @@
1
- require 'watir_helper/common_helpers'
1
+ #******************************************************
2
+ #Validation methods
3
+ #******************************************************
4
+ require File.expand_path('common_helpers', File.dirname(__FILE__))
2
5
 
3
6
  module ValidationsHelper
4
7
 
5
- #Check whether a character range is present in a textfield or not.
6
- def validate_chars_range_contain_textfield(range_start,range_end) #for positive integers and chars range
7
- if (range_start <= range_end) and (range_start.length==1) and (range_end.length==1)
8
- puts $settext.gsub(/[#{range_start}-#{range_end}]/,'*').index('*')? "Present" : "Not Present"
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
- #Check whether a substring is present in a textfield or not.
15
- def contains_sub_string(substring)
16
- return $settext.sub(substring,'*').index('*') ? true : false
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
- #Check whether a date is in mmddyyyy format or not.
20
- def validate_date_format_mmddyyyy(date)
21
- if(date =~ /^(0[1-9]|1[012])[- \/.](0[1-9]|[12][0-9]|3[01])[- \/.](19|20)\d\d$/).nil?
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 ddmmyyyy format or not.
29
- def validate_date_format_ddmmyyyy(date)
30
- if(date=~/^(0[1-9]|[12][0-9]|3[01])[- \/.](0[1-9]|1[012])[- \/.](19|20)\d\d$/).nil?
31
- puts "Invalid Date(ddmmyyyy) Format"
32
- else
33
- puts "Valid Date(ddmmyyyy) Format"
34
- end
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 the age entered is in the given range or not.
38
- def is_age_in_the_range(range_start,range_end)
39
- if ($settext.to_i>=range_start.to_i and $settext.to_i<=range_end.to_i)
40
- return true
41
- else
42
- return false
43
- end
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
- def validate_email_address(email_id)
48
- if(email_id=~/^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}$/).nil?
49
- puts "Invalid E-mail id Format"
50
- else
51
- puts "Valid E-mail id Format"
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
- #Check whether the indian mobile number entered is valid or not.
56
- def validate_indian_mobile_number(mobile_no)
57
- if(mobile_no.to_i>0)
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
- #Check whether the indian landline number entered is valid or not.
75
- def validate_indian_landline_number(landline_no)#like "020-30303030"
76
- if(landline_no.length==12) #In India landline number should be of 10 digits including std code
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 value entered is an Integer or not.
89
- def is_an_Integer(value)
90
- value.is_a?(Integer)
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
- #Check whether the value entered is a Float or not.
94
- def is_a_Float(value)
95
- value.is_a?(Float)
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
- #Check whether the value entered is a String or not.
99
- def is_a_String(value)
100
- value.is_a?(String)
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
- #Check whether the value entered is a Regular Expression or not.
104
- def is_a_reg_exp(value)
105
- value.is_a?(Regexp)
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
- #Check whether the value entered is a Character or not.
110
- def is_a_char(value) #Like "3",'3',"a",'a'
111
- value.length==1
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
- #Check whether the value entered contains a string or not.
115
- def contain_chars(char_set)
116
- is_string_contains_character_set($settext,char_set)
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
- def is_string_contains_reg_exp_character_set(char_string,char_set)
121
- flag=0 #Here char_set is a regular expression of characters
122
- #The format for regular expression of character set(or char_set) should be like /[$#!@^*&()~]/
123
- if(char_string.sub(char_set,'**').index('**') ? true : false)==true
124
- flag=1
125
- end
126
- flag==1
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
- def is_string_contains_character_set(char_string,char_set)
131
- flag=0 #Here char_set is a string of characters
132
- char_set.each_byte do |char|
133
- if(char_string.sub(char.chr.to_s,'**').index('**') ? true : false )==true
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.1.2
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: 2011-06-16 00:00:00.000000000 -04:00
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/include_all_helpers.rb
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
- - lib/watir_helper.rb
40
- - test/testing_watir_helper.rb
41
- - test/testing_watir_helper_spec.rb
42
- - README
43
- has_rdoc: true
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: 1.5.2
62
+ rubygems_version: 2.4.5
65
63
  signing_key:
66
- specification_version: 3
67
- summary: A utility for making Automation Testing faster, simpler and easier.
64
+ specification_version: 4
65
+ summary: Watir helper
68
66
  test_files:
69
- - test/testing_watir_helper.rb
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
-