awetestlib 0.0.2-x86-mingw32

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,106 @@
1
+ module FireWatir
2
+ class Firefox
3
+
4
+ def close
5
+
6
+ if js_eval("getWindows().length").to_i == 1
7
+ js_eval("getWindows()[0].close()")
8
+
9
+ if current_os == :macosx
10
+ %x{ osascript -e 'tell application "Firefox" to quit' }
11
+ end
12
+
13
+ # wait for the app to close properly
14
+ @t.join if @t
15
+ else
16
+ # Check if window exists, because there may be the case that it has been closed by click event on some element.
17
+ # For e.g: Close Button, Close this Window link etc.
18
+ window_number = find_window(:url, @window_url)
19
+
20
+ # If matching window found. Close the window.
21
+ if window_number.try(:>, 0)
22
+ js_eval "getWindows()[#{window_number}].close()"
23
+ end
24
+
25
+ end
26
+ end
27
+
28
+
29
+
30
+ # Waits for the page to get loaded.
31
+ def wait(last_url = nil)
32
+ #puts "In wait function "
33
+ isLoadingDocument = ""
34
+ start = Time.now
35
+
36
+ while isLoadingDocument != "false"
37
+ # MONKEYPATCH - START
38
+ isLoadingDocument = js_eval("#{browser_var}=#{window_var}.getBrowser(); #{browser_var}.webProgress.isLoadingDocument;") rescue return
39
+ # MONKEYPATCH - END
40
+ #puts "Is browser still loading page: #{isLoadingDocument}"
41
+
42
+ # Raise an exception if the page fails to load
43
+ if (Time.now - start) > 300
44
+ raise "Page Load Timeout"
45
+ end
46
+ end
47
+ # If the redirect is to a download attachment that does not reload this page, this
48
+ # method will loop forever. Therefore, we need to ensure that if this method is called
49
+ # twice with the same URL, we simply accept that we're done.
50
+ url = js_eval("#{browser_var}.contentDocument.URL")
51
+
52
+ if(url != last_url)
53
+ # Check for Javascript redirect. As we are connected to Firefox via JSSh. JSSh
54
+ # doesn't detect any javascript redirects so check it here.
55
+ # If page redirects to itself that this code will enter in infinite loop.
56
+ # So we currently don't wait for such a page.
57
+ # wait variable in JSSh tells if we should wait more for the page to get loaded
58
+ # or continue. -1 means page is not redirected. Anyother positive values means wait.
59
+ jssh_command = "var wait = -1; var meta = null; meta = #{browser_var}.contentDocument.getElementsByTagName('meta');
60
+ if(meta != null)
61
+ {
62
+ var doc_url = #{browser_var}.contentDocument.URL;
63
+ for(var i=0; i< meta.length;++i)
64
+ {
65
+ var content = meta[i].content;
66
+ var regex = new RegExp(\"^refresh$\", \"i\");
67
+ if(regex.test(meta[i].httpEquiv))
68
+ {
69
+ var arrContent = content.split(';');
70
+ var redirect_url = null;
71
+ if(arrContent.length > 0)
72
+ {
73
+ if(arrContent.length > 1)
74
+ redirect_url = arrContent[1];
75
+
76
+ if(redirect_url != null)
77
+ {
78
+ regex = new RegExp(\"^.*\" + redirect_url + \"$\");
79
+ if(!regex.test(doc_url))
80
+ {
81
+ wait = arrContent[0];
82
+ }
83
+ }
84
+ break;
85
+ }
86
+ }
87
+ }
88
+ }
89
+ wait;"
90
+ wait_time = js_eval(jssh_command).to_i
91
+ begin
92
+ if(wait_time != -1)
93
+ sleep(wait_time)
94
+ # Call wait again. In case there are multiple redirects.
95
+ js_eval "#{browser_var} = #{window_var}.getBrowser()"
96
+ wait(url)
97
+ end
98
+ rescue
99
+ end
100
+ end
101
+ set_browser_document()
102
+ run_error_checks()
103
+ return self
104
+ end
105
+ end
106
+ end
@@ -0,0 +1,175 @@
1
+ module Watir
2
+
3
+ class IE
4
+
5
+ ###################################
6
+ def browser_screen_offset(browser)
7
+ parent = page_container.document.parentWindow
8
+ [parent.screenLeft.to_i,
9
+ parent.screenTop.to_i]
10
+ end
11
+
12
+ end
13
+
14
+ class Element
15
+ # for watir element returns array of arrays where each element is a [name, value] as long as value is other than null or blank
16
+ def get_attributes
17
+ attrs = []
18
+ self.document.attributes.each do |atr|
19
+ k= []
20
+ next if (atr.value == 'null') || (atr.value == '')
21
+ k << atr.name << atr.value
22
+ attrs << k
23
+ end
24
+ attrs.sort
25
+ end
26
+
27
+ ###################################
28
+ def attribute_values
29
+ hash = Hash.new
30
+ ['id', # 'offsetParent', 'style', 'currentstyle',
31
+ 'offsetHeight', 'offsetWidth', 'offsetLeft', 'offsetTop',
32
+ 'clientHeight', 'clientWidth', 'clientLeft', 'clientTop',
33
+ 'scrollHeight', 'scrollWidth', 'scrollLeft', 'scrollTop',
34
+ 'className', 'resizable',
35
+ 'visible', 'sourceIndex'].each do |attr|
36
+ value = attribute_value(attr)
37
+ myClass = value.class
38
+ if myClass =~ /WIN32OLE/i or value.is_a?(WIN32OLE)
39
+ meths = Hash.new
40
+ value.ole_methods.each do |m|
41
+ meths[m.name] = m.helpstring
42
+ end
43
+ hash[attr] = meths.sort
44
+ else
45
+ hash[attr] = value
46
+ end
47
+ end
48
+ hash
49
+ end
50
+
51
+ ###################################
52
+ def fetch_attributes
53
+ assert_exists
54
+ assert_enabled
55
+ obj = ole_object
56
+ hash = Hash.new
57
+ methods = obj.ole_methods
58
+ methods.each do |m|
59
+ hash[m.name] = "visible: #{m.visible?}: #{m.helpstring}: #{m.invoke_kind}: #{m.params}: #{m.return_type}: #{m.return_type_detail}"
60
+ end
61
+ hash.sort.to_yaml
62
+ end
63
+
64
+ ###################################
65
+ def bottom_edge
66
+ assert_exists
67
+ assert_enabled
68
+ ole_object.getBoundingClientRect.bottom.to_i
69
+ end
70
+
71
+ ###################################
72
+ def top_edge
73
+ assert_exists
74
+ assert_enabled
75
+ ole_object.getBoundingClientRect.top.to_i
76
+ end
77
+
78
+ ###################################
79
+ def top_edge_absolute
80
+ top_edge + page_container.document.parentWindow.screenTop.to_i
81
+ end
82
+
83
+ ###################################
84
+ def left_edge
85
+ assert_exists
86
+ assert_enabled
87
+ ole_object.getBoundingClientRect.left.to_i
88
+ end
89
+
90
+ ###################################
91
+ def right_edge
92
+ assert_exists
93
+ assert_enabled
94
+ ole_object.getBoundingClientRect.right.to_i
95
+ end
96
+
97
+ ###################################
98
+ def left_edge_absolute
99
+ left_edge + page_container.document.parentWindow.screenLeft.to_i
100
+ end
101
+
102
+ ###################################
103
+ def dimensions
104
+ assert_exists
105
+ assert_enabled
106
+ x = ole_object.getBoundingClientRect.right.to_i - left_edge
107
+ y = ole_object.getBoundingClientRect.bottom.to_i - top_edge
108
+ [x, y]
109
+ end
110
+
111
+ ###################################
112
+ def screen_offset
113
+ [left_edge_absolute, top_edge_absolute]
114
+ end
115
+
116
+ ###################################
117
+ def client_offset
118
+ [left_edge, top_edge]
119
+ end
120
+
121
+ ###################################
122
+ def client_center
123
+ client_offset + dimensions.map { |dim| dim/2 }
124
+ # x, y = client_offset
125
+ # w, h = dimensions
126
+ # cx = x + ( w / 2 ).to_i
127
+ # cy = y + ( h / 2 ).to_i
128
+ # [cx, cy]
129
+ end
130
+
131
+ ###################################
132
+ def screen_center
133
+ x, y = screen_offset
134
+ w, h = dimensions
135
+ cx = x + (w / 2).to_i
136
+ cy = y + (h / 2).to_i
137
+ [cx, cy]
138
+ end
139
+
140
+ ###################################
141
+ def client_lower_right
142
+ x, y = client_offset
143
+ w, h = dimensions
144
+ lrx = x + w
145
+ lry = y + h
146
+ [lrx, lry]
147
+ end
148
+
149
+ ###################################
150
+ def screen_lower_right
151
+ x, y = screen_offset
152
+ w, h = dimensions
153
+ lrx = x + w
154
+ lry = y + h
155
+ [lrx, lry]
156
+ end
157
+
158
+ ###################################
159
+ def bounding_rectangle_offsets
160
+ l, t = client_offset
161
+ r = ole_object.getBoundingClientRect.right.to_i
162
+ b = ole_object.getBoundingClientRect.bottom.to_i
163
+ [t, b, l, r]
164
+ end
165
+
166
+
167
+ end
168
+
169
+ #class NonControlElement
170
+ # class Ol < NonControlElement
171
+ # TAG = 'OL'
172
+ # end
173
+ #end
174
+
175
+ end