Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also .

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also .
Choose a base branch
...
Choose a head branch
  • 5 commits
  • 4 files changed
  • 0 commit comments
  • 2 contributors
Commits on Jul 12, 2012
Despo Pentara Despo Pentara
Despo Pentara and Despo Pentara
aiming for consistent usage
between selenium and webkit
Despo Pentara Despo Pentara
Despo Pentara and Despo Pentara
Despo Pentara Despo Pentara
Despo Pentara and Despo Pentara
Despo Pentara Despo Pentara
Despo Pentara and Despo Pentara
Commits on Mar 14, 2013
Showing with 59 additions and 7 deletions.
  1. +1 −0 .travis.yml
  2. +4 −2 README.md
  3. +25 −5 lib/prickle/capybara/popup/selenium.rb
  4. +29 −0 spec/capybara/popups/selenium_spec.rb
View
@@ -1,5 +1,6 @@
language: ruby
rvm:
+ - 2.0.0
- 1.9.2
- 1.9.3
- rbx-19mode
View
@@ -76,7 +76,7 @@ element(:name => "flower").has_text? "Anemone" # exact match
### Popup
-**Selenium**
+**Selenium simplified**
```ruby
popup.confirm
@@ -86,7 +86,9 @@ popup.message
popup.contains_message? "<text>"
```
-**Webkit**
+**Webkit and Selenium**
+
+*This was implemented to enable for an easy switch between Webkit and Selenium. If you can suggest a better way of achieving this, open an issue or even better, send a pull request!*
```ruby
popup.confirm {
@@ -6,15 +6,22 @@ class Selenium
include ::Capybara::DSL
def initialize
- @popup = page.driver.browser.switch_to.alert
+ @popup = page.driver.browser.switch_to.alert rescue nil
end
- def confirm
- @popup.accept
+ alias :popup :initialize
+
+ def confirm &block
+ handle_webkit_syntax &block if block_given?
+ popup.accept
+ self
end
- def dismiss
- @popup.dismiss
+ alias :accept :confirm
+
+ def dismiss &block
+ return handle_webkit_syntax_dismiss &block if block_given?
+ popup.dismiss
end
def message
@@ -25,6 +32,19 @@ def contains_message? message
raise Exceptions::MessageNotContainedInPopup.new(self.message) unless self.message.eql? message
end
+ private
+
+ def handle_webkit_syntax_dismiss &block
+ handle_webkit_syntax &block
+ popup.accept
+ self
+ end
+
+ def handle_webkit_syntax &block
+ block.call
+ @message = popup.text
+ end
+
end
end
end
@@ -38,4 +38,33 @@
end
end
end
+
+
+ context "alternate popup syntax", :javascript => true do
+ it 'can confirm an alert box' do
+
+ alert = prickly.popup.accept {
+ prickly.click_by_name 'popups'
+ }
+
+ alert.contains_message? "Hello"
+ end
+
+ it 'can confirm a popup' do
+ alert = prickly.popup.confirm {
+ prickly.click_by_name 'confirm_box'
+ }
+ alert.contains_message? "Click yes to continue"
+ end
+
+ it 'can dismiss a popup' do
+ alert = prickly.popup.dismiss {
+ prickly.click_by_name 'confirm_box'
+ }
+
+ alert.contains_message? "Click yes to continue"
+ end
+
+ end
+
end

No commit comments for this range