2016-03-08 00:52:19 +00:00
|
|
|
# frozen_string_literal: true
|
2016-10-04 18:10:29 +00:00
|
|
|
Capybara::SpecHelper.spec "#execute_script", requires: [:js] do
|
2012-07-21 20:44:10 +00:00
|
|
|
it "should execute the given script and return nothing" do
|
|
|
|
@session.visit('/with_js')
|
2016-06-12 23:28:47 +00:00
|
|
|
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')
|
2012-07-21 20:44:10 +00:00
|
|
|
end
|
2016-06-12 23:28:47 +00:00
|
|
|
|
|
|
|
it "should be able to call functions defined in the page" do
|
|
|
|
@session.visit('/with_js')
|
|
|
|
expect{ @session.execute_script("$('#change').text('Funky Doodle')") }.not_to raise_error
|
|
|
|
end
|
2016-12-23 00:22:46 +00:00
|
|
|
|
2016-12-30 20:33:57 +00:00
|
|
|
it "should pass arguments to the script", requires: [:js, :es_args] do
|
2016-12-23 00:22:46 +00:00
|
|
|
@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
|
|
|
|
|
2016-12-30 20:33:57 +00:00
|
|
|
it "should support passing elements as arguments to the script", requires: [:js, :es_args] do
|
2016-12-23 00:22:46 +00:00
|
|
|
@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
|
2012-07-21 20:44:10 +00:00
|
|
|
end
|