Created
October 11, 2021 14:58
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment