selenium_surfer 0.0.3 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -17,11 +17,22 @@ module SeleniumSurfer
17
17
  def initialize(_msg, _context)
18
18
  super _msg
19
19
  @context = _context
20
- @source = _context.root_context.page_source # cache page source for future reference
20
+ @source = _context.root_context.page_source rescue nil # cache page source for future reference
21
21
  end
22
22
  end
23
23
 
24
24
  # Error thrown when an element operation is attempted in an empty search result set
25
25
  class EmptySetError < ContextError; end
26
26
 
27
+ # Wraps a web driver error adding
28
+ class WebDriverError < ContextError
29
+
30
+ attr_reader :original
31
+
32
+ def initialize(_original, _context)
33
+ super _original.message, _context
34
+ @original = _original
35
+ end
36
+ end
37
+
27
38
  end
@@ -46,19 +46,23 @@ module SeleniumSurfer
46
46
  # clears and sends_keys to this context main element
47
47
  def fill(_value)
48
48
  raise EmptySetError.new('Cannot call \'fill\' on an empty set', self) if empty?
49
- context.first.clear
50
- context.first.send_keys _value
49
+ wrap_errors do
50
+ context.first.clear
51
+ context.first.send_keys _value
52
+ end
51
53
  end
52
54
 
53
55
  # Any methods missing are forwarded to the main element (first).
54
56
  def method_missing(_method, *_args, &_block)
55
- m = /^(.*)_all$/.match _method.to_s
56
- if m then
57
- return [] if empty?
58
- context.map { |e| e.send(m[1], *_args, &_block) }
59
- else
60
- raise EmptySetError.new("Cannot call '#{_method}' on an empty set", self) if empty?
61
- context.first.send(_method, *_args, &_block)
57
+ wrap_errors do
58
+ m = /^(.*)_all$/.match _method.to_s
59
+ if m then
60
+ return [] if empty?
61
+ context.map { |e| e.send(m[1], *_args, &_block) }
62
+ else
63
+ raise EmptySetError.new("Cannot call '#{_method}' on an empty set", self) if empty?
64
+ context.first.send(_method, *_args, &_block)
65
+ end
62
66
  end
63
67
  end
64
68
 
@@ -76,12 +80,25 @@ module SeleniumSurfer
76
80
 
77
81
  private
78
82
 
83
+ # wrap every selenium errors that happen inside block.
84
+ def wrap_errors
85
+ begin
86
+ yield
87
+ rescue Selenium::WebDriver::Error::WebDriverError => e
88
+ raise WebDriverError.new e, self
89
+ end
90
+ end
91
+
92
+ # base filtering method, expands current context
79
93
  def search_elements(_options)
80
- context.inject([]) do |r, element|
81
- r + element.find_elements(_options)
94
+ wrap_errors do
95
+ context.inject([]) do |r, element|
96
+ r + element.find_elements(_options)
97
+ end
82
98
  end
83
99
  end
84
100
 
101
+ # returns the current context
85
102
  def context
86
103
  @elements
87
104
  end
@@ -1,3 +1,3 @@
1
1
  module SeleniumSurfer
2
- VERSION = "0.0.3"
2
+ VERSION = "0.1.1"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: selenium_surfer
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.1.1
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: 2013-08-14 00:00:00.000000000 Z
12
+ date: 2013-09-26 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: selenium-webdriver