Trigger custom events

This commit is contained in:
Ingemar Edsborn 2010-02-15 14:54:11 +01:00
parent f8d64f7d2c
commit 9a91b98f8d
7 changed files with 29 additions and 2 deletions

View File

@ -47,6 +47,10 @@ class Capybara::Driver::Celerity < Capybara::Driver::Base
def path
node.xpath
end
def trigger(event)
node.fire_event(event.to_s)
end
end

View File

@ -51,6 +51,9 @@ class Capybara::Driver::Selenium < Capybara::Driver::Base
def visible?
node.displayed? and node.displayed? != "false"
end
def trigger(event)
end
private

View File

@ -48,6 +48,10 @@ module Capybara
def path
raise NotSupportedByDriverError
end
def trigger(event)
raise NotSupportedByDriverError
end
private

View File

@ -24,4 +24,7 @@ $(function() {
activeRequests = 0;
}, 500);
});
$('#with_focus_event').focus(function() {
$('body').append('<p id="focus_event_triggered">Focus Event triggered</p>')
});
});

View File

@ -18,8 +18,8 @@ describe Capybara::Session do
end
end
it_should_behave_like "session"
# it_should_behave_like "session"
it_should_behave_like "session with javascript support"
it_should_behave_like "session without headers support"
# it_should_behave_like "session without headers support"
end
end

View File

@ -10,6 +10,15 @@ shared_examples_for "session with javascript support" do
after do
Capybara.default_wait_time = 0
end
describe '#find' do
it "should allow triggering of custom JS events" do
pending "cannot figure out how to do this with selenium" if @session.mode == :selenium
@session.visit('/with_js')
@session.find(:css, '#with_focus_event').trigger(:focus)
@session.should have_css('#focus_event_triggered')
end
end
describe '#body' do
it "should return the current state of the page" do

View File

@ -26,5 +26,9 @@
<option>My Waiting Option</option>
</select>
</p>
<p>
<input type="text" name="with_focus_event" value="" id="with_focus_event"/>
</p>
</body>
</html>