Sha256: e242fdb568fd1c45c8ded87de58148a21b51591347bc2a2f58211ae77c5d189d

Contents?: true

Size: 1.2 KB

Versions: 77

Compression:

Stored size: 1.2 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')
    expect(@session).to have_css('#change')
    @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

77 entries across 64 versions & 5 rubygems

Version Path
blacklight-spotlight-3.6.0.beta8 vendor/bundle/ruby/3.2.0/gems/capybara-3.40.0/lib/capybara/spec/session/execute_script_spec.rb
capybara-3.40.0 lib/capybara/spec/session/execute_script_spec.rb
capybara-3.39.2 lib/capybara/spec/session/execute_script_spec.rb
capybara-3.39.1 lib/capybara/spec/session/execute_script_spec.rb
capybara-3.39.0 lib/capybara/spec/session/execute_script_spec.rb
tdiary-5.2.4 vendor/bundle/ruby/3.1.0/gems/capybara-3.36.0/lib/capybara/spec/session/execute_script_spec.rb
capybara-3.38.0 lib/capybara/spec/session/execute_script_spec.rb
tdiary-5.2.3 vendor/bundle/ruby/3.1.0/gems/capybara-3.37.1/lib/capybara/spec/session/execute_script_spec.rb
tdiary-5.2.2 vendor/bundle/ruby/3.1.0/gems/capybara-3.37.1/lib/capybara/spec/session/execute_script_spec.rb
capybara-3.37.1 lib/capybara/spec/session/execute_script_spec.rb
capybara-3.37.0 lib/capybara/spec/session/execute_script_spec.rb
tdiary-5.2.1 vendor/bundle/ruby/3.1.0/gems/capybara-3.36.0/lib/capybara/spec/session/execute_script_spec.rb
tdiary-5.2.0 vendor/bundle/ruby/2.7.0/gems/capybara-3.35.3/lib/capybara/spec/session/execute_script_spec.rb
tdiary-5.2.0 vendor/bundle/ruby/3.0.0/gems/capybara-3.36.0/lib/capybara/spec/session/execute_script_spec.rb
date_n_time_picker_activeadmin-0.1.2 vendor/bundle/ruby/2.6.0/gems/capybara-3.36.0/lib/capybara/spec/session/execute_script_spec.rb
date_n_time_picker_activeadmin-0.1.1 vendor/bundle/ruby/2.6.0/gems/capybara-3.36.0/lib/capybara/spec/session/execute_script_spec.rb
capybara-3.36.0 lib/capybara/spec/session/execute_script_spec.rb
tdiary-5.1.7 vendor/bundle/ruby/3.0.0/gems/capybara-3.35.3/lib/capybara/spec/session/execute_script_spec.rb
tdiary-5.1.7 vendor/bundle/ruby/2.7.0/gems/capybara-3.35.3/lib/capybara/spec/session/execute_script_spec.rb
tdiary-5.1.6 vendor/bundle/ruby/2.7.0/gems/tdiary-5.1.5/vendor/bundle/ruby/2.7.0/gems/capybara-3.35.3/lib/capybara/spec/session/execute_script_spec.rb