Skip to content

Instantly share code, notes, and snippets.

@SarahElson
Created February 22, 2024 06:23
Show Gist options
  • Save SarahElson/fd72af8baeb7fd2bd3c75f63c2c03981 to your computer and use it in GitHub Desktop.
Save SarahElson/fd72af8baeb7fd2bd3c75f63c2c03981 to your computer and use it in GitHub Desktop.
Automate UI Tests With Selenium
package demo;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.testng.Assert;
import org.testng.annotations.Test;
public class DemoClass {
@Test
public void title_test() {
/* Initializing ChromeDriver, for any other browser, use its respective driver class */
WebDriver driver = new ChromeDriver();
// Opening the Lambdatest E-Commerce Playground
driver.get("https://ecommerce-playground.lambdatest.io/");
/* Retrieving the text of a “TOP TRENDING CATEGORIES” element by locating using cssSelection attribute */
String val = driver.findElement(By.cssSelector(".module-title")).getText();
// Verifying the Outcomes
Assert.assertEquals( val, "TOP TRENDING CATEGORIES");
// Closing the WebDriver and terminating the browser session.
driver.quit();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment