added evaluate_script method to all javascipt drivers for evaluating javascript

This commit is contained in:
Dennis Rogenius 2009-12-11 22:41:12 +01:00
parent bcff9d7eda
commit 7867084063
3 changed files with 30 additions and 15 deletions

View File

@ -70,6 +70,10 @@ class Capybara::Driver::Culerity
browser.elements_by_xpath(selector).map { |node| Node.new(self, node) }
end
def evaluate_script(script)
browser.execute_script "#{script}"
end
private
def url(path)

View File

@ -84,6 +84,10 @@ class Capybara::Driver::Selenium
driver.find_elements(:xpath, selector).map { |node| Node.new(self, node) }
end
def evaluate_script(script)
driver.execute_script "return #{script}"
end
private
def url(path)

View File

@ -63,20 +63,27 @@ shared_examples_for 'driver' do
end
shared_examples_for "driver with javascript support" do
before { @driver.visit('/with_js') }
describe '#find' do
it "should find dynamically changed nodes" do
@driver.visit('/with_js')
@driver.find('//p').first.text.should == 'I changed it'
end
end
describe '#drag_to' do
it "should drag and drop an object" do
@driver.visit('/with_js')
draggable = @driver.find('//div[@id="drag"]').first
droppable = @driver.find('//div[@id="drop"]').first
draggable.drag_to(droppable)
@driver.find('//div[contains(., "Dropped!")]').should_not be_nil
end
end
describe "#evaluate_script" do
it "should return the value of the executed script" do
@driver.evaluate_script('1+1').should == 2
end
end
end