Sha256: b15218b2ae266301026af87bc8c264fb0293a2521ee489bd6966e8615bd5f551

Contents?: true

Size: 1.65 KB

Versions: 16

Compression:

Stored size: 1.65 KB

Contents

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

16 entries across 16 versions & 4 rubygems

Version Path
tinymce-rails-7.1.2 vendor/bundle/ruby/3.3.0/gems/capybara-2.4.4/lib/capybara/spec/session/accept_alert_spec.rb
capybara-2.6.2 lib/capybara/spec/session/accept_alert_spec.rb
capybara-2.6.1 lib/capybara/spec/session/accept_alert_spec.rb
capybara-2.6.0 lib/capybara/spec/session/accept_alert_spec.rb
angular-rails4-templates-0.4.1 vendor/ruby/2.1.0/gems/capybara-2.4.4/lib/capybara/spec/session/accept_alert_spec.rb
angular-rails4-templates-0.4.0 vendor/ruby/2.1.0/gems/capybara-2.4.4/lib/capybara/spec/session/accept_alert_spec.rb
angular-rails4-templates-0.3.0 vendor/ruby/2.1.0/gems/capybara-2.4.4/lib/capybara/spec/session/accept_alert_spec.rb
capybara-2.5.0 lib/capybara/spec/session/accept_alert_spec.rb
solidus_backend-1.0.0.pre3 vendor/bundle/gems/capybara-2.4.4/lib/capybara/spec/session/accept_alert_spec.rb
solidus_backend-1.0.0.pre2 vendor/bundle/gems/capybara-2.4.4/lib/capybara/spec/session/accept_alert_spec.rb
solidus_backend-1.0.0.pre vendor/bundle/gems/capybara-2.4.4/lib/capybara/spec/session/accept_alert_spec.rb
capybara-2.4.4 lib/capybara/spec/session/accept_alert_spec.rb
capybara-2.4.3 lib/capybara/spec/session/accept_alert_spec.rb
capybara-2.4.2 lib/capybara/spec/session/accept_alert_spec.rb
capybara-2.4.1 lib/capybara/spec/session/accept_alert_spec.rb
capybara-2.4.0 lib/capybara/spec/session/accept_alert_spec.rb