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.
@@ -1,32 +1,29 @@
1
- require 'watir_helper/common_helpers'
1
+ #******************************************************
2
+ #Login methods
3
+ #******************************************************
4
+ require File.expand_path('common_helpers', File.dirname(__FILE__))
2
5
 
3
6
  module LoginHelper
4
7
 
5
8
  #Login using button into an application.
6
- def login_using_button(user_prop,user_prop_value,username,pass_prop,pass_prop_value,password,btn_prop,btn_prop_value)
7
- btn_prop=/#{btn_prop}/
8
- btn_prop_value=/#{btn_prop_value}/
9
- $ie.text_field(user_prop.intern,user_prop_value).set(username)
10
- $ie.text_field(pass_prop.intern,pass_prop_value).set(password)
11
- $ie.button(btn_prop.intern,btn_prop_value).click
9
+ def login_using_button(browser_handle, user_prop, user_prop_value, username, pass_prop, pass_prop_value, password, btn_prop, btn_prop_value)
10
+ browser_handle.text_field(user_prop.intern,user_prop_value).set(username)
11
+ browser_handle.text_field(pass_prop.intern,pass_prop_value).set(password)
12
+ browser_handle.button(/#{btn_prop}/.intern, /#{btn_prop_value}/).click
12
13
  end
13
14
 
14
15
  #Login using link into an application.
15
- def login_using_link(user_prop,user_prop_value,username,pass_prop,pass_prop_value,password,link_prop,link_prop_value)
16
- link_prop=/#{link_prop}/
17
- link_prop_value=/#{link_prop_value}/
18
- $ie.text_field(user_prop.intern,user_prop_value).set(username)
19
- $ie.text_field(pass_prop.intern,pass_prop_value).set(password)
20
- $ie.link(link_prop.intern,link_prop_value).click
16
+ def login_using_link(browser_handle, user_prop, user_prop_value, username, pass_prop, pass_prop_value, password, link_prop, link_prop_value)
17
+ browser_handle.text_field(user_prop.intern,user_prop_value).set(username)
18
+ browser_handle.text_field(pass_prop.intern,pass_prop_value).set(password)
19
+ browser_handle.link(/#{link_prop}/.intern, /#{link_prop_value}/).click
21
20
  end
22
21
 
23
22
  #Login using image into an application.
24
- def login_using_image(user_prop,user_prop_value,username,pass_prop,pass_prop_value,password,img_prop,img_prop_value)
25
- img_prop=/#{img_prop}/
26
- img_prop_value=/#{img_prop_value}/
27
- $ie.text_field(user_prop.intern,user_prop_value).set(username)
28
- $ie.text_field(pass_prop.intern,pass_prop_value).set(password)
29
- $ie.image(img_prop.intern,img_prop_value).click
23
+ def login_using_image(browser_handle, user_prop, user_prop_value, username, pass_prop, pass_prop_value, password, img_prop, img_prop_value)
24
+ browser_handle.text_field(user_prop.intern,user_prop_value).set(username)
25
+ browser_handle.text_field(pass_prop.intern,pass_prop_value).set(password)
26
+ browser_handle.image(/#{img_prop}/.intern, /#{img_prop_value}/).click
30
27
  end
31
28
 
32
29
  end
@@ -1,102 +1,98 @@
1
- require 'win32ole'
2
-
3
- #Pop Up's Support
4
- # Watir now optionally installs AutoIt - http://www.autoitscript.com/
5
- # This is the prefered method for dealing wth pop ups, file requesters etc.
6
- # To enable the same, execute the following steps on your command prompt
7
- # - cd C:\ruby\lib\ruby\gems\1.8\gems\watir-1.6.2\lib\watir
8
- # - regsvr32 AutoItX3.dll
9
- # - You will get a pop-up of successful registration , press "OK" button on it.
10
- # Now,You can easily handle pop-up's.
11
-
12
- # Note:
13
- # The latest version of Watir is 1.6.5 whose close function doesn't work fine if we
14
- # handle pop-up's in our scripts.But close function of Watir 1.6.2 works fine with
15
- # pop-up handling.
16
-
17
- #Create an OLE connection for handling pop-up's.
18
- $ai=WIN32OLE.new("AutoItX3.Control")
19
-
20
1
  #******************************************************
21
2
  #Pop-up handling methods
22
3
  #******************************************************
4
+ require File.expand_path('common_helpers', File.dirname(__FILE__))
23
5
 
24
6
  module PopupHelper
25
7
 
26
- #Javascript pop-up's.
8
+ #Javascript pop-up's
27
9
 
28
- #Click on a button on a pop-up.
29
- def click_a_button_on_a_popup(title,click_element_id)
30
- $ai.WinWait(title,"",30)
31
- $ai.WinActivate(title)
32
- $ai.ControlClick(title,"",click_element_id)
10
+ #Click a button on a pop-up.
11
+ def click_button_popup(title, button_id)
12
+ window = RAutomation::Window.new(:title => /#{title}/)
13
+ window.button(:value => /#{button_id}/).click
33
14
  end
34
-
35
- #Click on "OK" button on a javascript pop-up.
36
- def click_ok_on_javascript_popup(title)
37
- click_a_button_on_a_popup(title,"","OK")
15
+
16
+ #Pop-up window exists
17
+ def popup_exists_with_title?(title)
18
+ window = RAutomation::Window.new(:title => /#{title}/)
19
+ window.exists?
38
20
  end
39
21
 
40
- #Click on "Cancel" button on a javascript pop-up.
41
- def click_cancel_on_javascript_popup(title)
42
- click_a_button_on_a_popup(title,"","Cancel")
22
+ #Click "OK" button on a javascript pop-up.
23
+ def click_ok_js_popup(title)
24
+ click_button_popup(title, "OK")
43
25
  end
44
26
 
45
- #Click on "Yes" button on a javascript pop-up.
46
- def click_yes_on_javascript_popup(title)
47
- click_a_button_on_a_popup(title,"","&Yes")
27
+ #Click "Cancel" button on a javascript pop-up.
28
+ def click_cancel_js_popup(title)
29
+ click_button_popup(title, "Cancel")
48
30
  end
49
31
 
50
- #Click on "No" button on a javascript pop-up.
51
- def click_no_on_javascript_popup(title)
52
- click_a_button_on_a_popup(title,"","&No")
32
+ #Click "Yes" button on a javascript pop-up.
33
+ def click_yes_js_popup(title)
34
+ click_button_popup(title, "&Yes")
35
+ end
36
+
37
+ #Click "Yes" button on a javascript pop-up.
38
+ def click_yes_to_all_js_popup(title)
39
+ click_button_popup(title, "Yes To &All")
40
+ end
41
+
42
+ #Click "No" button on a javascript pop-up.
43
+ def click_no_js_popup(title)
44
+ click_button_popup(title, "&No")
53
45
  end
54
46
 
55
47
  #File Dialogs
56
- #Click on "Open" button on a file dialog pop-up.
57
- def click_open_on_file_dialog_popup(title)
58
- click_a_button_on_a_popup(title,"&Open")
48
+
49
+ #Click "Open" button on a file dialog pop-up.
50
+ def click_open_file_dialog_popup(title)
51
+ click_button_popup(title, "&Open")
59
52
  end
60
53
 
61
- #Click on "Save" button on a file dialog pop-up.
62
- def click_save_on_file_dialog_popup(title)
63
- click_a_button_on_a_popup(title,"&Save")
54
+ #Click "Save" button on a file dialog pop-up.
55
+ def click_save_file_dialog_popup(title)
56
+ click_button_popup(title, "&Save")
64
57
  end
65
58
 
66
- #Click on "Cancel" button on a file dialog pop-up.
67
- def click_cancel_on_file_dialog_popup(title)
68
- click_a_button_on_a_popup(title,"Cancel")
59
+ #Click "Cancel" button on a file dialog pop-up.
60
+ def click_cancel_file_dialog_popup(title)
61
+ click_button_popup(title, "Cancel")
69
62
  end
70
63
 
71
- #Save As
72
- #Click on a button on a Save As or Open pop-up.
73
- def click_a_button_on_save_or_open_popup(title,file_path,click_element_id)
74
- $ai.WinWait(title,"",30)
75
- $ai.WinActivate(title)
76
- $ai.ControlSend(title,"","Edit1",file_path)
77
- $ai.ControlClick(title,"",click_element_id)
64
+ #Click "Run" button on a file dialog pop-up.
65
+ def click_run_file_dialog_popup(title)
66
+ click_button_popup(title, "&Run")
78
67
  end
79
68
 
80
- #Click on "Save" button on a Save As pop-up.
81
- def click_save_on_save_as_popup(title,save_file_path)
82
- click_a_button_on_save_or_open_popup(title,save_file_path,"&Save")
69
+ #Save As or Open As pop-up's
70
+
71
+ #Click a button on 'Save As' or 'Open As' pop-up's.
72
+ def click_button_saveas_or_openas_popup(title, file_path, button_id)
73
+ window = RAutomation::Window.new :title => /#{title}/
74
+ window.text_field(:class => "Edit").set file_path
75
+ window.button(:value => /#{button_id}/).click
83
76
  end
84
77
 
85
- #Click on "Cancel" button on a Save As pop-up.
86
- def click_cancel_on_save_as_popup(title,save_file_path)
87
- click_a_button_on_save_or_open_popup(title,save_file_path,"Cancel")
78
+ #Click "Save" button on 'Save As' pop-up's.
79
+ def click_save_saveas_popup(title, save_file_path)
80
+ click_button_saveas_or_openas_popup(title, save_file_path, "&Save")
88
81
  end
89
82
 
90
- #Open
91
- #Click on "Open" button on an Open pop-up.
92
- def click_open_on_open_as_popup(title,open_file_path)
93
- click_a_button_on_save_or_open_popup(title,open_file_path,"&Open")
83
+ #Click "Cancel" button on 'Save As' pop-up's.
84
+ def click_cancel_saveas_popup(title, save_file_path)
85
+ click_button_saveas_or_openas_popup(title, save_file_path, "Cancel")
94
86
  end
95
87
 
96
- #Click on "Cancel" button on an Open pop-up.
97
- def click_cancel_on_open_as_popup(title,open_file_path)
98
- click_a_button_on_save_or_open_popup(title,open_file_path,"Cancel")
88
+ #Click "Open" button on 'Open As' pop-up's.
89
+ def click_open_openas_popup(title, open_file_path)
90
+ click_button_saveas_or_openas_popup(title, open_file_path, "&Open")
99
91
  end
100
92
 
93
+ #Click "Cancel" button on 'Open As' pop-up's.
94
+ def click_cancel_openas_popup(title, open_file_path)
95
+ click_button_saveas_or_openas_popup(title, open_file_path, "Cancel")
101
96
  end
102
97
 
98
+ end
@@ -1,35 +1,33 @@
1
- require 'watir_helper/common_helpers'
1
+ #******************************************************
2
+ #Radio Button methods
3
+ #******************************************************
4
+ require File.expand_path('common_helpers', File.dirname(__FILE__))
2
5
 
3
6
  module RadioButtonHelper
4
7
 
5
8
  #Click a radio button.
6
- def click_radio_button(property,propertyvalue)
7
- propertyvalue=/#{propertyvalue}/
8
- $ie.radio(property.intern,propertyvalue).set
9
+ def click_radio_button(browser_handle, property, property_value)
10
+ browser_handle.radio(property.intern, /#{property_value}/).set
9
11
  end
10
12
 
11
13
  #Clear a radio button.
12
- def clear_radio_button(property,propertyvalue)
13
- propertyvalue=/#{propertyvalue}/
14
- $ie.radio(property.intern,propertyvalue).clear
14
+ def clear_radio_button(browser_handle, property, property_value)
15
+ browser_handle.radio(property.intern, /#{property_value}/).clear
15
16
  end
16
17
 
17
18
  #Highlight or Flash a radio button.
18
- def flash_radio_button(property,propertyvalue)
19
- propertyvalue=/#{propertyvalue}/
20
- $ie.radio(property.intern,propertyvalue).flash
19
+ def flash_radio_button(browser_handle, property, property_value)
20
+ browser_handle.radio(property.intern, /#{property_value}/).flash
21
21
  end
22
22
 
23
23
  #Check whether a radio button exists or not.
24
- def exists_radio_button(property,propertyvalue)
25
- propertyvalue=/#{propertyvalue}/
26
- $ie.radio(property.intern,propertyvalue).exists?
24
+ def exists_radio_button?(browser_handle, property, property_value)
25
+ browser_handle.radio(property.intern, /#{property_value}/).exists?
27
26
  end
28
27
 
29
28
  #Check whether a radio button is checked or not.
30
- def is_checked_radio_button(property,propertyvalue)
31
- propertyvalue=/#{propertyvalue}/
32
- $ie.radio(property.intern,propertyvalue).checked?
29
+ def is_radio_button_checked?(browser_handle, property, property_value)
30
+ browser_handle.radio(property.intern, /#{property_value}/).checked?
33
31
  end
34
32
 
35
33
  end
@@ -1,41 +1,38 @@
1
- require 'watir_helper/common_helpers'
1
+ #******************************************************
2
+ #Select List methods
3
+ #******************************************************
4
+ require File.expand_path('common_helpers', File.dirname(__FILE__))
2
5
 
3
6
  module SelectListHelper
4
7
 
5
8
  #Select from a Select list.
6
- def select_from_select_list(property,propertyvalue,selected_value)
7
- propertyvalue=/#{propertyvalue}/
8
- $ie.select_list(property.intern,propertyvalue).select(selected_value)
9
+ def select_from_select_list(browser_handle, property, property_value, selected_value)
10
+ browser_handle.select_list(property.intern, /#{property_value}/).select(selected_value)
9
11
  end
10
12
 
11
13
  #Clear selection from a Select list.
12
- def clear_selection_from_select_list(property,propertyvalue)
13
- propertyvalue=/#{propertyvalue}/
14
- $ie.select_list(property.intern,propertyvalue).clearSelection
14
+ def clear_selection_from_select_list(browser_handle, property, property_value)
15
+ browser_handle.select_list(property.intern, /#{property_value}/).clearSelection
15
16
  end
16
17
 
17
18
  #Get all contents of a Select list.
18
- def get_all_contents_of_select_list(property,propertyvalue)
19
- propertyvalue=/#{propertyvalue}/
20
- $ie.select_list(property.intern,propertyvalue).getAllContents
19
+ def get_all_contents_of_select_list(browser_handle, property, property_value)
20
+ browser_handle.select_list(property.intern, /#{property_value}/).getAllContents
21
21
  end
22
22
 
23
23
  #Highlight or Flash a Select list.
24
- def flash_select_list(property,propertyvalue)
25
- propertyvalue=/#{propertyvalue}/
26
- $ie.select_list(property.intern,propertyvalue).flash
24
+ def flash_select_list(browser_handle, property, property_value)
25
+ browser_handle.select_list(property.intern, /#{property_value}/).flash
27
26
  end
28
27
 
29
28
  #Check whether a Select list exists or not.
30
- def exists_select_list(property,propertyvalue)
31
- propertyvalue=/#{propertyvalue}/
32
- $ie.select_list(property.intern,propertyvalue).exists?
29
+ def exists_select_list?(browser_handle, property, property_value)
30
+ browser_handle.select_list(property.intern, /#{property_value}/).exists?
33
31
  end
34
32
 
35
33
  #Check whether a particular value is selected from a Select list or not.
36
- def is_value_selected_from_select_list(property,propertyvalue,selected_value)
37
- propertyvalue=/#{propertyvalue}/
38
- $ie.select_list(property.intern,propertyvalue).selected?(selected_value)
34
+ def is_value_selected_from_select_list?(browser_handle, property, property_value, selected_value)
35
+ browser_handle.select_list(property.intern, /#{property_value}/).selected?(selected_value)
39
36
  end
40
37
 
41
38
  end
@@ -1,17 +1,18 @@
1
- require 'watir_helper/common_helpers'
1
+ #******************************************************
2
+ #Span methods
3
+ #******************************************************
4
+ require File.expand_path('common_helpers', File.dirname(__FILE__))
2
5
 
3
6
  module SpanHelper
4
7
 
5
8
  #Highlight or Flash a span.
6
- def flash_span(property,propertyvalue)
7
- propertyvalue=/#{propertyvalue}/
8
- $ie.span(property.intern,propertyvalue).flash
9
+ def flash_span(browser_handle, property, property_value)
10
+ browser_handle.span(property.intern, /#{property_value}/).flash
9
11
  end
10
12
 
11
13
  #Check whether a span exists or not.
12
- def exists_span(property,propertyvalue)
13
- propertyvalue=/#{propertyvalue}/
14
- $ie.span(property.intern,propertyvalue).exists?
14
+ def exists_span?(browser_handle, property, property_value)
15
+ browser_handle.span(property.intern, /#{property_value}/).exists?
15
16
  end
16
17
 
17
18
  end
@@ -1,23 +1,23 @@
1
- require 'watir_helper/common_helpers'
1
+ #******************************************************
2
+ #Table methods
3
+ #******************************************************
4
+ require File.expand_path('common_helpers', File.dirname(__FILE__))
2
5
 
3
6
  module TableHelper
4
7
 
5
8
  #Highlight or Flash a table.
6
- def flash_table(property,propertyvalue)
7
- propertyvalue=/#{propertyvalue}/
8
- $ie.table(property.intern,propertyvalue).flash
9
+ def flash_table(browser_handle, property, property_value)
10
+ browser_handle.table(property.intern, /#{property_value}/).flash
9
11
  end
10
12
 
11
13
  #Check whether a table exists or not.
12
- def exists_table(property,propertyvalue)
13
- propertyvalue=/#{propertyvalue}/
14
- $ie.table(property.intern,propertyvalue).exists?
14
+ def exists_table?(browser_handle, property, property_value)
15
+ browser_handle.table(property.intern, /#{property_value}/).exists?
15
16
  end
16
17
 
17
- #Return the table contents.
18
- def return_table_contents(property,propertyvalue)
19
- propertyvalue=/#{propertyvalue}/
20
- $ie.table(property.intern,propertyvalue).to_a
18
+ #Get the table contents.
19
+ def get_table_contents(browser_handle, property, property_value)
20
+ browser_handle.table(property.intern, /#{property_value}/).to_a
21
21
  end
22
22
 
23
23
  end
@@ -1,51 +1,43 @@
1
- require 'watir_helper/common_helpers'
1
+ #******************************************************
2
+ #TextField methods
3
+ #******************************************************
4
+ require File.expand_path('common_helpers', File.dirname(__FILE__))
2
5
 
3
6
  module TextFieldHelper
4
7
 
5
8
  #Set a texfield with a text.
6
- def set_textfield(property,propertyvalue,settextvalue)
7
- $settext=settextvalue
8
- $ie.text_field(property.intern,propertyvalue).set settextvalue
9
+ def set_textfield(browser_handle, property, property_value, settextvalue)
10
+ browser_handle.text_field(property.intern, /#{property_value}/).set settextvalue.to_s
9
11
  end
10
12
 
11
13
  #Get the text from the textfield.
12
- def get_textfield()
13
- if $settext.nil?
14
- return nil
15
- else
16
- return $settext
17
- end
14
+ def get_textfield_contents(browser_handle, property, property_value)
15
+ browser_handle.text_field(property.intern, /#{property_value}/).value
18
16
  end
19
17
 
20
18
  #Clear a texfield.
21
- def clear_textfield(property,propertyvalue)
22
- propertyvalue=/#{propertyvalue}/
23
- $ie.text_field(property.intern,propertyvalue).clear
19
+ def clear_textfield(browser_handle, property, property_value)
20
+ browser_handle.text_field(property.intern, /#{property_value}/).clear
21
+ end
22
+
23
+ #TextField contains a value or not
24
+ def textfield_contains_value?(browser_handle, property, property_value, val)
25
+ get_textfield_contents(browser_handle, property, property_value) == val ? true : false
24
26
  end
25
27
 
26
28
  #Highlight or Flash a textfield.
27
- def flash_textfield(property,propertyvalue)
28
- propertyvalue=/#{propertyvalue}/
29
- $ie.text_field(property.intern,propertyvalue).flash
29
+ def flash_textfield(browser_handle, property, property_value)
30
+ browser_handle.text_field(property.intern, /#{property_value}/).flash
30
31
  end
31
32
 
32
33
  #Check whether a textfield exists or not.
33
- def exists_textfield(property,propertyvalue)
34
- propertyvalue=/#{propertyvalue}/
35
- $ie.text_field(property.intern,propertyvalue).exists?
34
+ def exists_textfield?(browser_handle, property, property_value)
35
+ browser_handle.text_field(property.intern, /#{property_value}/).exists?
36
36
  end
37
37
 
38
38
  #Check whether a textfield is blank or not.
39
- def is_blank_textfield()
40
- return $settext.nil? ? true : false
41
- end
42
-
39
+ def is_blank_textfield?(browser_handle, property, property_value)
40
+ [nil, ""].include?(get_textfield_contents(browser_handle, property, property_value)) ? true : false
43
41
  end
44
42
 
45
-
46
-
47
-
48
-
49
-
50
-
51
-
43
+ end