Created
December 29, 2021 11:47
-
-
Save muditlambda/567efe141cdff08068785749314761af to your computer and use it in GitHub Desktop.
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
import org.junit.jupiter.api.*; | |
import org.junit.jupiter.params.ParameterizedTest; | |
import org.junit.jupiter.params.provider.Arguments; | |
import org.junit.jupiter.params.provider.MethodSource; | |
import org.openqa.selenium.By; | |
import org.openqa.selenium.WebDriver; | |
import org.openqa.selenium.WebElement; | |
import org.openqa.selenium.chrome.ChromeDriver; | |
import org.openqa.selenium.firefox.FirefoxDriver; | |
import java.util.concurrent.TimeUnit; | |
import java.util.stream.Stream; | |
import static org.junit.jupiter.params.provider.Arguments.arguments; | |
public class JUnitParamTest { | |
String urlToTest = "https://www.lambdatest.com/selenium-playground/simple-form-demo.php"; | |
WebDriver driver; | |
public void browser_setup(String browser) { | |
System.out.println("Setting up the drivers and browsers"); | |
if(browser.equalsIgnoreCase("Chrome")) { | |
System.setProperty("webdriver.chrome.driver", "C:\\Users\\Shalini\\Downloads\\chromedriver_latest94\\chromedriver.exe"); | |
driver = new ChromeDriver(); | |
} | |
if(browser.equalsIgnoreCase("Firefox")) { | |
System.setProperty("webdriver.gecko.driver","C:\\Users\\Shalini\\Downloads\\geckodriver\\geckodriver.exe"); | |
driver = new FirefoxDriver(); | |
} | |
} | |
@ParameterizedTest | |
@MethodSource("browser") | |
public void enterAndDisplayMessage(String browser) { | |
browser_setup(browser); | |
String inputString ="Hello"; | |
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(); | |
Assertions.assertEquals(inputString,message); | |
System.out.println("********Execution of "+methodName+" has ended********"); | |
} | |
@AfterEach | |
public void tearDown() { | |
System.out.println("Quitting the browsers has started"); | |
driver.quit(); | |
System.out.println("Quitting the browsers has ended"); | |
} | |
@AfterAll | |
public static void end() { | |
System.out.println("Tests ended"); | |
} | |
static Stream<Arguments> browser() { | |
return Stream.of( | |
arguments("Chrome"), | |
arguments("Firefox") | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment