Sha256: 2c2b854b9c9e17d39d515eb9deca08118c45e9920e07197745a9f2abd0e2182c

Contents?: true

Size: 1.68 KB

Versions: 10

Compression:

Stored size: 1.68 KB

Contents

# frozen_string_literal: true
Capybara::SpecHelper.spec '#accept_alert', :requires => [:modals] do
  before do
    @session.visit('/with_js')
  end

  it "should accept the alert" do
    @session.accept_alert do
      @session.click_link('Open alert')
    end
    expect(@session).to have_xpath("//a[@id='open-alert' and @opened='true']")
  end
  
  it "should accept the alert if the text matches" do
    @session.accept_alert 'Alert opened' do
      @session.click_link('Open alert')
    end
    expect(@session).to have_xpath("//a[@id='open-alert' and @opened='true']")
  end
  
  it "should not accept the alert if the text doesnt match" do
    expect do
      @session.accept_alert 'Incorrect Text' do
        @session.click_link('Open alert')
      end
    end.to raise_error(Capybara::ModalNotFound)
  end

  it "should return the message presented" do
    message = @session.accept_alert do
      @session.click_link('Open alert')
    end
    expect(message).to eq('Alert opened')
  end

  context "with an asynchronous alert" do
    it "should accept the alert" do
      @session.accept_alert do
        @session.click_link('Open delayed alert')
      end
      expect(@session).to have_xpath("//a[@id='open-delayed-alert' and @opened='true']")
    end

    it "should return the message presented" do
      message = @session.accept_alert do
        @session.click_link('Open delayed alert')
      end
      expect(message).to eq('Delayed alert opened')
    end
    
    it "should allow to adjust the delay" do
      @session.accept_alert wait: 4 do
        @session.click_link('Open slow alert')
      end
      expect(@session).to have_xpath("//a[@id='open-slow-alert' and @opened='true']")
    end
  end
end

Version data entries

10 entries across 10 versions & 3 rubygems

Version Path
capybara-2.9.2 lib/capybara/spec/session/accept_alert_spec.rb
tdiary-5.0.2 vendor/bundle/gems/capybara-2.8.0/lib/capybara/spec/session/accept_alert_spec.rb
capybara-2.9.1 lib/capybara/spec/session/accept_alert_spec.rb
capybara-2.9.0 lib/capybara/spec/session/accept_alert_spec.rb
capybara-2.8.1 lib/capybara/spec/session/accept_alert_spec.rb
capybara-2.8.0 lib/capybara/spec/session/accept_alert_spec.rb
tdiary-5.0.1 vendor/bundle/gems/capybara-2.7.1/lib/capybara/spec/session/accept_alert_spec.rb
ish_lib_manager-0.0.1 test/dummy/vendor/bundle/ruby/2.3.0/gems/capybara-2.7.1/lib/capybara/spec/session/accept_alert_spec.rb
capybara-2.7.1 lib/capybara/spec/session/accept_alert_spec.rb
capybara-2.7.0 lib/capybara/spec/session/accept_alert_spec.rb