balin / com.github.epadronu.balin.core / withAlert

withAlert

inline fun Browser.withAlert(alertContext: Alert.() -> Unit): Unit

Switches to the currently active modal dialog for this particular driver instance.

You can interact with the dialog handler only inside alertContext.

Browser.drive(driverFactory) {
    // Given I navigate to the page under test, which popup alerts
    to(pageWithAlerts)

    // And I'm in the context of the page
    assertEquals(`$`("h1", 0).text, "Page with Alerts")

    // When I click in the button which makes the alert appear
    `$`("#alert", 0).click()

    // And I change the driver's context to the alert
    withAlert {
        // Then I should be able to get the alert's text
        assertEquals(text, "Balin is awesome!")

        // And I accept the alert
        accept()
    }

    // Then I should return into the context of the page at the end of the `withAlert` method
    assertEquals(`$`("h1", 0).text, "Page with Alerts")
}

Parameters

alertContext - here you can interact with the dialog handler.

Exceptions

org.openqa.selenium.NoAlertPresentException - If the dialog cannot be found.