uptime_monitor 0.2.0 → 0.3.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +1 -1
- data/Gemfile +1 -0
- data/Gemfile.lock +4 -1
- data/README.md +155 -179
- data/VERSION +1 -1
- data/lib/uptime_monitor/browsers.treetop +36 -0
- data/lib/uptime_monitor/maestro.treetop +253 -0
- data/lib/uptime_monitor/maestro_broswer.rb +20 -0
- data/lib/uptime_monitor/parser.rb +45 -0
- data/lib/uptime_monitor/uptime_monitor.rb +19 -13
- data/spec/browsers_lang_parser_spec.rb +36 -0
- data/spec/maestro_lang_parser_spec.rb +153 -0
- data/spec/uptime_monitor_spec.rb +18 -44
- data/uptime_monitor.gemspec +12 -6
- metadata +22 -5
- data/TODO.md +0 -10
- data/lib/uptime_monitor/browser_reader.rb +0 -41
- data/spec/browser_reader_spec.rb +0 -40
data/README.md
CHANGED
@@ -17,6 +17,10 @@ Run bundle install from the ragios root directory
|
|
17
17
|
```
|
18
18
|
bundle install
|
19
19
|
```
|
20
|
+
In the Ragios root directory, in the file ```config.rb```, add to line 1
|
21
|
+
```ruby
|
22
|
+
require 'uptime_monitor'
|
23
|
+
```
|
20
24
|
Restart ragios
|
21
25
|
|
22
26
|
##usage:
|
@@ -29,14 +33,12 @@ monitor = {
|
|
29
33
|
contact: "admin@obiora.com",
|
30
34
|
via: "gmail_notifier",
|
31
35
|
plugin: "uptime_monitor",
|
32
|
-
exists?:
|
33
|
-
|
34
|
-
],
|
35
|
-
browser: ["firefox"]
|
36
|
+
exists?: 'title.with_text("Obi Akubue")'
|
37
|
+
browser: "firefox"
|
36
38
|
}
|
37
39
|
ragios.create(monitor)
|
38
40
|
```
|
39
|
-
The above example will create a ragios monitor that will, every 5 minutes, use firefox to visit the website url http://obi-akubue.org, and verify that the title tag
|
41
|
+
The above example will create a ragios monitor that will, every 5 minutes, use firefox to visit the website url http://obi-akubue.org, and verify that the home page title tag matches the text "Obi Akubue". The validations performed as defined in the exists? key/value pair. When the title tag doesn't match the text, a failure notification will be sent out to the provided contact "admin@obiora.com".
|
40
42
|
|
41
43
|
###Using the plugin
|
42
44
|
To use the uptime monitor plugin add the key/value pair to the monitor
|
@@ -47,80 +49,93 @@ plugin: "uptime_monitor"
|
|
47
49
|
###Browsers
|
48
50
|
A browser is specified, by adding a browser key/value pair to the monitor
|
49
51
|
```ruby
|
50
|
-
browser:
|
52
|
+
browser: "firefox"
|
51
53
|
```
|
52
54
|
Supported browsers include Firefox, Chrome, Safari and Phantomjs. Other browsers can be specified as
|
53
55
|
```ruby
|
54
|
-
browser:
|
55
|
-
browser:
|
56
|
-
browser:
|
56
|
+
browser: "chrome"
|
57
|
+
browser: "safari"
|
58
|
+
browser: "phantomjs"
|
57
59
|
```
|
58
60
|
uptime_monitor uses [Watir Webdriver](http://watirwebdriver.com), firefox runs out of the box with no configuration required. To use Chrome or Safari see the Watir Webdriver documentation on downloading the appropriate driver binary and configuration.
|
59
61
|
|
60
62
|
By default, the browsers don't run headless, to run the browser headless, you can specify it in the format below:
|
61
63
|
```ruby
|
62
|
-
browser:
|
64
|
+
browser: "firefox headless"
|
63
65
|
```
|
64
66
|
This will run firefox as a headless browser. You should have [Xvfb](https://en.wikipedia.org/wiki/Xvfb) installed to run a non-headless browsers as headless. Headless browsers like Phantomjs don't require Xvfb.
|
65
67
|
|
66
|
-
|
68
|
+
To run Chrome browser as headless
|
67
69
|
```ruby
|
68
|
-
browser:
|
70
|
+
browser: "chrome headless"
|
69
71
|
```
|
70
|
-
The above example will run firefox as a non-headless browser.
|
71
72
|
|
72
73
|
###Validations
|
73
|
-
To verify that a html element exists on the web page, a validation needs to be added to the monitor. Validations are specified with the exists? key/value pair which takes
|
74
|
+
To verify that a html element exists on the web page, a validation needs to be added to the monitor. Validations are specified with the exists? key/value pair which takes a string of html elements as it's value. It verifies that the html elements in the array exists on the current web page.
|
74
75
|
```ruby
|
75
|
-
exists?:
|
76
|
-
[:h1]
|
77
|
-
[:div]
|
78
|
-
]
|
76
|
+
exists?: "h1 div"
|
79
77
|
```
|
80
78
|
The above example will verify that a h1 and a div exists on the page.
|
81
79
|
|
82
80
|
####HTML Elements
|
83
|
-
The simplest way to specify a html element is using
|
81
|
+
The simplest way to specify a html element is using the element name.
|
84
82
|
```ruby
|
85
|
-
exists?:
|
86
|
-
[:h1]
|
87
|
-
[:div]
|
88
|
-
[:a]
|
89
|
-
[:img]
|
90
|
-
[:span]
|
91
|
-
]
|
83
|
+
exists?: "h1 div a img span"
|
92
84
|
```
|
93
|
-
HTML elements can also be specified
|
85
|
+
HTML elements can also be specified with their attributes in a ruby-like syntax.
|
94
86
|
```ruby
|
95
|
-
exists?:
|
96
|
-
[div: {class: "box_content"}]
|
97
|
-
]
|
87
|
+
exists?: 'div.where(class: "box_content")'
|
98
88
|
```
|
99
|
-
The above will verify that a div with class "box_content" exists on the page.
|
89
|
+
The above will verify that a div with class attribute equals to "box_content" exists on the page.
|
100
90
|
|
101
91
|
Other examples:
|
102
92
|
```ruby
|
103
|
-
|
93
|
+
img.where(src: "https://fc03.deviantart.net/fs14/f/2007/047/f/2/Street_Addiction_by_gizmodus.jpg")
|
104
94
|
|
105
95
|
```
|
106
96
|
Specifies an img tag with src="https://fc03.deviantart.net/fs14/f/2007/047/f/2/Street_Addiction_by_gizmodus.jpg".
|
107
97
|
|
108
98
|
```ruby
|
109
|
-
|
99
|
+
div.where(id:"test", class: "test-section")
|
110
100
|
```
|
111
101
|
Specifes a div with id="test" and class="test-section".
|
112
102
|
|
103
|
+
####Multiple validations
|
104
|
+
Multiple validations can be added to a monitor, see below:
|
105
|
+
```ruby
|
106
|
+
validations = <<-eos
|
107
|
+
div.where(class: "box_content")
|
108
|
+
img.where(src: "https://fc03.deviantart.net/fs14/f/2007/047/f/2/Street_Addiction_by_gizmodus.jpg")
|
109
|
+
div.where(id:"test", class: "test-section")
|
110
|
+
eos
|
111
|
+
|
112
|
+
monitor = {
|
113
|
+
monitor: "My Blog title tag",
|
114
|
+
url: "http://obi-akubue.org",
|
115
|
+
every: "5m",
|
116
|
+
contact: "admin@obiora.com",
|
117
|
+
via: "gmail_notifier",
|
118
|
+
plugin: "uptime_monitor",
|
119
|
+
exists?: validations,
|
120
|
+
browser: "firefox"
|
121
|
+
}
|
122
|
+
|
123
|
+
ragios.create(monitor)
|
124
|
+
```
|
125
|
+
In the above example the string variable *validations* contains validations that need to be performed when the monitor runs. During execution, the monitor will visit the website and verify that all the html elements specified in the validations exists on the page, if any of them doesn't exist, a notification of the failure will be sent out.
|
126
|
+
|
127
|
+
|
113
128
|
####Standard attributes
|
114
129
|
|
115
|
-
Only standard attributes for an element can be included in the
|
130
|
+
Only standard attributes for an element can be included in the above format *div.where(id: "test")*, for example a div has the following standard attributes id, class, lang, dir, title, align, onclick, ondblclick, onmousedown, onmouseup, onmouseover, onmousemove, onmouseout, onkeypress, onkeydown, onkeyup. So *div.where(class: "anything")* will work.
|
116
131
|
|
117
|
-
|
132
|
+
But custom or data attributes cannot be included in the same format, for example
|
118
133
|
```html
|
119
134
|
<div data-brand="toyota">
|
120
135
|
```
|
121
136
|
The following
|
122
137
|
```ruby
|
123
|
-
|
138
|
+
div.where(data-brand: "toyota")
|
124
139
|
```
|
125
140
|
will give an error because "data-brand" is not a standard attibute for div, to specify elements by data or custom attributes use css selectors, see below.
|
126
141
|
|
@@ -128,13 +143,13 @@ will give an error because "data-brand" is not a standard attibute for div, to s
|
|
128
143
|
####Using CSS Selectors
|
129
144
|
HTML elements can also be specified with css selectors.
|
130
145
|
```ruby
|
131
|
-
|
146
|
+
element.where(css: "#rss-link")
|
132
147
|
```
|
133
148
|
This specifies an element with id="rss-link".
|
134
149
|
|
135
150
|
To specify an element by data attributes
|
136
151
|
```ruby
|
137
|
-
|
152
|
+
element.where(css: "[data-brand='toyota']")
|
138
153
|
```
|
139
154
|
|
140
155
|
####Helpers for HTML elements
|
@@ -145,40 +160,40 @@ An anchor tag could be specified with a link helper, this makes it more readable
|
|
145
160
|
|
146
161
|
Using the anchor tag
|
147
162
|
```ruby
|
148
|
-
|
163
|
+
a.where(text: "Click Here")
|
149
164
|
```
|
150
165
|
|
151
166
|
More readble using a helper
|
152
167
|
```ruby
|
153
|
-
|
168
|
+
link.where(text: "Click Here")
|
154
169
|
```
|
155
170
|
|
156
171
|
```ruby
|
157
|
-
|
172
|
+
link.where(href: "https://www.southmunn.com/aboutus")
|
158
173
|
```
|
159
174
|
|
160
175
|
#####Buttons
|
161
176
|
```ruby
|
162
|
-
|
177
|
+
button.where(id: "searchsubmit")
|
163
178
|
```
|
164
179
|
|
165
180
|
#####Text Fields
|
166
181
|
```ruby
|
167
|
-
|
182
|
+
text_field.where(id: "search")
|
168
183
|
```
|
169
184
|
|
170
185
|
More readable than the input tag
|
171
186
|
```ruby
|
172
|
-
|
187
|
+
input.where(id: "search")
|
173
188
|
```
|
174
189
|
|
175
190
|
#####Checkboxes
|
176
191
|
```ruby
|
177
|
-
|
192
|
+
checkbox.where(value: "Butter")
|
178
193
|
```
|
179
194
|
#####Radio Buttons
|
180
195
|
```ruby
|
181
|
-
|
196
|
+
radio.where(name: "group1", value: "Milk")
|
182
197
|
```
|
183
198
|
|
184
199
|
#####Drop Down menus
|
@@ -191,65 +206,50 @@ More readable than the input tag
|
|
191
206
|
```
|
192
207
|
Helper
|
193
208
|
```ruby
|
194
|
-
|
209
|
+
select_list.where(name: "mydropdown")
|
195
210
|
```
|
196
211
|
|
197
212
|
Or HTML select tag
|
198
213
|
```ruby
|
199
|
-
|
214
|
+
select.where(name: "mydropdown")
|
200
215
|
```
|
201
216
|
|
202
217
|
Options of the drop-down menu can be specified using option
|
203
218
|
```ruby
|
204
|
-
|
219
|
+
option.where(value: "Milk")
|
205
220
|
```
|
206
221
|
|
207
222
|
####Text Validations
|
208
223
|
A text validation is used to verify that the text content of a html element hasn't changed. For example,
|
209
224
|
```ruby
|
210
|
-
exists?:
|
211
|
-
[:title, [text: "Welcome to my site"]]
|
212
|
-
]
|
225
|
+
exists?: 'title.with_text("Welcome to my site")'
|
213
226
|
```
|
214
|
-
The above example first verifies that a title tag exists on the page, then it verifies that title tag text is equal to "Welcome to my site".
|
215
|
-
|
227
|
+
The above example first verifies that a title tag exists on the page, then it verifies that title tag text is equal to "Welcome to my site". The above example is a text validation.
|
228
|
+
Text validations can also verify that the html element's text includes the provided string:
|
216
229
|
```ruby
|
217
|
-
|
218
|
-
```
|
219
|
-
Text validations can also verify that the html element's text includes the provided string, in the format below:
|
220
|
-
```ruby
|
221
|
-
exists?: [
|
222
|
-
[:title, [includes_text: "Welcome"]]
|
223
|
-
]
|
230
|
+
exists?: 'title.includes_text("Welcome")'
|
224
231
|
```
|
225
232
|
The above example verifies that the title tag's text includes the string "Welcome".
|
226
233
|
Another example, to verify that a div with class="box_content" includes the string "SouthMunn is a Website"
|
227
234
|
```ruby
|
228
|
-
exists?:
|
229
|
-
[{div: {class: "box_content"}}, [includes_text: "SouthMunn is a Website"]]
|
230
|
-
]
|
235
|
+
exists?: 'div.where(class: "box_content").includes_text("SouthMunn is a Website")'
|
231
236
|
```
|
232
237
|
Text validations can be used on html elements that can contain text like title, div, span, h1, h2 etc.
|
233
238
|
|
234
239
|
####Actions
|
235
240
|
Validations can also include actions. The actions are performed on the html element after it is verfied that the element exists. Example to set a text field's value
|
236
241
|
```ruby
|
237
|
-
exists?:
|
238
|
-
[{text_field: {id: "username"}}, [set: "admin"]]
|
239
|
-
]
|
240
|
-
```
|
241
|
-
The above example will set the text field's value to the string "admin".
|
242
|
-
The following is an action
|
243
|
-
```ruby
|
244
|
-
[set: "admin"]
|
242
|
+
exists?: 'text_field.where(id: "username").set("admin")'
|
245
243
|
```
|
244
|
+
The above example is an action that will set the text field's value to the string "admin".
|
245
|
+
|
246
246
|
#####Actions on html elements
|
247
247
|
Common actions performed on elements are set, select and click.
|
248
248
|
|
249
|
-
|
249
|
+
For example to set value for a textfield or textarea.
|
250
250
|
```ruby
|
251
|
-
|
252
|
-
|
251
|
+
text_field.where(name: "q").set("ruby")
|
252
|
+
text_area.where(name: "longtext").set("In a world...")
|
253
253
|
```
|
254
254
|
Select an option from a drop down menu
|
255
255
|
```html
|
@@ -260,32 +260,32 @@ Select an option from a drop down menu
|
|
260
260
|
</select>
|
261
261
|
```
|
262
262
|
```ruby
|
263
|
-
|
263
|
+
select_list.where(name: "mydropdown").select("Old Cheese")
|
264
264
|
```
|
265
265
|
Click a radio button, checkbox, link or button
|
266
266
|
```ruby
|
267
|
-
|
268
|
-
|
269
|
-
|
270
|
-
|
267
|
+
radio.where(name: "group1", value: "Milk").click
|
268
|
+
checkbox.where(name: "checkbox").click
|
269
|
+
link.where(text: "Click Here").click
|
270
|
+
button.where(id: "submit").click
|
271
271
|
```
|
272
272
|
####Waiting
|
273
|
-
For webpages that use a lot of AJAX, it's possible to wait until an element exists, by using the
|
273
|
+
For webpages that use a lot of AJAX, it's possible to wait until an element exists, by using the wait_for keyword. This keyword takes an element as value. It is a special type of validation, it will wait for 30 seconds for the provided element to exist, if the element doesn't exist in 30 seconds the validation fails.
|
274
274
|
```ruby
|
275
|
-
|
275
|
+
wait_for div.where(id: "open-section")
|
276
276
|
```
|
277
277
|
The above example will wait 30 seconds until the div exists, if it doesn't exist after 30 seconds the validation will fail.
|
278
278
|
|
279
279
|
####Multiple validations and actions
|
280
280
|
```ruby
|
281
|
-
|
282
|
-
|
283
|
-
|
284
|
-
|
285
|
-
|
286
|
-
|
281
|
+
validations = <<-eos
|
282
|
+
text_field.where(id: "username").set("admin")
|
283
|
+
text_field.where(id: "password").set("pass")
|
284
|
+
button.click
|
285
|
+
title.includes_text("Dashboard")
|
286
|
+
eos
|
287
287
|
```
|
288
|
-
With multiple validations like the example above, the monitor will run the validations, line by line, from top to bottom. When it meets an action it will apply it on the element in the validation. The monitor fails
|
288
|
+
With multiple validations like the example above, the monitor will run the validations, line by line, from top to bottom. When it meets an action it will apply it on the element in the validation. The monitor fails its test if any of the validation fails. So for the monitor to pass, all validations must pass.
|
289
289
|
|
290
290
|
When actions like clicking a link, changes the current page, the following validations will be performed on the new page.
|
291
291
|
|
@@ -297,6 +297,14 @@ Transactions are achieved by a combination of multiple validations and actions.
|
|
297
297
|
|
298
298
|
Example, to monitor the keyword search feature on my blog, notice the validations in the exists? key's value:
|
299
299
|
```ruby
|
300
|
+
steps = <<-eos
|
301
|
+
title.with_text("Obi Akubue")
|
302
|
+
text_field.where(id: "s").set("ruby")
|
303
|
+
button.where(id: "searchsubmit").click
|
304
|
+
title.includes_text("ruby").includes_text("Search Results")
|
305
|
+
h2.where(class: "pagetitle").includes_text("Search results for")
|
306
|
+
eos
|
307
|
+
|
300
308
|
monitor = {
|
301
309
|
monitor: "My Blog: keyword search",
|
302
310
|
url: "http://obi-akubue.org",
|
@@ -304,22 +312,16 @@ monitor = {
|
|
304
312
|
contact: "admin@obiora.com",
|
305
313
|
via: "gmail_notifier",
|
306
314
|
plugin: "uptime_monitor",
|
307
|
-
exists?:
|
308
|
-
|
309
|
-
[{text_field: {id: "s"}}, [set: "ruby"]],
|
310
|
-
[{button:{id: "searchsubmit"}}, [:click]],
|
311
|
-
[:title, [includes_text: "ruby"], [includes_text: "Search Results"]],
|
312
|
-
[{h2:{class: "pagetitle"}},[includes_text: "Search results for"]]
|
313
|
-
],
|
314
|
-
browser: ["firefox"]
|
315
|
+
exists?: steps,
|
316
|
+
browser: "firefox"
|
315
317
|
}
|
316
318
|
ragios.create(monitor)
|
317
319
|
```
|
318
|
-
In the above example the monitor will visit "http://obi-akubue.org" every hour, and perform a search for keyword 'ruby', then confirm that the search works by checking that the title
|
320
|
+
In the above example, the monitor will visit "http://obi-akubue.org" every hour, and perform a search for keyword 'ruby', then confirm that the search works by checking that the title and h2 tag of the *search results page* contains the expected text.
|
319
321
|
|
320
|
-
Another example, to search my friend's ecommerce site http://akross.net, for a citizen brand wristwatch, add
|
322
|
+
Another example, to search my friend's ecommerce site http://akross.net, for a citizen brand wristwatch, add the watch to cart, and go to the checkout page.
|
321
323
|
|
322
|
-
This transaction verifies the
|
324
|
+
This transaction verifies the following about the site:
|
323
325
|
|
324
326
|
1. Product search is working
|
325
327
|
|
@@ -330,6 +332,17 @@ This transaction verifies the the following about the site:
|
|
330
332
|
4. All three above works together as a sequence
|
331
333
|
|
332
334
|
```ruby
|
335
|
+
add_items_to_cart = <<-eos
|
336
|
+
title.with_text("All Watches Shop, Authentic Watches at Akross")
|
337
|
+
text_field.where(name: "filter_name").set("citizen")
|
338
|
+
div.where(class: "button-search").click
|
339
|
+
title.with_text("search")
|
340
|
+
link.where(text: "search")
|
341
|
+
button.where(value: "Add to Cart").click
|
342
|
+
link.where(text: "Checkout").click
|
343
|
+
title.with_text("Checkout")
|
344
|
+
eos
|
345
|
+
|
333
346
|
monitor = {
|
334
347
|
monitor: "Akross.net: Add citizen watch to cart and checkout",
|
335
348
|
url: "http://akross.net",
|
@@ -337,34 +350,25 @@ monitor = {
|
|
337
350
|
contact: "admin@obiora.com",
|
338
351
|
via: "ses",
|
339
352
|
plugin: "uptime_monitor",
|
340
|
-
exists?:
|
341
|
-
|
342
|
-
[{text_field: {name: "filter_name"}}, [set: "citizen"]],
|
343
|
-
[{div: {class: "button-search"}}, [:click]],
|
344
|
-
[:title,[text: "Search"]],
|
345
|
-
[link: {text: "Search"}],
|
346
|
-
[{button: {value: "Add to Cart"}}, [:click]],
|
347
|
-
[{link: {text: "Checkout"}}, [:click]],
|
348
|
-
[:title, [text: "Checkout"]]
|
349
|
-
],
|
350
|
-
browser: ["phantomjs"]
|
353
|
+
exists?: add_items_to_cart,
|
354
|
+
browser: "firefox"
|
351
355
|
}
|
352
356
|
|
357
|
+
|
353
358
|
ragios.create(monitor)
|
354
359
|
```
|
355
360
|
|
356
|
-
|
357
361
|
Another example, to monitor the login process of the website http://southmunn.com
|
358
362
|
```ruby
|
359
|
-
login_process =
|
360
|
-
|
361
|
-
|
362
|
-
|
363
|
-
|
364
|
-
|
365
|
-
|
366
|
-
|
367
|
-
|
363
|
+
login_process = <<-eos
|
364
|
+
title.with_text("Website Uptime Monitoring | SouthMunn.com")
|
365
|
+
link.where(text: "login").click
|
366
|
+
title.with_text("Sign in - Website Uptime Monitoring | SouthMunn.com")
|
367
|
+
text_field.where(id: "username").set("admin")
|
368
|
+
text_field.where(id: "password").set("pass")
|
369
|
+
button.click
|
370
|
+
title.with_text("Dashboard - Website Uptime Monitoring | SouthMunn.com")
|
371
|
+
eos
|
368
372
|
|
369
373
|
monitor = {
|
370
374
|
monitor: "My Website login processs",
|
@@ -374,8 +378,9 @@ monitor = {
|
|
374
378
|
via: "email_notifier",
|
375
379
|
plugin: "uptime_monitor",
|
376
380
|
exists?: login_process,
|
377
|
-
browser:
|
381
|
+
browser: "firefox headless"
|
378
382
|
}
|
383
|
+
|
379
384
|
ragios.create(monitor)
|
380
385
|
```
|
381
386
|
|
@@ -384,12 +389,10 @@ Sometimes it's useful to run validations outside Ragios to verify that the valid
|
|
384
389
|
```ruby
|
385
390
|
require 'uptime_monitor'
|
386
391
|
|
387
|
-
page_element1 = [:title]
|
388
|
-
page_element2 = [:div]
|
389
392
|
monitor = {
|
390
393
|
url: "http://obi-akubue.org",
|
391
|
-
browser:
|
392
|
-
exists?:
|
394
|
+
browser: "firefox headless",
|
395
|
+
exists?: "title div"
|
393
396
|
}
|
394
397
|
|
395
398
|
u = Ragios::Plugin::UptimeMonitor.new
|
@@ -400,17 +403,16 @@ u.test_result
|
|
400
403
|
#=> {
|
401
404
|
# :results =>
|
402
405
|
# [
|
403
|
-
# [
|
404
|
-
# [
|
405
|
-
#
|
406
|
-
#
|
406
|
+
# ["title", "exists_as_expected"],
|
407
|
+
# ["div", "exists_as_expected"]
|
408
|
+
# ]
|
409
|
+
# }
|
407
410
|
|
408
411
|
#test result for a failed test during downtime
|
409
|
-
page_element = [:title, [text: "dont_exist"]]
|
410
412
|
monitor = {
|
411
413
|
url: "http://obi-akubue.org",
|
412
|
-
browser:
|
413
|
-
exists?:
|
414
|
+
browser: "firefox headless",
|
415
|
+
exists?: 'title.with_text("something")'
|
414
416
|
}
|
415
417
|
|
416
418
|
u.init(monitor)
|
@@ -418,34 +420,38 @@ u.test_command?
|
|
418
420
|
#=> false
|
419
421
|
u.test_result
|
420
422
|
#=> {
|
421
|
-
# :results=>
|
423
|
+
# :results =>
|
422
424
|
# [
|
423
|
-
#
|
425
|
+
# ["title, with text \"something\"", "does_not_exist_as_expected"]
|
424
426
|
# ]
|
425
|
-
#
|
427
|
+
# }
|
426
428
|
```
|
427
|
-
In the above example the test_command
|
429
|
+
In the above example the *test_command?* method runs the validations and returns true when all validations passes, returns false when any of the validation fails. *test_result* is a hash that contains the result of the tests ran by *test_command?*.
|
428
430
|
|
429
431
|
|
430
432
|
####Testing individual validations
|
431
|
-
It can be very useful to test validations individually before adding them to Ragios. This can be done by running plugin's browser
|
433
|
+
It can be very useful to test validations/actions individually before adding them to Ragios. This can be done by running plugin's browser directly.
|
432
434
|
```ruby
|
433
435
|
require 'uptime_monitor'
|
434
436
|
|
435
437
|
url= "http://obi-akubue.org"
|
436
438
|
headless = false
|
437
439
|
browser_name = "firefox"
|
438
|
-
browser = Hercules::
|
440
|
+
browser = Hercules::Maestro::Browser.new(url, browser_name, headless)
|
439
441
|
|
440
|
-
browser.exists?
|
442
|
+
browser.exists? 'title.includes_text("ruby")'
|
441
443
|
|
442
|
-
browser.exists?
|
444
|
+
browser.exists? 'text_field.where(id: "s").set("ruby")'
|
443
445
|
|
444
|
-
browser.exists?
|
446
|
+
browser.exists? 'checkbox.where(name: "checkbox").click'
|
445
447
|
|
446
448
|
browser.close
|
447
449
|
```
|
448
|
-
The above example
|
450
|
+
The above example will launch firebox and open the provided url. The exists?() method takes a single validation/action as parameter and performs the validation on the current page, it returns true if the validation passes and returns false if the validation fails. In the first validation
|
451
|
+
```
|
452
|
+
browser.exists? 'title.includes_text("ruby")'
|
453
|
+
```
|
454
|
+
it checks if the title tag on the current webpage includes the text 'ruby'.
|
449
455
|
|
450
456
|
|
451
457
|
##Screenshots
|
@@ -468,11 +474,10 @@ See an example below:
|
|
468
474
|
```ruby
|
469
475
|
require 'uptime_monitor'
|
470
476
|
|
471
|
-
page_element = [:title, [text: "dont_exist"]]
|
472
477
|
monitor = {
|
473
478
|
url: "http://obi-akubue.org",
|
474
|
-
browser:
|
475
|
-
exists?:
|
479
|
+
browser: "firefox headless",
|
480
|
+
exists?: 'title.with_text("dont_exist")'
|
476
481
|
}
|
477
482
|
|
478
483
|
u = Ragios::Plugin::UptimeMonitor.new
|
@@ -483,23 +488,22 @@ u.test_result
|
|
483
488
|
#=> {
|
484
489
|
# :results=>
|
485
490
|
# [
|
486
|
-
# [
|
491
|
+
# ["title, with text \"dont_exist\"", "does_not_exist_as_expected"]
|
487
492
|
# ],
|
488
493
|
# :screenshot=>
|
489
494
|
# "http://screenshot-ragios.s3.amazonaws.com/uploads/screenshot1428783237.png"
|
490
495
|
# }
|
491
496
|
```
|
492
|
-
Notice that
|
497
|
+
Notice that *test_result* includes a url to the screenshot of the webpage when the test failed. This test result is also included in the notifications sent to site admin by Ragios when a test fails. So this way the admin can see exactly what webpage looked like when the transaction failed.
|
493
498
|
|
494
499
|
##Disable screenshots on individual monitors
|
495
500
|
To disable screenshots on a particular monitor add the key/value pair ```disable_screenshots: true```
|
496
501
|
example:
|
497
502
|
```ruby
|
498
|
-
page_element = [:title]
|
499
503
|
monitor = {
|
500
504
|
url: "http://obi-akubue.org",
|
501
|
-
browser:
|
502
|
-
exists?:
|
505
|
+
browser: "firefox headless",
|
506
|
+
exists?: "title",
|
503
507
|
disable_screenshots: true
|
504
508
|
}
|
505
509
|
|
@@ -507,34 +511,6 @@ ragios.create(monitor)
|
|
507
511
|
```
|
508
512
|
This will diable screenshots only for this monitor, no screenshots will be taken when its test fails.
|
509
513
|
|
510
|
-
##Specification:
|
511
|
-
```ruby
|
512
|
-
monitor = {
|
513
|
-
monitor: "My Website",
|
514
|
-
url: "http://mysite.com",
|
515
|
-
every: "5m",
|
516
|
-
contact: "admin@obiora.com",
|
517
|
-
via: "mail_notifier",
|
518
|
-
plugin: "uptime_monitor",
|
519
|
-
exists?: [
|
520
|
-
[:title, [text: "Welcome to my site"]],
|
521
|
-
[{div: {id:"test", class: "test-section"}}, [text: "this is a test"]],
|
522
|
-
[a: {href: "/aboutus" }],
|
523
|
-
[:h1],
|
524
|
-
[:h2,[text: "Login"]],
|
525
|
-
[form: {action: "/signup", method: "get"}],
|
526
|
-
[{element: {css: "#submit-button"}}, [:click]],
|
527
|
-
[{text_field: {id: "username"}}, [set: "admin"]],
|
528
|
-
[{text_field: {id: "password"}}, [set: "pass"]],
|
529
|
-
[link: {text: "Contact Us"}],
|
530
|
-
[wait_until_exists?: [div: {id:"open-section"}]]
|
531
|
-
],
|
532
|
-
browser: ["firefox", headless: true]
|
533
|
-
}
|
534
|
-
ragios.create(monitor)
|
535
|
-
```
|
536
|
-
|
537
|
-
|
538
514
|
##License:
|
539
515
|
MIT License.
|
540
516
|
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.3.1
|
@@ -0,0 +1,36 @@
|
|
1
|
+
grammar Browsers
|
2
|
+
|
3
|
+
rule body
|
4
|
+
space? browser_name space? headless? {
|
5
|
+
def content
|
6
|
+
hash = {}
|
7
|
+
hash[:browser] = browser_name.content
|
8
|
+
hash[:headless] = !elements.last.empty?
|
9
|
+
hash
|
10
|
+
end
|
11
|
+
}
|
12
|
+
end
|
13
|
+
|
14
|
+
rule headless
|
15
|
+
"headless" space? {
|
16
|
+
def content
|
17
|
+
true
|
18
|
+
end
|
19
|
+
}
|
20
|
+
end
|
21
|
+
|
22
|
+
rule browser_name
|
23
|
+
[\S]+ {
|
24
|
+
def content
|
25
|
+
text_value
|
26
|
+
end
|
27
|
+
}
|
28
|
+
end
|
29
|
+
|
30
|
+
rule space
|
31
|
+
[\s]+ {
|
32
|
+
def content
|
33
|
+
end
|
34
|
+
}
|
35
|
+
end
|
36
|
+
end
|