watir 2.0.3 → 2.0.4

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGES CHANGED
@@ -1,3 +1,8 @@
1
+ == Version 2.0.4 - 2011/10/29
2
+
3
+ * IE#execute_script escapes multi-line JavaScript scripts
4
+ * allow css and xpath locators for element collection methods, fixes http://jira.openqa.org/browse/WTR-493
5
+
1
6
  == Version 2.0.3 - 2011/10/21
2
7
 
3
8
  * fix ElementCollections#[]
data/VERSION CHANGED
@@ -1 +1 @@
1
- 2.0.3
1
+ 2.0.4
@@ -16,38 +16,38 @@ module Watir
16
16
 
17
17
  # Return the options used when creating new instances of IE.
18
18
  # BUG: this interface invites misunderstanding/misuse such as IE.options[:speed] = :zippy]
19
- def self.options
20
- {:speed => self.speed, :visible => self.visible, :attach_timeout => self.attach_timeout, :zero_based_indexing => self.zero_based_indexing}
21
- end
19
+ def self.options
20
+ {:speed => self.speed, :visible => self.visible, :attach_timeout => self.attach_timeout, :zero_based_indexing => self.zero_based_indexing}
21
+ end
22
22
  # set values for options used when creating new instances of IE.
23
- def self.set_options options
24
- options.each do |name, value|
25
- send "#{name}=", value
26
- end
27
- end
28
- # The globals $FAST_SPEED and $HIDE_IE are checked both at initialization
29
- # and later, because they
30
- # might be set after initialization. Setting them beforehand (e.g. from
31
- # the command line) will affect the class, otherwise it is only a temporary
32
- # effect
33
- @@speed = $FAST_SPEED ? :fast : :slow
34
- def self.speed
35
- return :fast if $FAST_SPEED
36
- @@speed
37
- end
38
- def self.speed= x
39
- $FAST_SPEED = nil
40
- @@speed = x
41
- end
42
- @@visible = $HIDE_IE ? false : true
43
- def self.visible
44
- return false if $HIDE_IE
45
- @@visible
46
- end
47
- def self.visible= x
48
- $HIDE_IE = nil
49
- @@visible = x
50
- end
23
+ def self.set_options options
24
+ options.each do |name, value|
25
+ send "#{name}=", value
26
+ end
27
+ end
28
+ # The globals $FAST_SPEED and $HIDE_IE are checked both at initialization
29
+ # and later, because they
30
+ # might be set after initialization. Setting them beforehand (e.g. from
31
+ # the command line) will affect the class, otherwise it is only a temporary
32
+ # effect
33
+ @@speed = $FAST_SPEED ? :fast : :slow
34
+ def self.speed
35
+ return :fast if $FAST_SPEED
36
+ @@speed
37
+ end
38
+ def self.speed= x
39
+ $FAST_SPEED = nil
40
+ @@speed = x
41
+ end
42
+ @@visible = $HIDE_IE ? false : true
43
+ def self.visible
44
+ return false if $HIDE_IE
45
+ @@visible
46
+ end
47
+ def self.visible= x
48
+ $HIDE_IE = nil
49
+ @@visible = x
50
+ end
51
51
 
52
52
  @@zero_based_indexing = true
53
53
  def self.zero_based_indexing= enabled
@@ -202,20 +202,20 @@ module Watir
202
202
  def speed= how_fast
203
203
  case how_fast
204
204
  when :zippy then
205
- @typingspeed = 0
206
- @pause_after_wait = 0.01
207
- @type_keys = false
208
- @speed = :fast
205
+ @typingspeed = 0
206
+ @pause_after_wait = 0.01
207
+ @type_keys = false
208
+ @speed = :fast
209
209
  when :fast then
210
- @typingspeed = 0
211
- @pause_after_wait = 0.01
212
- @type_keys = true
213
- @speed = :fast
210
+ @typingspeed = 0
211
+ @pause_after_wait = 0.01
212
+ @type_keys = true
213
+ @speed = :fast
214
214
  when :slow then
215
- @typingspeed = 0.08
216
- @pause_after_wait = 0.1
217
- @type_keys = true
218
- @speed = :slow
215
+ @typingspeed = 0.08
216
+ @pause_after_wait = 0.1
217
+ @type_keys = true
218
+ @speed = :slow
219
219
  else
220
220
  raise ArgumentError, "Invalid speed: #{how_fast}"
221
221
  end
@@ -228,12 +228,12 @@ module Watir
228
228
 
229
229
  # deprecated: use speed = :fast instead
230
230
  def set_fast_speed
231
- self.speed = :fast
231
+ self.speed = :fast
232
232
  end
