After the method you can write:
//Validation
if(exptitle.equals(acttitle)) {
System.out.println("Test is Passed");
}
else {
System.out.println("Test is Failed");
}
driver.close(); // Close the browser
Example:
package PageTestPackage;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.testng.annotations.Test;
import io.github.bonigarcia.wdm.WebDriverManager;
public class OpenUrl {
@Test
public void eSchoolJourney () {
WebDriverManager.chromedriver().setup();
WebDriver driver=new ChromeDriver();
driver.manage().window().maximize();
driver.manage().deleteAllCookies();
driver.get("http://qa.user.student.ui.eschooljourney.com:3001");
System.out.println("Title : "+driver.getTitle());
System.out.println("Current URL "+driver.getCurrentUrl());
//System.out.print("PageSource : "+driver.getPageSource());
driver.findElement(By.id("username_input")).sendKeys("ronoitc"); // Enter username
driver.findElement(By.id("password_input")).sendKeys("Ronjititc@1234"); // Enter password
driver.findElement(By.id("button_test")).click();
String exptitle="eSchool Journey Student User App"; // Collect from Url page source
String acttitle=driver.getTitle(); // get Title by automation
//Validation
if(exptitle.equals(acttitle)) {
System.out.println("Test is Passed");
}
else {
System.out.println("Test is Failed");
}
driver.close(); // Close the browser
}
}