Created
December 26, 2018 17:39
-
-
Save pragmatictesters/1e54dba2f1473d7a4ac0475d4f6f5ea5 to your computer and use it in GitHub Desktop.
Selenium WebDriver Examples : Login to PTL HRM
Demonstrate use of basic commands in Selenium
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 com.pragmatic.selenium; | |
import io.github.bonigarcia.wdm.WebDriverManager; | |
import org.openqa.selenium.By; | |
import org.openqa.selenium.Keys; | |
import org.openqa.selenium.WebDriver; | |
import org.openqa.selenium.WebElement; | |
import org.openqa.selenium.chrome.ChromeDriver; | |
import org.testng.Assert; | |
import org.testng.annotations.Test; | |
import java.util.concurrent.TimeUnit; | |
/** | |
* <b>Selenium WebDriver Examples </b> | |
* <p> | |
* First Selenium script : Login to PTL HRM | |
*/ | |
public class HelloSelenium { | |
/** | |
* Demonstrate login to PTL HRM with valid credentials | |
* | |
* @throws InterruptedException | |
*/ | |
@Test | |
public void testHelloSelenium() throws InterruptedException { | |
//Open an instance the target browser | |
WebDriverManager.chromedriver().setup(); | |
WebDriver driver = new ChromeDriver(); | |
driver.manage().window().fullscreen(); | |
//Implicit wait | |
driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS); | |
//Type the URL in address bar | |
driver.get("http://hrm.pragmatictestlabs.com"); | |
driver.navigate().to("http://hrm.pragmatictestlabs.com"); | |
//driver.navigate().refresh(); | |
//driver.navigate().back(); | |
//driver.navigate().forward(); | |
//Wait till the page is loaded | |
//This will be taken care by Selenium with get method | |
//Do something with the page | |
//Type username | |
WebElement txtUsername = driver.findElement(By.id("txtUsername")); | |
txtUsername.clear(); | |
txtUsername.sendKeys("Admin"); | |
//Type password | |
driver.findElement(By.name("txtPassword")).sendKeys("Ptl@#321"); | |
//driver.findElement(By.name("txtPassword")).sendKeys(Keys.RETURN); | |
//driver.findElement(By.name("txtPassword")).submit(); | |
//Click login button | |
driver.findElement(By.id("btnLogin")).click(); | |
//Verify the output (actual) with the expected | |
//Check the welcome message | |
String welcomeMessage = driver.findElement(By.id("welcome")).getText(); | |
Assert.assertEquals(welcomeMessage, "Welcome Admin"); | |
//Introduce a delay | |
Thread.sleep(5000); | |
//Close the browser | |
driver.close(); | |
//driver.quit(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment