package StepDefinitions; import io.cucumber.java.After; import io.cucumber.java.en.Given; import io.cucumber.java.en.Then; import io.cucumber.java.en.When; import io.github.bonigarcia.wdm.WebDriverManager; import org.openqa.selenium.By; import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebElement; import org.openqa.selenium.firefox.FirefoxDriver; import org.testng.Assert; public class ExceptionHandling { private WebDriver driver; @Given("the ecom website") public void the_ecom_website() { WebDriverManager.firefoxdriver().setup(); driver = new FirefoxDriver(); driver.get("https://www.tpointtech.com/"); driver.manage().window().maximize(); } @When("the homepage opens verify it") public void the_homepage_opens_verify_it() { String expectedTitle = "Tpoint Tech - Free Online Tutorials conveyed"; String actualTitle = driver.getTitle(); Assert.assertEquals(actualTitle, expectedTitle, "Page title is not correct"); } @Then("click on the course selenium") public void click_on_the_course_selenium() { WebElement selenium = driver.findElement(By.xpath("//ul[@class='nav']//a[text()=' Selenium']")); selenium.click(); } @Then("verify navigated to course page") public void verify_navigated_to_course_page() { String expectedUrl = "https://www.javatpoint.com/selenium-tutorial"; String currentUrl = driver.getCurrentUrl(); if (currentUrl.contains(expectedUrl)) { System.out.println("Successfully navigated to the Selenium course page."); } else { System.out.println("Failed to navigate to the Selenium course page."); } } @After public void tearDown() { if (driver != null) { driver.quit(); } } }