Module: Watirloo::Locker
- Defined in:
- lib/watirloo/locker.rb
Overview
manages references to browsers we care about to run tests agains. Saves references to window handles internall to yaml file so we can reuse the browser for tests by reattaching to it between tests. you put reference to a browser in storage. Next time you run a test you can restore the browser’s reference instead fo staring a new one.
Constant Summary collapse
- @@locker_file =
File.join(ENV['TEMP'], "watirloo_temp_locker.yml")
Class Method Summary collapse
-
.add(browser, key = 'default') ⇒ Object
add browser to storage for later reuse.
-
.browser(key = 'default') ⇒ Object
returns IE reference to a browser with a given key.
-
.clear ⇒ Object
clear Storage.
- .locker ⇒ Object
- .locker=(locker) ⇒ Object
-
.mapping ⇒ Object
hash of => IE.hwnd to attach and reuse browsers example: mapping = 234567, :bla => 234234.
-
.remove(key = 'default') ⇒ Object
remove browser from storage and from further reusing.
Class Method Details
.add(browser, key = 'default') ⇒ Object
add browser to storage for later reuse. by convention if you don’t have any browsers it so you can later restore it and continue working with it. pass either browser referene or the hwnd Fixnum
54 55 56 57 |
# File 'lib/watirloo/locker.rb', line 54 def add(browser, key='default') mapping[key] = browser.kind_of?(Watir::IE) ? browser.hwnd : browser save_mapping end |
.browser(key = 'default') ⇒ Object
returns IE reference to a browser with a given key
43 44 45 46 47 48 49 |
# File 'lib/watirloo/locker.rb', line 43 def browser(key='default') if key == 'default' (@browser && @browser.exists?) ? @browser : @browser = attach_browser else attach_browser(key) end end |
.clear ⇒ Object
clear Storage
67 68 69 70 71 |
# File 'lib/watirloo/locker.rb', line 67 def clear @browser = nil mapping.clear save_mapping end |
.locker ⇒ Object
34 35 36 |
# File 'lib/watirloo/locker.rb', line 34 def locker @@locker_file end |
.locker=(locker) ⇒ Object
38 39 40 |
# File 'lib/watirloo/locker.rb', line 38 def locker=( locker ) @@locker_file = locker end |
.mapping ⇒ Object
hash of => IE.hwnd to attach and reuse browsers example: mapping = 234567, :bla => 234234
30 31 32 |
# File 'lib/watirloo/locker.rb', line 30 def mapping @mapping ||= read_mapping end |
.remove(key = 'default') ⇒ Object
remove browser from storage and from further reusing
60 61 62 63 64 |
# File 'lib/watirloo/locker.rb', line 60 def remove(key='default') @browser = nil if key == 'default' mapping.delete(key) if mapping[key] save_mapping end |