uptime_monitor 0.0.4 → 0.0.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. data/README.md +179 -41
  2. data/VERSION +1 -1
  3. data/uptime_monitor.gemspec +3 -3
  4. metadata +4 -4
data/README.md CHANGED
@@ -1,6 +1,7 @@
1
1
  uptime_monitor (Hercules)
2
2
  ==========================
3
3
  [![Build Status](https://travis-ci.org/obi-a/uptime_monitor.png?branch=master)](https://travis-ci.org/obi-a/uptime_monitor)
4
+ [![Gem Version](https://badge.fury.io/rb/uptime_monitor.svg)](http://badge.fury.io/rb/uptime_monitor)
4
5
 
5
6
  Uptime_monitor is a [ragios](https://github.com/obi-a/ragios) plugin that uses a real web browser to perform transactions on a website to ensure that features of the site are still working correctly. It can check elements of a webpage to ensure they still exist and it can also perform transactions like a website login to ensure that the process still works correctly.
6
7
 
@@ -34,7 +35,7 @@ monitor = {monitor: "My Blog title tag",
34
35
  }
35
36
  ragios.add [monitor]
36
37
  ```
37
- 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 on the page matches the text "Obi Akubue".
38
+ 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 on the page matches the text "Obi Akubue". When the title tag doesn't match the text, a failure notification will be sent out to the contact.
38
39
 
39
40
  ###Using the plugin
40
41
  To use the uptime monitor plugin add the key/value pair to the monitor
@@ -43,7 +44,7 @@ plugin: "uptime_monitor"
43
44
  ```
44
45
 
45
46
  ###Browsers
46
- The browser to use is specified, by adding a browser key/value pair to the monitor
47
+ A browser is specified, by adding a browser key/value pair to the monitor
47
48
  ```ruby
48
49
  browser: ["firefox"]
49
50
  ```
@@ -53,7 +54,7 @@ browser: ["chrome"]
53
54
  browser: ["safari"]
54
55
  browser: ["phantomjs"]
55
56
  ```
56
- uptime_monitor uses [Watir Webdriver](http://watirwebdriver.com), firefox runs out of the box with no configuration requried. To use Chrome or Safari see the Watir Webdriver documentation on downloading the appropriate driver binary and configuration.
57
+ 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.
57
58
 
58
59
  By default, the browsers don't run headless, to run the browser headless, you can specify it in the format below:
59
60
  ```ruby
@@ -75,7 +76,7 @@ exists?: [
75
76
  [:div]
76
77
  ]
77
78
  ```
78
- The above example will verify that an h1 and a div exists on the page.
79
+ The above example will verify that a h1 and a div exists on the page.
79
80
 
80
81
  ####HTML Elements
81
82
  The simplest way to specify a html element is using a symbol.
@@ -112,7 +113,7 @@ Specifes a div with id="test" and class="test-section".
112
113
 
113
114
  Only standard attributes for an element can be included in the hash, for example a div can only include all or any of the following attributes id, class, lang, dir, title, align, onclick, ondblclick, onmousedown, onmouseup, onmouseover, onmousemove, onmouseout, onkeypress, onkeydown, onkeyup.
114
115
 
115
- Custom or data attributes cannot be included, for example to specify a div by data attributes, for example
116
+ Custom or data attributes cannot be included, for example
116
117
  ```html
117
118
  <div data-brand="toyota">
118
119
  ```
@@ -139,13 +140,14 @@ To specify an element by data attributes
139
140
  Helpers are available to make some elements easier to reason about:
140
141
 
141
142
  #####Links
142
- An anchor tag could be specified by a link, this makes it more readable and easier to reason about
143
+ An anchor tag could be specified with a link helper, this makes it more readable and easier to reason about.
144
+
143
145
  Using the anchor tag
144
146
  ```ruby
145
147
  [a: {text: "Click Here"}]
146
148
  ```
147
149
 
148
- More readble using helper
150
+ More readble using a helper
149
151
  ```ruby
150
152
  [link: {text: "Click Here"}]
151
153
  ```
@@ -166,10 +168,10 @@ More readble using helper
166
168
 
167
169
  More readable than the input tag
168
170
  ```ruby
169
- [input: {id: "search", type: "text"}]
171
+ [input: {id: "search"}]
170
172
  ```
171
173
 
172
- #####Checkbox
174
+ #####Checkboxes
173
175
  ```ruby
174
176
  [checkbox: {value: "Butter"}]
175
177
  ```
@@ -178,7 +180,7 @@ More readable than the input tag
178
180
  [radio: {name: "group1", value: "Milk"}]
179
181
  ```
180
182
 
181
- ######Drop Down menus
183
+ #####Drop Down menus
182
184
  ```html
183
185
  <select name="mydropdown">
184
186
  <option value="Milk">Fresh Milk</option>
@@ -202,38 +204,119 @@ Options of the drop-down menu can be specified using option
202
204
  ```
203
205
 
204
206
  ####Text Validations
207
+ A text validation is used to verify that the text content of a html element hasn't changed. For example,
208
+ ```ruby
209
+ exists?: [
210
+ [:title, [text: "Welcome to my site"]]
211
+ ]
212
+ ```
213
+ 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".
214
+ The following is a text validation:
215
+ ```ruby
216
+ [text: "Welcome to my site"]
217
+ ```
218
+ Text validations can also verify that the html element's text includes the provided string, in the format below:
219
+ ```ruby
220
+ exists?: [
221
+ [:title, [includes_text: "Welcome"]]
222
+ ]
223
+ ```
224
+ The above example verifies that the title tag's text includes the string "Welcome".
225
+ Another example, to verify that a div with class="box_content" includes the string "SouthMunn is a Website"
226
+ ```ruby
227
+ exists?: [
228
+ [{div: {class: "box_content"}}, [includes_text: "SouthMunn is a Website"]]
229
+ ]
230
+ ```
231
+ Text validations can be used on html elements that can contain text like title, div, span, h1, h2 etc.
205
232
 
206
- ... more documentation coming soon
233
+ ####Actions
234
+ Validations can also include actions. The actions are performed on the html element after it is validated. Example to set a text field's value
235
+ ```ruby
236
+ exists?: [
237
+ [{text_field: {id: "username"}}, [set: "admin"]]
238
+ ]
239
+ ```
240
+ The above example will set the text field's value to the string "admin".
241
+ The following is an action
242
+ ```ruby
243
+ [set: "admin"]
244
+ ```
245
+ #####Actions on html elements
246
+ Common actions performed on elements are set, select and click.
207
247
 
208
- ##Specification:
248
+ Set value for a textfield or textarea.
249
+ ```ruby
250
+ [{text_field: {name: "q"}}, [set: "ruby"]]
251
+ [{text_area: {name: "longtext"}}, [set: "In a world..."]]
252
+ ```
253
+ Select an option from a drop down menu
254
+ ```html
255
+ <select name="mydropdown">
256
+ <option value="Milk">Fresh Milk</option>
257
+ <option value="Cheese">Old Cheese</option>
258
+ <option value="Bread">Hot Bread</option>
259
+ </select>
260
+ ```
261
+ ```ruby
262
+ [{select_list: {name: "mydropdown"}},[select: "Old Cheese"]]
263
+ ```
264
+ Click a radio button, checkbox, link or button
265
+ ```ruby
266
+ [{radio: {name: "group1", value: "Milk"}}, [:click]]
267
+ [{checkbox:{name: "checkbox"}}, [:click]]
268
+ [{link: {text: "Click Here"}}, [:click]]
269
+ [{button: {id: "submit"}}, [:click]]
270
+ ```
271
+ ####Waiting
272
+ For webpages that use a lot of AJAX, it's possible to wait until an element exists, by using the wait_until_exists? key. This key 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.
273
+ ```ruby
274
+ [wait_until_exists?: [div: {id:"open-section"}]]
275
+ ```
276
+ The above example will wait 30 seconds until the div exists, if it doesn't exist after 30 seconds the validation will fail.
209
277
 
210
- <pre lang="ruby">
211
- monitor = {monitor: "My Website",
212
- url: "http://mysite.com",
213
- every: "5m",
214
- contact: "admin@mail.com",
215
- via: "email_notifier",
278
+ ####Multiple validations and actions
279
+ ```ruby
280
+ exists?: [
281
+ [{text_field: {id: "username"}}, [set: "admin"]],
282
+ [{text_field: {id: "password"}}, [set: "pass"]],
283
+ [:button, [:click]],
284
+ [:title, [includes_text: "Dashboard"]]
285
+ ]
286
+ ```
287
+ 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 it's test if any of the validation fails. So for the monitor to pass, all validations must pass.
288
+
289
+ When actions like clicking a link, changes the current page, the following validations will be performed on the new page.
290
+
291
+ A combination of multiple validations and actions form the basis for performing transactions.
292
+
293
+
294
+ ####Performing Transactions
295
+ Transactions are achieved by a combination of multiple validations and actions.
296
+
297
+ To monitor the keyword search feature on my blog:
298
+ ```ruby
299
+ monitor = {monitor: "My Blog: keyword search",
300
+ url: "http://obi-akubue.org",
301
+ every: "1h",
302
+ contact: "admin@obiora.com",
303
+ via: "gmail_notifier",
216
304
  plugin: "uptime_monitor",
217
305
  exists?: [
218
- [:title, [text: "Welcome to my site"]],
219
- [{div: {id:"test", class: "test-section"}}, [text: "this is a test"]],
220
- [a: {href: "/aboutus" }],
221
- [:h1],
222
- [:h2,[text: "Login"]],
223
- [form: {action: "/signup", method: "get"}],
224
- [{element: {css: "#submit-button"}}, [:click]],
225
- [{text_field: {id: "username"}}, [set: "admin"]],
226
- [{text_field: {id: "password"}}, [set: "pass"]],
227
- [link: {text: "Contact Us"}],
228
- [wait_until_exists?: [div: {id:"open-section"}]]
306
+ [:title,[text: "Obi Akubue"]],
307
+ [{text_field: {id: "s"}}, [set: "ruby"]],
308
+ [{button:{id: "searchsubmit"}}, [:click]],
309
+ [:title, [includes_text: "ruby"], [includes_text: "Search Results"]],
310
+ [{h2:{class: "pagetitle"}},[includes_text: "Search results for"]]
229
311
  ],
230
- browser: ["firefox", headless: true]
312
+ browser: ["firefox"]
231
313
  }
232
314
  ragios.add [monitor]
233
- </pre>
315
+ ```
316
+ 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 tag and h2 tag of the search results page contains the expected text.
234
317
 
235
- ###Monitor login process of a real site
236
- <pre lang="ruby">
318
+ Another example, to monitor the login process of the website southmunn.com
319
+ ```ruby
237
320
  login_process = [
238
321
  [:title, [text: "Website Uptime Monitoring | SouthMunn.com"]],
239
322
  [{link: {text:"Login"}}, [:click]],
@@ -244,20 +327,23 @@ login_process = [
244
327
  [:title, [text: "Dashboard - Website Uptime Monitoring | SouthMunn.com"]]
245
328
  ]
246
329
 
247
- monitor = {monitor: "My Website",
330
+ monitor = {monitor: "My Website login processs",
248
331
  url: "https:/southmunn.com",
249
- every: "5m",
250
- contact: "admin@mail.com",
332
+ every: "1h",
333
+ contact: "admin@obiora.com",
251
334
  via: "email_notifier",
252
335
  plugin: "uptime_monitor",
253
336
  exists?: login_process,
254
337
  browser: ["firefox", headless: true]
255
338
  }
256
339
  ragios.add [monitor]
257
- </pre>
340
+ ```
341
+
342
+ ####Testing the validations outside Ragios
343
+ Sometimes it's useful to run validations outside Ragios to verify that the validations are syntactically correct and don't raise any exceptions. This is best done by running the uptime_monitor plugin as a Plain Old Ruby Object.
344
+ ```ruby
345
+ require 'uptime_monitor'
258
346
 
259
- ###Real site test:
260
- <pre lang="ruby">
261
347
  monitor = {monitor: "About Us page",
262
348
  url: "https://www.southmunn.com/aboutus",
263
349
  browser: ["firefox", headless: false],
@@ -268,7 +354,7 @@ monitor = {monitor: "About Us page",
268
354
  }
269
355
 
270
356
  u = Ragios::Plugin::UptimeMonitor.new
271
- u.init monitor
357
+ u.init(monitor)
272
358
  u.test_command?
273
359
  #=> true
274
360
  u.test_result
@@ -294,6 +380,58 @@ u.test_result
294
380
  # {:src=>
295
381
  # "https://fc03.deviantart.net/fs14/f/2007/047/f/2/Street_Addiction_by_gizmodus.jpg"}}]=>
296
382
  # :does_not_exist_as_expected}
383
+ ```
384
+ In the above example the test_command?() method runs all 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?().
385
+
386
+ ####Testing individual validations
387
+ It can be very useful to test validations individually before adding them to Ragios. This can be done by running plugin's browser object directly.
388
+ ```ruby
389
+ require 'uptime_monitor'
390
+
391
+ url= "http://obi-akubue.org"
392
+ headless = false
393
+ browser_name = "firefox"
394
+ browser = Hercules::UptimeMonitor::Browser.new(url, browser_name, headless)
395
+
396
+ browser.exists? [:title, [includes_text: "ruby"]]
397
+
398
+ browser.exists? [{h2:{class: "pagetitle"}}]
399
+
400
+ browser.exists? [{checkbox:{name: "checkbox"}}, [:click]]
401
+
402
+ browser.close
403
+ ```
404
+ The above example creates a browser object and visits the url. The exists? method takes a single validation as arguement and performs the validation on the url, it returns true if the validation passes and returns false if the validation fails. In the first validation it checks if the title tag on the url includes the text 'ruby'.
405
+
406
+
407
+ ##Specification:
408
+ <pre lang="ruby">
409
+ monitor = {monitor: "My Website",
410
+ url: "http://mysite.com",
411
+ every: "5m",
412
+ contact: "admin@obiora.com",
413
+ via: "mail_notifier",
414
+ plugin: "uptime_monitor",
415
+ exists?: [
416
+ [:title, [text: "Welcome to my site"]],
417
+ [{div: {id:"test", class: "test-section"}}, [text: "this is a test"]],
418
+ [a: {href: "/aboutus" }],
419
+ [:h1],
420
+ [:h2,[text: "Login"]],
421
+ [form: {action: "/signup", method: "get"}],
422
+ [{element: {css: "#submit-button"}}, [:click]],
423
+ [{text_field: {id: "username"}}, [set: "admin"]],
424
+ [{text_field: {id: "password"}}, [set: "pass"]],
425
+ [link: {text: "Contact Us"}],
426
+ [wait_until_exists?: [div: {id:"open-section"}]]
427
+ ],
428
+ browser: ["firefox", headless: true]
429
+ }
430
+ ragios.add [monitor]
297
431
  </pre>
298
432
 
299
- ###More details coming soon
433
+
434
+ ##License:
435
+ MIT License.
436
+
437
+ Copyright (c) 2014 Obi Akubue, obi-akubue.org
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.4
1
+ 0.0.5
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = "uptime_monitor"
8
- s.version = "0.0.4"
8
+ s.version = "0.0.5"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["obi-a"]
12
- s.date = "2014-04-06"
12
+ s.date = "2014-04-12"
13
13
  s.description = "A Ragios plugin that uses a real web browser to monitor transactions on a website for availability"
14
14
  s.email = "obioraakubue@yahoo.com"
15
15
  s.extra_rdoc_files = [
@@ -38,7 +38,7 @@ Gem::Specification.new do |s|
38
38
  s.homepage = "http://github.com/obi-a/uptime_monitor"
39
39
  s.licenses = ["MIT"]
40
40
  s.require_paths = ["lib"]
41
- s.rubygems_version = "1.8.24"
41
+ s.rubygems_version = "1.8.28"
42
42
  s.summary = "Real browser website uptime monitoring plugin for Ragios"
43
43
 
44
44
  if s.respond_to? :specification_version then
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: uptime_monitor
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 0.0.5
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2014-04-06 00:00:00.000000000 Z
12
+ date: 2014-04-12 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: headless
@@ -196,7 +196,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
196
196
  version: '0'
197
197
  segments:
198
198
  - 0
199
- hash: 660930515595020497
199
+ hash: -2995370031578709279
200
200
  required_rubygems_version: !ruby/object:Gem::Requirement
201
201
  none: false
202
202
  requirements:
@@ -205,7 +205,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
205
205
  version: '0'
206
206
  requirements: []
207
207
  rubyforge_project:
208
- rubygems_version: 1.8.24
208
+ rubygems_version: 1.8.28
209
209
  signing_key:
210
210
  specification_version: 3
211
211
  summary: Real browser website uptime monitoring plugin for Ragios