selenium-dsl 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -16,19 +16,61 @@ class SeleniumDsl
16
16
  end
17
17
 
18
18
  def find_element(typ,el)
19
- wait = Selenium::WebDriver::Wait.new(:timeout => 10)
20
- wait.until { @nodes = @nodes.find_element(typ, el) }
19
+ wait = Selenium::WebDriver::Wait.new(:timeout => 5)
20
+ wait.until do
21
+ try=5
22
+ begin
23
+ # sleep 1
24
+ nodes = @nodes.find_element(typ, el)
25
+ rescue Exception => e
26
+ if e.class == Selenium::WebDriver::Error::NoSuchWindowError ||
27
+ e.class == Selenium::WebDriver::Error::NoSuchElementError
28
+ if e.class == Selenium::WebDriver::Error::NoSuchWindowError
29
+ puts "switch window from #{@driver.window_handle} to #{@driver.window_handles[0]}" if !opt_v
30
+ @driver.switch_to.window @driver.window_handles[0]
31
+ # binding.pry
32
+ end
33
+ try-= 1
34
+ try>0 ? retry : raise(e.class,e.to_s)
35
+ else
36
+ failed
37
+ end
38
+ end
39
+ @nodes = nodes if nodes
40
+ nodes
41
+ end
21
42
  print '.'.green if !opt_v
22
- rescue Exception => e
23
- failed
43
+ # rescue Exception => e
44
+ # failed
24
45
  end
25
46
 
26
47
  def find_elements(typ,el,idx)
27
- wait = Selenium::WebDriver::Wait.new(:timeout => 10)
28
- wait.until { @nodes = @nodes.find_elements(typ, el)[idx-1] }
48
+ wait = Selenium::WebDriver::Wait.new(:timeout => 5)
49
+ wait.until do
50
+ try=5
51
+ begin
52
+ # sleep 1
53
+ nodes = @nodes.find_elements(typ, el)[idx-1]
54
+ rescue Exception => e
55
+ if e.class == Selenium::WebDriver::Error::NoSuchWindowError ||
56
+ e.class == Selenium::WebDriver::Error::NoSuchElementError
57
+ if e.class == Selenium::WebDriver::Error::NoSuchWindowError
58
+ puts "switch window from #{@driver.window_handle} to #{@driver.window_handles[0]}" if !opt_v
59
+ @driver.switch_to.window @driver.window_handles[0]
60
+ # binding.pry
61
+ end
62
+ try-= 1
63
+ try>0 ? retry : raise(e.class,e.to_s)
64
+ else
65
+ failed
66
+ end
67
+ end
68
+ @nodes = nodes if nodes
69
+ nodes
70
+ end
29
71
  print '.'.green if !opt_v
30
- rescue Exception => e
31
- failed
72
+ # rescue Exception => e
73
+ # failed
32
74
  end
33
75
 
34
76
  def parse_cmd(line)
@@ -103,7 +145,7 @@ class SeleniumDsl
103
145
  if (parse_cmd(line[0]) && eval("\"#{@return}\" #{splt} /#{line[1]}/"))
104
146
  print '.'.green if !opt_v
105
147
  else
106
- print 'F'.red if !opt_v
148
+ failed #print 'F'.red if !opt_v
107
149
  end
108
150
  end
109
151
  end
@@ -119,8 +161,8 @@ class SeleniumDsl
119
161
  protected
120
162
 
121
163
  def assert(prm)
122
- if prm[0,2]=='->'
123
- if @return =~ /#{prm[2,99]}/
164
+ if prm[0,2]=='=~'
165
+ if @return =~ /#{prm[2,99].strip}/
124
166
  print '.'.green if !opt_v
125
167
  else
126
168
  failed
@@ -28,7 +28,9 @@ class SeleniumDsl
28
28
  end
29
29
 
30
30
  def _firefox(prm)
31
- @driver = Selenium::WebDriver.for :firefox
31
+ profile = Selenium::WebDriver::Firefox::Profile.new
32
+ profile['browser.cache.disk.enable'] = false
33
+ @driver = Selenium::WebDriver.for :firefox, :profile => profile
32
34
  end
33
35
 
34
36
  def _phantomjs(prm)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: selenium-dsl
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
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: 2012-12-05 00:00:00.000000000 Z
12
+ date: 2012-12-10 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: selenium-webdriver