233
233
 
234
234
  # deprecated: use speed = :slow instead
235
235
  def set_slow_speed
236
- self.speed = :slow
236
+ self.speed = :slow
237
237
  end
238
238
 
239
239
  def visible
@@ -327,7 +327,7 @@ module Watir
327
327
  end
328
328
  rescue Watir::Wait::TimeoutError
329
329
  raise NoMatchingWindowFoundException,
330
- "Unable to locate a window with #{how} of #{what}"
330
+ "Unable to locate a window with #{how} of #{what}"
331
331
  end
332
332
  @ie = ieTemp
333
333
  end
@@ -340,7 +340,7 @@ module Watir
340
340
  end
341
341
  attr_writer :hwnd
342
342
 
343
- # Are we attached to an open browser?
343
+ # Are we attached to an open browser?
344
344
  def exists?
345
345
  begin
346
346
  !!(@ie.name =~ /Internet Explorer/)
@@ -419,12 +419,11 @@ module Watir
419
419
 
420
420
  # Execute the given JavaScript string
421
421
  def execute_script(source)
422
- document.parentWindow.eval(source.to_s)
422
+ escaped_src = source.to_s.gsub(/[\r\n']/) {|m| "\\#{m}"}
423
+ document.parentWindow.eval(escaped_src)
423
424
  rescue WIN32OLERuntimeError, NoMethodError #if eval fails we need to use execScript(source.to_s) which does not return a value, hence the workaround
424
425
  wrapper = "_watir_helper_div_#{rand(100000)}"
425
- escaped_src = source.to_s
426
- escaped_src = escaped_src.gsub("'", "\\\\'")
427
- cmd = "var e= document.createElement('DIV'); e.id='#{wrapper}'; e.innerHTML= eval('#{escaped_src}');document.body.appendChild(e);"
426
+ cmd = "var e = document.createElement('DIV'); e.id='#{wrapper}'; e.innerHTML = eval('#{escaped_src}'); document.body.appendChild(e);"
428
427
  document.parentWindow.execScript(cmd)
429
428
  wrapper_obj = document.getElementById(wrapper)
430
429
  result_value = wrapper_obj.innerHTML
@@ -29,6 +29,7 @@ module Watir
29
29
  end
30
30
 
31
31
  def match_with_specifiers?(element)
32
+ return true if has_excluding_specifiers?
32
33
  @specifiers.all? {|how, what| how == :index || match?(element, how, what)}
33
34
  end
34
35
 
@@ -9,49 +9,41 @@
9
9
  $LOAD_PATH.unshift File.join(File.dirname(__FILE__), '..') unless $SETUP_LOADED
10
10
  require 'unittests/setup'
11
11
 
12
- # Since the CSS selectors were added to Watir::IE, these CSS selector tests
13
- # will fail when using Firefox, until someone implements the method
14
- # "element_by_css(selector)" for that browser that is.. so for now only run
15
- # them for IE.
16
- if Watir::Browser.default == 'ie'
17
-
18
- class TC_CSS_Selector < Test::Unit::TestCase
19
- include Watir::Exception
20
-
21
- # Same test as TC_Divs_XPath::test_divs but using css selectors instead
22
- def test_matching_queries
23
- goto_page "div.html"
24
-
25
- assert_raises(UnknownObjectException) {browser.div(:css , "div[id='div77']").click }
26
- assert_raises(UnknownObjectException) {browser.div(:css , "div[title='div77']").click }
27
-
28
- assert(browser.text_field(:css, "input[name='text1']").verify_contains("0") )
29
- browser.div(:css , "div[id='div3']").click
30
- assert(browser.text_field(:css, "input[ name = 'text1' ]").verify_contains("1") )
31
- browser.div(:css , "div[id = div4]").click
32
- assert(browser.text_field(:css, "input[name=text1]").verify_contains("0") )
33
- end
34
-
35
- def test_form
36
- goto_page "forms2.html"
37
- assert(browser.form(:css, "#f2").action =~ /pass2.html$/)
38
- assert_equal(browser.button(:css, "form #b2").value, "Click Me")
39
- end
40
-
41
- def test_image
42
- goto_page "div.html"
43
- assert_equal( "circle", browser.image(:css, "*[id ^= 'circ']").id )
44
- end
45
-
46
- def test_link
47
- goto_page "links1.html"
48
- assert_equal( "link_name", browser.link(:css, "*[name *= ink_nam]").name )
49
- end
50
-
51
- def test_table
52
- goto_page "table1.html"
53
- assert_equal( "Header", browser.cell(:css , ".sample th").text )
54
- end
55
- end
56
-
57
- end
12
+ class TC_CSS_Selector < Test::Unit::TestCase
13
+ include Watir::Exception
14
+
15
+ # Same test as TC_Divs_XPath::test_divs but using css selectors instead
16
+ def test_matching_queries
17
+ goto_page "div.html"
18
+
19
+ assert_raises(UnknownObjectException) {browser.div(:css , "div[id='div77']").click }
20
+ assert_raises(UnknownObjectException) {browser.div(:css , "div[title='div77']").click }
21
+
22
+ assert(browser.text_field(:css, "input[name='text1']").verify_contains("0") )
23
+ browser.div(:css , "div[id='div3']").click
24
+ assert(browser.text_field(:css, "input[ name = 'text1' ]").verify_contains("1") )
25
+ browser.div(:css , "div[id = div4]").click
26
+ assert(browser.text_field(:css, "input[name=text1]").verify_contains("0") )
27
+ end
28
+
29
+ def test_form
30
+ goto_page "forms2.html"
31
+ assert(browser.form(:css, "#f2").action =~ /pass2.html$/)
32
+ assert_equal(browser.button(:css, "form #b2").value, "Click Me")
33
+ end
34
+
35
+ def test_image
36
+ goto_page "div.html"
37
+ assert_equal( "circle", browser.image(:css, "*[id ^= 'circ']").id )
38
+ end
39
+
40
+ def test_link
41
+ goto_page "links1.html"
42
+ assert_equal( "link_name", browser.link(:css, "*[name *= ink_nam]").name )
43
+ end
44
+
45
+ def test_table
46
+ goto_page "table1.html"
47
+ assert_equal( "Header", browser.cell(:css , ".sample th").text )
48
+ end
49
+ end
@@ -62,6 +62,12 @@ class TC_ElementCollections < Test::Unit::TestCase
62
62
  elements.each do |element|
63
63
  assert Watir::Div, element.class
64
64
  end
65
+
66
+ elements = browser.elements(:css => "div")
67
+ assert 2, elements.size
68
+ elements.each do |element|
69
+ assert Watir::Div, element.class
70
+ end
65
71
  end
66
72
 
67
73
  def test_multiple_specifiers
@@ -1,9 +1,8 @@
1
1
  # Unit Test for Internet Explorer
2
2
 
3
3
  $LOAD_PATH.unshift File.join(File.dirname(__FILE__), '..') unless $SETUP_LOADED
4
- require 'watir/win32ole'
4
+ require 'unittests/setup'
5
5
  require 'unittests/ie_mock'
6
- require 'test/unit'
7
6
 
8
7
  class TC_ie < Test::Unit::TestCase
9
8
  include Watir::Exception
@@ -35,12 +34,21 @@ class TC_ie < Test::Unit::TestCase
35
34
  @faked_ie.tagged_element_locator('A', :no_such_mechanism, "verifying error handling")
36
35
  end
37
36
  end
37
+
38
+ def test_execute_script
39
+ script = %q[
40
+ var x = 'something';
41
+ var y = " else";
42
+ x + y;
43
+ ]
44
+ assert_equal "something else", browser.execute_script(script)
45
+ end
38
46
 
39
47
  # is this correct?
40
48
  def test_getLink_ByUrlReturnsNilOnNoLinks
41
49
  assert_nil(@faked_ie.tagged_element_locator('A', :url, "whatever"))
42
50
  end
43
-
51
+
44
52
  # is this correct?
45
53
  def test_getLink_ByTextReturnsNilOnNoLinks
46
54
  assert_nil(@faked_ie.tagged_element_locator('A', :text, "whatever"))
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: watir
3
3
  version: !ruby/object:Gem::Version
4
- hash: 9
4
+ hash: 7
5
5
  prerelease:
6
6
  segments:
7
7
  - 2
8
8
  - 0
9
- - 3
10
- version: 2.0.3
9
+ - 4
10
+ version: 2.0.4
11
11
  platform: ruby
12
12
  authors:
13
13
  - Bret Pettichord
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-10-21 00:00:00 Z
18
+ date: 2011-10-28 00:00:00 Z
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
21
21
  name: win32-process
@@ -57,12 +57,12 @@ dependencies:
57
57
  requirements:
58
58
  - - "="
59
59
  - !ruby/object:Gem::Version
60
- hash: 9
60
+ hash: 7
61
61
  segments:
62
62
  - 2
63
63
  - 0
64
- - 3
65
- version: 2.0.3
64
+ - 4
65
+ version: 2.0.4
66
66
  type: :runtime
67
67
  version_requirements: *id003
68
68
  - !ruby/object:Gem::Dependency