Sha256: aa1406b3ac65fc3834d44e2bbeae67eaeeef950cbfd09b79b3b791acc5e0497c

Contents?: true

Size: 1.15 KB

Versions: 27

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: [: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: [: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

27 entries across 23 versions & 3 rubygems

Version Path
tdiary-5.0.8 vendor/bundle/gems/capybara-2.18.0/lib/capybara/spec/session/execute_script_spec.rb
tdiary-5.0.8 vendor/bundle/ruby/2.5.0/gems/capybara-2.18.0/lib/capybara/spec/session/execute_script_spec.rb
tdiary-5.0.8 vendor/bundle/gems/tdiary-5.0.7/vendor/bundle/gems/capybara-2.16.1/lib/capybara/spec/session/execute_script_spec.rb
capybara-2.18.0 lib/capybara/spec/session/execute_script_spec.rb
capybara-2.17.0 lib/capybara/spec/session/execute_script_spec.rb
tdiary-5.0.7 vendor/bundle/gems/capybara-2.16.1/lib/capybara/spec/session/execute_script_spec.rb
capybara-2.16.1 lib/capybara/spec/session/execute_script_spec.rb
capybara-2.16.0 lib/capybara/spec/session/execute_script_spec.rb
capybara-2.15.4 lib/capybara/spec/session/execute_script_spec.rb
capybara-2.15.3 lib/capybara/spec/session/execute_script_spec.rb
capybara-2.15.2 lib/capybara/spec/session/execute_script_spec.rb
tdiary-5.0.6 vendor/bundle/gems/capybara-2.15.1/lib/capybara/spec/session/execute_script_spec.rb
capybara-2.15.1 lib/capybara/spec/session/execute_script_spec.rb
capybara-2.15.0 lib/capybara/spec/session/execute_script_spec.rb
tdiary-5.0.5 vendor/bundle/gems/tdiary-5.0.4/vendor/bundle/gems/capybara-2.13.0/lib/capybara/spec/session/execute_script_spec.rb
tdiary-5.0.5 vendor/bundle/gems/capybara-2.13.0/lib/capybara/spec/session/execute_script_spec.rb
tdiary-5.0.5 vendor/bundle/gems/capybara-2.14.3/lib/capybara/spec/session/execute_script_spec.rb
capybara-2.14.4 lib/capybara/spec/session/execute_script_spec.rb
capybara-2.14.3 lib/capybara/spec/session/execute_script_spec.rb
capybara-2.14.2 lib/capybara/spec/session/execute_script_spec.rb