Skip to content

Instantly share code, notes, and snippets.

@muditlambda
Created December 29, 2021 11:44
Show Gist options
  • Save muditlambda/413056a4c42ebfd1e5ec02f105c202f1 to your computer and use it in GitHub Desktop.
Save muditlambda/413056a4c42ebfd1e5ec02f105c202f1 to your computer and use it in GitHub Desktop.
package com.pages;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.TestNG.Assert;
import org.TestNG.annotations.AfterTest;
import org.TestNG.annotations.BeforeTest;
import org.TestNG.annotations.Test;
import java.util.concurrent.TimeUnit;
public class TestNGOrder {
String urlToTest = "https://www.lambdatest.com/selenium-playground/simple-form-demo.php";
WebDriver driver;
@BeforeTest
public void setup() {
System.out.println("Setting up the drivers");
System.setProperty("webdriver.chrome.driver", "C:\\Users\\Shalini\\Downloads\\chromedriver_latest94\\chromedriver.exe");
driver = new ChromeDriver();
}
@Test(priority = 1)
public void enterAndDisplayMessage() {
String inputString ="Hello World";
String methodName = Thread.currentThread()
.getStackTrace()[1]
.getMethodName();
System.out.println("********Execution of "+methodName+" has been started********");
System.out.println("Launching LambdaTest selenium playground website started..");
driver.get(urlToTest);
driver.manage().window().maximize();
driver.manage().timeouts().pageLoadTimeout(10, TimeUnit.SECONDS);
WebElement textBox = driver.findElement(By.xpath("//input[@id='user-message']"));
textBox.sendKeys(inputString);
WebElement showButton = driver.findElement(By.id("showInput"));
showButton.click();
WebElement messageDisplayed = driver.findElement(By.xpath("//div[@id='user-message']//span[@id = 'message']"));
String message = messageDisplayed.getText();
Assert.assertEquals(inputString,message);
System.out.println("********Execution of "+methodName+" has ended********");
}
@Test(priority = 2)
public void addAndDisplayResult(){
String methodName = Thread.currentThread()
.getStackTrace()[1]
.getMethodName();
System.out.println("********Execution of "+methodName+" has been started********");
System.out.println("Launching LambdaTest selenium playground website started..");
driver.get(urlToTest);
driver.manage().window().maximize();
driver.manage().timeouts().pageLoadTimeout(10, TimeUnit.SECONDS);
WebElement input1 = driver.findElement(By.id("sum1"));
input1.sendKeys("1");
WebElement input2 = driver.findElement(By.id("sum2"));
input2.sendKeys("3");
WebElement addButton = driver.findElement(By.xpath("//*[@id='gettotal']//button[contains(@class,'selenium_btn')]"));
addButton.click();
WebElement resultDisplayed = driver.findElement(By.id("addmessage"));
String result = resultDisplayed.getText();
Assert.assertEquals("4",result);
System.out.println("********Execution of "+methodName+" has ended********");
}
@AfterTest
public void tearDown() {
driver.quit();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment