Accordion
Three collapsible sections. Only one stays open at a time, so your test has to check both the open and the closed state.
Automation testing uses code to run checks that a person would otherwise run by hand. It pays off for repetitive, stable and high-risk flows.
Learn one language properly, then Selenium or Playwright. The tool is easy once the programming is comfortable.
Use stable locators, explicit waits instead of sleeps, independent test data and no dependency between tests.
Practice tasks
- Assert that section 1 is open and the other two are closed when the page loads.
- Click section 2 and assert its content becomes visible and section 1 closes.
- Assert the
aria-expandedattribute changes fromfalsetotrue. - Click an open section again and assert it collapses.
- Read the text inside section 3 after opening it.
Sample automation code
Assert.assertTrue(driver.findElement(By.id("section1-content")).isDisplayed());
Assert.assertFalse(driver.findElement(By.id("section2-content")).isDisplayed());
driver.findElement(By.id("section2-heading")).click();
new WebDriverWait(driver, Duration.ofSeconds(5))
.until(ExpectedConditions.visibilityOfElementLocated(By.id("section2-content")));
Assert.assertEquals(driver.findElement(By.id("section2-heading")).getAttribute("aria-expanded"), "true");
await expect(page.getByTestId('section1-content')).toBeVisible();
await page.getByTestId('section2-heading').click();
await expect(page.getByTestId('section2-content')).toBeVisible();
await expect(page.getByTestId('section1-content')).toBeHidden();