

import io.github.bonigarcia.seljup.SeleniumJupiter;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;

import static org.assertj.core.api.Assertions.assertThat;

@ExtendWith(SeleniumJupiter.class)
class HelloWorldSeleniumTest {

    @Test
    void testNavigateToSlowCalculator(WebDriver driver) {
        //Step 1: Open main page
        String sutUrl = "https://bonigarcia.dev/selenium-webdriver-java/";
        driver.get(sutUrl);

        //Assert main page title
        String title = driver.getTitle();
        assertThat(title).isEqualTo("Hands-On Selenium WebDriver with Java");

        //Step 2: Click the “Slow calculator” link
        WebElement slowCalcLink = driver.findElement(By.linkText("Slow calculator"));
        slowCalcLink.click();

        //Step 3: Assert navigation
        String currentUrl = driver.getCurrentUrl();
        assertThat(currentUrl).contains("slow-calculator");

        //No need for driver.quit()
    }
}
