Skip to main content

Modals

DrevOps\BehatSteps\Steps\Web\ModalTrait - Source, Example, Helpers

Interact with and assert modals.

  • Assert modal visibility.
  • Assert modal content.
  • Interact with modal buttons.

Supports multiple modal implementations (jQuery UI dialogs, Bootstrap modals, native HTML dialog element, custom modals) through the modal.selectors, modal.content_selectors and modal.close_selectors options. All steps require a JavaScript-enabled browser driver.

Options​

OptionTypeDefaultTagDescription
modal.selectorsmap[...]-CSS selectors of the modal container, tried in order.
modal.content_selectorsmap[...]-CSS selectors of the modal content element, tried in order.
modal.close_selectorsmap[...]-CSS selectors of the modal close button, tried in order.
modal.wait_timeoutinteger3-Maximum time, in seconds, to wait for a modal to appear.

Steps​

@When I close the modal

Close the modal by clicking the close button

When I close the modal
@When I click on the element :selector in the modal

Click an element in the modal by CSS selector, button label, or link text

When I click on the element "Save" in the modal
When I click on the element ".btn-save" in the modal
When I click on the element "Cancel" in the modal
@When I wait for the modal to appear

Wait for the modal to appear

When I wait for the modal to appear
@Then I should see the modal

Assert that the modal is visible

Then I should see the modal
@Then I should not see the modal

Assert that the modal is not visible

Then I should not see the modal
@Then I should see the text :text in the modal

Assert that the modal contains text

Then I should see the text "Welcome message" in the modal
@Then I should not see the text :text in the modal

Assert that the modal does not contain text

Then I should not see the text "Error message" in the modal