forked from despo/prickle
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
146 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
module Prickle | ||
module Capybara | ||
module Popups | ||
class Selenium | ||
|
||
include ::Capybara::DSL | ||
|
||
def initialize | ||
@popup = page.driver.browser.switch_to.alert | ||
end | ||
|
||
def confirm | ||
@popup.accept | ||
end | ||
|
||
def dismiss | ||
@popup.dismiss | ||
end | ||
|
||
def message | ||
@popup.text | ||
end | ||
|
||
def contains_message? message | ||
raise Exceptions::MessageNotContainedInPopup.new(message) unless self.message.eql? message | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
module Prickle | ||
module Capybara | ||
module Popups | ||
class Webkit | ||
|
||
include ::Capybara::DSL | ||
|
||
def message | ||
@message | ||
end | ||
|
||
def contains_message? message | ||
raise Exceptions::MessageNotContainedInPopup.new(self.message) unless self.message.include? message | ||
end | ||
|
||
def accept &block | ||
manage_js_popup true, &block | ||
end | ||
|
||
def dismiss &block | ||
manage_js_popup false, &block | ||
end | ||
|
||
def accept_alert accept=true | ||
page.execute_script "window.original_alert_function = window.alert" | ||
page.execute_script "window.alert_msg = null" | ||
page.execute_script "window.alert = function(msg) { window.alert_msg = msg; return #{!!accept}; }" | ||
yield | ||
page.execute_script "window.alert = window.original_alert_function" | ||
@message = page.evaluate_script "window.alert_msg" | ||
self | ||
end | ||
|
||
def message | ||
@message | ||
end | ||
|
||
private | ||
def manage_js_popup accept | ||
page.execute_script "window.original_confirm_function = window.confirm" | ||
page.execute_script "window.confirm_msg = null" | ||
page.execute_script "window.confirm = function(msg) { window.confirm_msg = msg; return #{!!accept}; }" | ||
yield | ||
page.execute_script "window.confirm = window.original_confirm_function" | ||
@message = page.evaluate_script "window.confirm_msg" | ||
self | ||
end | ||
|
||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
require 'spec_helper' | ||
|
||
describe Prickle::Capybara::Popup do | ||
let(:prickly) { Prickly.new } | ||
|
||
before do | ||
Capybara.default_driver = :webkit | ||
Prickle::Capybara.wait_time = nil | ||
end | ||
|
||
before(:each) do | ||
prickly.visit '/' | ||
end | ||
|
||
context 'Managing webkit popups', :js => true do | ||
it 'can confirm an alert box', :js => true do | ||
|
||
alert = prickly.popup.accept_alert { | ||
prickly.click_by_name 'popups' | ||
} | ||
|
||
alert.contains_message? "Hello" | ||
end | ||
|
||
it 'can confirm a popup' do | ||
alert = prickly.popup.accept { | ||
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 | ||
|
||
context "matching text" do | ||
it "can verify the content of a popup" do | ||
alert = prickly.popup.accept_alert { | ||
prickly.click_by_name "popups" | ||
} | ||
|
||
alert.contains_message? "Hel" | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters