Skip to content

Instantly share code, notes, and snippets.

Revisions

  1. muditlambda created this gist Oct 11, 2021.
    116 changes: 116 additions & 0 deletions SeleniumPlaygroundTestsWithAndWithoutPriority.java
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,116 @@
    package LamdaTest;

    import org.openqa.selenium.By;
    import org.openqa.selenium.WebElement;
    import org.openqa.selenium.remote.DesiredCapabilities;
    import org.openqa.selenium.remote.RemoteWebDriver;
    import org.testng.Reporter;
    import org.testng.annotations.AfterClass;
    import org.testng.annotations.BeforeClass;
    import org.testng.annotations.Test;

    import java.net.MalformedURLException;
    import java.net.URL;

    class SeleniumPlaygroundTestsWithAndWithoutPriority {


    public String username = "YOUR USERNAME";
    public String accesskey = "YOUR ACCESSKEY";
    public static RemoteWebDriver driver = null;
    public String gridURL = "@hub.lambdatest.com/wd/hub";

    @BeforeClass
    public void setUp() throws Exception {
    DesiredCapabilities capabilities = new DesiredCapabilities();
    capabilities.setCapability("browserName", "chrome");
    capabilities.setCapability("version", "93.0");
    capabilities.setCapability("platform", "win10"); // If this cap isn't specified, it will just get the any available one
    capabilities.setCapability("build", "TestNGWithAndWithoutPriorityTests");
    capabilities.setCapability("name", "TestNGWithAndWithoutPriorityTestsSample");
    try {
    driver = new RemoteWebDriver(new URL("https://" + username + ":" + accesskey + gridURL), capabilities);
    } catch (MalformedURLException e) {
    System.out.println("Invalid grid URL");
    } catch (Exception e) {
    System.out.println(e.getMessage());
    }
    Reporter.log("Logging into Selenium Playground", true);
    driver.get("http://labs.lambdatest.com/selenium-playground/");
    }

    @Test
    public void getFirstOptionName() {
    try {
    WebElement option1 = driver.findElement(By.xpath("(//div[@class='contentlearn']//h2)[1]"));
    Reporter.log("The First Option Is: " + option1.getText(), true);
    } catch (Exception e) {

    }

    }

    @Test
    public void getSecondOptionName() {
    try {
    WebElement option2 = driver.findElement(By.xpath("(//div[@class='contentlearn']//h2)[2]"));
    Reporter.log("The Second Option Is: " + option2.getText(), true);
    } catch (Exception e) {

    }

    }

    @Test(priority = 1)
    public void getThirdOptionName() {
    try {
    WebElement option3 = driver.findElement(By.xpath("(//div[@class='contentlearn']//h2)[3]"));
    Reporter.log("The Third Option Is: " + option3.getText(), true);
    } catch (Exception e) {

    }

    }

    @Test(priority = 1)
    public void getFourthOptionName() {
    try {
    WebElement option4 = driver.findElement(By.xpath("(//div[@class='contentlearn']//h2)[4]"));
    Reporter.log("The Fourth Option Is: " + option4.getText(), true);
    } catch (Exception e) {

    }

    }


    @Test(priority = 0)
    public void getFifthOptionName() {
    try {
    WebElement option5 = driver.findElement(By.xpath("(//div[@class='contentlearn']//h2)[5]"));
    Reporter.log("The Fifth Option Is: " + option5.getText(), true);
    } catch (Exception e) {

    }

    }

    @Test(priority = 2)
    public void getSixthOptionName() {
    try {
    WebElement option6 = driver.findElement(By.xpath("(//div[@class='contentlearn']//h2)[6]"));
    Reporter.log("The Sixth Option Is: " + option6.getText(), true);
    } catch (Exception e) {

    }

    }

    @AfterClass
    public void closeBrowser() {
    driver.close();
    Reporter.log("Closing the browser", true);

    }

    }