Rayrun
← Back to Discord Forum

Java - Testing for Bootstrap modal opening and closing

Hi! I am writing an E2E test for opening and closing the a Bootstrap modal. However, the test is failing as the modal do not get opened according to the Playwright. The modal opens and closes fine on manual tests.

Following is the code snippet:

```

@When("I click on the Statistic button")
public void i_click_on_the_statistic_button () {
    page.onceDialog(dialog -> {
        modalOpened = true;
        dialog.dismiss();
    });
    page.getByRole(AriaRole.BUTTON).filter(new Locator.FilterOptions().setHasText("Statistics")).click();
}

@Then("Statistic modal opens")
public void statistic_modal_opens () {
    Assertions.assertTrue(modalOpened); //fails
    Assertions.assertEquals("modal fade show", page.locator("#statisticModal").getAttribute("class")); //also fails

This thread is trying to answer question "Why is the E2E test for opening and closing a Bootstrap modal failing in Playwright?"

4 replies

make sure the locators are correct and try using force click to see if it opens the modal

Does not work. I'm not sure what's going one I've simplified the code and removed the onDialogue and ends up with same results. The class name at the last getAttribute returns "modal fade" instead of "modal fade show"

@When("I click on the Statistic button")
    public void i_click_on_the_statistic_button () {
        page.locator("#statisticButton").click(new Locator.ClickOptions().setForce(true));
    }

    @Then("Statistic modal opens")
    public void statistic_modal_opens () {
        Assertions.assertEquals("modal fade show", page.locator("#statisticModal").getAttribute("class"));
    }

Resolved: Caused by the speed of the Playwright. Adding a wait after opening the modal resolved the issue

Think you might want to look Koushik's youtube channel or the video section here to get a good understanding how to handle them.

Related Discord Threads

TwitterGitHubLinkedIn
AboutQuestionsDiscord ForumBrowser ExtensionTagsQA Jobs

Rayrun is a community for QA engineers. I am constantly looking for new ways to add value to people learning Playwright and other browser automation frameworks. If you have feedback, email [email protected].