watir-webdriver 0.5.8 → 0.6.0

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -6,11 +6,6 @@ See http://rubyforge.org/pipermail/wtr-development/2009-October/001313.html.
6
6
 
7
7
  [![Build Status](https://secure.travis-ci.org/watir/watir-webdriver.png)](http://travis-ci.org/watir/watir-webdriver)
8
8
 
9
- API docs
10
- --------
11
-
12
- http://jarib.github.com/watir-webdriver/doc/
13
-
14
9
  Example
15
10
  -------
16
11
  ```ruby
@@ -39,9 +34,16 @@ watir-webdriver uses [watirspec](http://github.com/watir/watirspec) for testing.
39
34
 
40
35
  Specs specific to watir-webdriver are found in spec/*_spec.rb, with watirspec in spec/watirspec.
41
36
 
37
+ API docs
38
+ --------
39
+
40
+ * http://rdoc.info/gems/watir-webdriver/ (basic docs, updated on every release)
41
+ * http://watir.github.com/watir-webdriver/doc/ (includes all attribute methods, updated occasionally)
42
+
42
43
  See also
43
44
  --------
44
45
 
46
+ * http://watirwebdriver.com
45
47
  * http://github.com/jarib/webidl
46
48
  * http://github.com/watir/watirspec
47
49
  * http://selenium.googlecode.com
@@ -7,6 +7,7 @@ require 'watir-webdriver/exception'
7
7
  require 'watir-webdriver/xpath_support'
8
8
  require 'watir-webdriver/window'
9
9
  require 'watir-webdriver/has_window'
10
+ require 'watir-webdriver/alert'
10
11
  require 'watir-webdriver/atoms'
11
12
  require 'watir-webdriver/container'
12
13
  require 'watir-webdriver/cookies'
@@ -16,6 +17,7 @@ require 'watir-webdriver/locators/text_field_locator'
16
17
  require 'watir-webdriver/locators/child_row_locator'
17
18
  require 'watir-webdriver/locators/child_cell_locator'
18
19
  require 'watir-webdriver/browser'
20
+ require 'watir-webdriver/screenshot'
19
21
 
20
22
  module Watir
21
23
  @always_locate = true
@@ -0,0 +1,53 @@
1
+ # encoding: utf-8
2
+ module Watir
3
+ class Alert
4
+
5
+ include EventuallyPresent
6
+
7
+ def initialize(target_locator)
8
+ @target_locator = target_locator
9
+ @alert = nil
10
+ end
11
+
12
+ def text
13
+ assert_exists
14
+ @alert.text
15
+ end
16
+
17
+ def ok
18
+ assert_exists
19
+ @alert.accept
20
+ end
21
+
22
+ def close
23
+ assert_exists
24
+ @alert.dismiss
25
+ end
26
+
27
+ def set(value)
28
+ assert_exists
29
+ @alert.send_keys(value)
30
+ end
31
+
32
+ def exists?
33
+ assert_exists
34
+ true
35
+ rescue UnknownObjectException
36
+ false
37
+ end
38
+ alias_method :present?, :exists?
39
+
40
+ def selector_string
41
+ 'alert'
42
+ end
43
+
44
+ private
45
+
46
+ def assert_exists
47
+ @alert = @target_locator.alert
48
+ rescue Selenium::WebDriver::Error::NoAlertPresentError
49
+ raise UnknownObjectException, 'unable to locate alert'
50
+ end
51
+
52
+ end # Alert
53
+ end # Watir
@@ -102,6 +102,10 @@ module Watir
102
102
  @driver.page_source
103
103
  end
104
104
 
105
+ def alert
106
+ Alert.new driver.switch_to
107
+ end
108
+
105
109
  def refresh
106
110
  @driver.navigate.refresh
107
111
  run_checkers
@@ -132,6 +136,19 @@ module Watir
132
136
  @driver.switch_to.active_element.send_keys(*args)
133
137
  end
134
138
 
139
+ #
140
+ # Handles screenshot of current pages.
141
+ #
142
+ # @example
143
+ # browser.screenshot.save("screenshot.png")
144
+ #
145
+ # @return [Watir::Screenshot]
146
+ #
147
+
148
+ def screenshot
149
+ Screenshot.new driver
150
+ end
151
+
135
152
  def add_checker(checker = nil, &block)
136
153
  if block_given?
137
154
  @error_checkers << block
@@ -1,5 +1,7 @@
1
1
  module Watir
2
2
 
3
+ #
4
+ # Deprecated, use the new Alert API instead.
3
5
  #
4
6
  # Module provided by optional require:
5
7
  #
@@ -20,6 +22,7 @@ module Watir
20
22
  #
21
23
 
22
24
  def alert(&blk)
25
+ warn 'AlertHelper is deprecated. Use the new Alert API instead (e.g. browser.alert.close)'
23
26
  execute_script "window.alert = function(msg) { window.__lastWatirAlert = msg; }"
24
27
  yield
25
28
  execute_script "return window.__lastWatirAlert"
@@ -36,6 +39,7 @@ module Watir
36
39
  # end #=> "the confirm message"
37
40
 
38
41
  def confirm(bool, &blk)
42
+ warn 'AlertHelper is deprecated. Use the new Alert API instead (e.g. browser.confirm.close)'
39
43
  execute_script "window.confirm = function(msg) { window.__lastWatirConfirm = msg; return #{!!bool} }"
40
44
  yield
41
45
  execute_script "return window.__lastWatirConfirm"
@@ -53,6 +57,7 @@ module Watir
53
57
  #
54
58
 
55
59
  def prompt(answer, &blk)
60
+ warn 'AlertHelper is deprecated. Use the new Alert API instead (e.g. browser.prompt.close)'
56
61
  execute_script "window.prompt = function(text, value) { window.__lastWatirPrompt = { message: text, default_value: value }; return #{MultiJson.encode answer}; }"
57
62
  yield
58
63
  result = execute_script "return window.__lastWatirPrompt"
@@ -0,0 +1,40 @@
1
+ # encoding: utf-8
2
+ module Watir
3
+ class Screenshot
4
+
5
+ def initialize(driver)
6
+ @driver = driver
7
+ end
8
+
9
+ #
10
+ # Saves screenshot to given path.
11
+ #
12
+ # @param [String] path
13
+ #
14
+
15
+ def save(path)
16
+ @driver.save_screenshot(path)
17
+ end
18
+
19
+ #
20
+ # Represents screenshot as PNG image string.
21
+ #
22
+ # @return [String]
23
+ #
24
+
25
+ def png
26
+ @driver.screenshot_as(:png)
27
+ end
28
+
29
+ #
30
+ # Represents screenshot as Base64 encoded string.
31
+ #
32
+ # @return [String]
33
+ #
34
+
35
+ def base64
36
+ @driver.screenshot_as(:base64)
37
+ end
38
+
39
+ end # Screenshot
40
+ end # Watir
@@ -1,3 +1,3 @@
1
1
  module Watir
2
- VERSION = "0.5.8"
2
+ VERSION = "0.6.0"
3
3
  end
@@ -1,49 +1,91 @@
1
1
  require File.expand_path("watirspec/spec_helper", File.dirname(__FILE__))
2
- require "watir-webdriver/extensions/alerts"
3
2
 
4
- describe "AlertHelper" do
3
+ describe 'Alert API' do
5
4
  before do
6
5
  browser.goto WatirSpec.url_for("alerts.html", :needs_server => true)
7
6
  end
8
7
 
9
- it "handles an alert()" do
10
- returned = browser.alert do
11
- browser.button(:id => "alert").click
12
- end
13
-
14
- returned.should == "ok"
8
+ after do
9
+ browser.alert.close if browser.alert.exists?
15
10
  end
16
11
 
17
- it "handles a confirmed confirm()" do
18
- returned = browser.confirm(true) do
19
- browser.button(:id => "confirm").click
12
+ context 'alert' do
13
+ describe '#text' do
14
+ it 'returns text of alert' do
15
+ browser.button(:id => 'alert').click
16
+ browser.alert.text.should == 'ok'
17
+ end
20
18
  end
21
19
 
22
- returned.should == "set the value"
20
+ describe '#exists?' do
21
+ it 'returns false if alert is present' do
22
+ browser.alert.should_not exist
23
+ end
23
24
 
24
- browser.button(:id => "confirm").value.should == "true"
25
- end
25
+ it 'returns true if alert is present' do
26
+ browser.button(:id => 'alert').click
27
+ browser.alert.should exist
28
+ end
29
+ end
30
+
31
+ describe '#ok' do
32
+ it 'closes alert' do
33
+ browser.button(:id => 'alert').click
34
+ browser.alert.ok
35
+ browser.alert.should_not exist
36
+ end
37
+ end
26
38
 
27
- it "handles a cancelled confirm()" do
28
- returned = browser.confirm(false) do
29
- browser.button(:id => "confirm").click
39
+ describe '#close' do
40
+ it 'closes alert' do
41
+ browser.button(:id => 'alert').click
42
+ browser.alert.close
43
+ browser.alert.should_not exist
44
+ end
30
45
  end
31
46
 
32
- returned.should == "set the value"
47
+ describe 'when_present' do
48
+ it 'waits until alert is present and goes on' do
49
+ browser.button(:id => 'timeout-alert').click
50
+ browser.alert.when_present.close
51
+ browser.alert.should_not exist
52
+ end
33
53
 
34
- browser.button(:id => "confirm").value.should == "false"
54
+ it 'raises error if alert is not present after timeout' do
55
+ browser.button(:id => 'timeout-alert').click
56
+ lambda {
57
+ browser.alert.when_present(1).close
58
+ }.should raise_error(Watir::Wait::TimeoutError, 'timed out after 1 seconds, waiting for alert to become present')
59
+ end
60
+ end
35
61
  end
36
62
 
37
- it "handles a prompt()" do
38
- returned = browser.prompt("my name") do
39
- browser.button(:id => "prompt").click
63
+ context 'confirm' do
64
+ describe '#ok' do
65
+ it 'accepts confirm' do
66
+ browser.button(:id => 'confirm').click
67
+ browser.alert.ok
68
+ browser.button(:id => 'confirm').value.should == "true"
69
+ end
40
70
  end
41
71
 
42
- returned.should == {
43
- :message => "enter your name",
44
- :default_value => "John Doe"
45
- }
72
+ describe '#close' do
73
+ it 'cancels confirm' do
74
+ browser.button(:id => 'confirm').click
75
+ browser.alert.close
76
+ browser.button(:id => 'confirm').value.should == "false"
77
+ end
78
+ end
79
+ end
46
80
 
47
- browser.button(:id => "prompt").value.should == "my name"
81
+ context 'prompt' do
82
+ describe '#set' do
83
+ it 'enters text to prompt' do
84
+ browser.button(:id => 'prompt').click
85
+ browser.alert.set 'My Name'
86
+ browser.alert.ok
87
+ browser.button(:id => 'prompt').value.should == 'My Name'
88
+ end
89
+ end
48
90
  end
49
91
  end
@@ -118,4 +118,10 @@ describe Watir::Browser do
118
118
  lambda { browser.inspect }.should_not raise_error
119
119
  end
120
120
  end
121
+
122
+ describe '#screenshot' do
123
+ it 'returns an instance of of Watir::Screenshot' do
124
+ browser.screenshot.should be_kind_of(Watir::Screenshot)
125
+ end
126
+ end
121
127
  end
@@ -7,5 +7,6 @@
7
7
  <input id=alert type=button onclick="alert('ok')" value=Alert>
8
8
  <input id=confirm type=button onclick="this.value = confirm('set the value')" value=Confirm>
9
9
  <input id=prompt type=button onclick='this.value = prompt("enter your name", "John Doe")' value=Prompt>
10
+ <input id=timeout-alert type=button onclick="setTimeout('alert(\'ok\')', 3000)" value=Timeout-Alert>
10
11
  </body>
11
- </html>
12
+ </html>
@@ -0,0 +1,25 @@
1
+ require File.expand_path("watirspec/spec_helper", File.dirname(__FILE__))
2
+
3
+ describe Watir::Screenshot do
4
+ describe '#png' do
5
+ it 'gets png representation of screenshot from WebDriver' do
6
+ browser.driver.should_receive(:screenshot_as).with(:png)
7
+ browser.screenshot.png
8
+ end
9
+ end
10
+
11
+ describe '#base64' do
12
+ it 'gets base64 representation of screenshot from WebDriver' do
13
+ browser.driver.should_receive(:screenshot_as).with(:base64)
14
+ browser.screenshot.base64
15
+ end
16
+ end
17
+
18
+ describe '#save' do
19
+ it 'saves screenshot to given file' do
20
+ path = "#{Dir.tmpdir}/test.png"
21
+ browser.driver.should_receive(:save_screenshot).with(path)
22
+ browser.screenshot.save(path)
23
+ end
24
+ end
25
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: watir-webdriver
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.8
4
+ version: 0.6.0
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-05-14 00:00:00.000000000 Z
12
+ date: 2012-05-27 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: selenium-webdriver
@@ -171,6 +171,7 @@ files:
171
171
  - README.md
172
172
  - Rakefile
173
173
  - lib/watir-webdriver.rb
174
+ - lib/watir-webdriver/alert.rb
174
175
  - lib/watir-webdriver/aliases.rb
175
176
  - lib/watir-webdriver/atoms.rb
176
177
  - lib/watir-webdriver/atoms/README
@@ -223,6 +224,7 @@ files:
223
224
  - lib/watir-webdriver/locators/element_locator.rb
224
225
  - lib/watir-webdriver/locators/text_field_locator.rb
225
226
  - lib/watir-webdriver/row_container.rb
227
+ - lib/watir-webdriver/screenshot.rb
226
228
  - lib/watir-webdriver/user_editable.rb
227
229
  - lib/watir-webdriver/version.rb
228
230
  - lib/watir-webdriver/wait.rb
@@ -244,6 +246,7 @@ files:
244
246
  - spec/implementation.rb
245
247
  - spec/input_spec.rb
246
248
  - spec/locator_spec_helper.rb
249
+ - spec/screenshot_spec.rb
247
250
  - spec/spec_helper.rb
248
251
  - spec/special_chars_spec.rb
249
252
  - spec/wait_spec.rb
@@ -290,6 +293,7 @@ test_files:
290
293
  - spec/implementation.rb
291
294
  - spec/input_spec.rb
292
295
  - spec/locator_spec_helper.rb
296
+ - spec/screenshot_spec.rb
293
297
  - spec/spec_helper.rb
294
298
  - spec/special_chars_spec.rb
295
299
  - spec/wait_spec.rb