Sha256: 9ce0e37296e1efaa35ec8b884ad2c563a3d8d721df1575bc8150e26a0cae8986

Contents?: true

Size: 1.15 KB

Versions: 13

Compression:

Stored size: 1.15 KB

Contents

# frozen_string_literal: true

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
    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')
    expect { @session.execute_script("$('#change').text('Funky Doodle')") }.not_to raise_error
  end

  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

  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

Version data entries

13 entries across 13 versions & 2 rubygems

Version Path
tdiary-5.0.9 vendor/bundle/gems/capybara-3.2.1/lib/capybara/spec/session/execute_script_spec.rb
capybara-3.3.1 lib/capybara/spec/session/execute_script_spec.rb
capybara-3.3.0 lib/capybara/spec/session/execute_script_spec.rb
capybara-3.2.1 lib/capybara/spec/session/execute_script_spec.rb
capybara-3.2.0 lib/capybara/spec/session/execute_script_spec.rb
capybara-3.1.1 lib/capybara/spec/session/execute_script_spec.rb
capybara-3.1.0 lib/capybara/spec/session/execute_script_spec.rb
capybara-3.0.3 lib/capybara/spec/session/execute_script_spec.rb
capybara-3.0.2 lib/capybara/spec/session/execute_script_spec.rb
capybara-3.0.1 lib/capybara/spec/session/execute_script_spec.rb
capybara-3.0.0 lib/capybara/spec/session/execute_script_spec.rb
capybara-3.0.0.rc2 lib/capybara/spec/session/execute_script_spec.rb
capybara-3.0.0.rc1 lib/capybara/spec/session/execute_script_spec.rb