JS Testing Academy · QA Demo Site

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.

Practice tasks

  1. Assert that section 1 is open and the other two are closed when the page loads.
  2. Click section 2 and assert its content becomes visible and section 1 closes.
  3. Assert the aria-expanded attribute changes from false to true.
  4. Click an open section again and assert it collapses.
  5. 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");