teamcapybara--capybara/lib/capybara/spec/session/execute_script_spec.rb

28 lines
1.2 KiB
Ruby
Raw Normal View History

2016-03-08 00:52:19 +00:00
# frozen_string_literal: true
2018-03-01 00:11:41 +00:00
2016-10-04 18:10:29 +00:00
Capybara::SpecHelper.spec "#execute_script", requires: [:js] do
it "should execute the given script and return nothing" do
@session.visit('/with_js')
expect(@session.execute_script("document.getElementById('change').textContent = 'Funky Doodle'")).to be_nil
2016-10-04 18:10:29 +00:00
expect(@session).to have_css('#change', text: 'Funky Doodle')
end
it "should be able to call functions defined in the page" do
@session.visit('/with_js')
2018-03-01 00:11:41 +00:00
expect { @session.execute_script("$('#change').text('Funky Doodle')") }.not_to raise_error
end
2018-03-01 00:11:41 +00:00
it "should pass arguments to the script", requires: %i[js es_args] do
@session.visit('/with_js')
@session.execute_script("document.getElementById('change').textContent = arguments[0]", "Doodle Funk")
expect(@session).to have_css('#change', text: 'Doodle Funk')
end
2018-03-01 00:11:41 +00:00
it "should support passing elements as arguments to the script", requires: %i[js es_args] do
@session.visit('/with_js')
el = @session.find(:css, '#change')
@session.execute_script("arguments[1].textContent = arguments[0]", "Doodle Funk", el)
expect(@session).to have_css('#change', text: 'Doodle Funk')
end
end