Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save RDayal11/c1aea033b5598229a111b8f3cdba16e5 to your computer and use it in GitHub Desktop.
Save RDayal11/c1aea033b5598229a111b8f3cdba16e5 to your computer and use it in GitHub Desktop.
TestNGPriorityTests
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.example</groupId>
<artifactId>LambdaTest</artifactId>
<version>1.0-SNAPSHOT</version>
<dependencies>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-api</artifactId>
<version>4.0.0-alpha-7</version>
</dependency>
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<version>6.14.3</version>
</dependency>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-remote-driver</artifactId>
<version>4.0.0-alpha-7</version>
</dependency>
</dependencies>
<properties>
<maven.compiler.source>8</maven.compiler.source>
<maven.compiler.target>8</maven.compiler.target>
</properties>
</project>
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);
}
}
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 SeleniumPlaygroundTestsWithoutPriority {
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", "94.0");
capabilities.setCapability("platform", "win10"); // If this cap isn't specified, it will just get the any available one
capabilities.setCapability("build", "TestNGWithoutPriorityTests");
capabilities.setCapability("name", "TestNGWithoutPriorityTestsSample");
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
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
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
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
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);
}
}
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 SeleniumPlaygroundTestsWithPriority {
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", "94.0");
capabilities.setCapability("platform", "win10"); // If this cap isn't specified, it will just get the any available one
capabilities.setCapability("build", "TestNGWithPriorityTests");
capabilities.setCapability("name", "TestNGWithPriorityTestsSample");
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(priority = 1)
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(priority = 2)
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 = 3)
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 = 4)
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 = 5)
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 = 6)
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);
}
}
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 SeleniumPlaygroundTestsWithSamePriority {
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", "TestNGWithSamePriorityTests");
capabilities.setCapability("name", "TestNGWithSamePriorityTestsSample");
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(priority = 1)
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(priority = 1)
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 = 2)
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 = -2)
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 = -3)
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);
}
}
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite name="TestNGPriorityTest">
<test name="TestNGPriorityTest" >
<classes>
<class name="LamdaTest.SeleniumPlaygroundTestsWithoutPriority" >
</class>
<class name="LamdaTest.SeleniumPlaygroundTestsWithPriority" >
</class>
<class name="LamdaTest.SeleniumPlaygroundTestsWithSamePriority" >
</class>
<class name="LamdaTest.SeleniumPlaygroundTestsWithAndWithoutPriority" >
</class>
</classes>
</test>
</suite>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment