0% found this document useful (0 votes)
2 views

TestNG(TestNG XML File)

Jsjsk
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

TestNG(TestNG XML File)

Jsjsk
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

LoginPageTest.

java
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.By;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;
import org.testng.Assert;
import org.testng.annotations.*;
import java.time.Duration;

public class LoginPageTest {


public WebDriver driver;
@BeforeMethod
public void setUp()
{
System.setProperty("webdriver.chrome.driver", "C:\\Users\\DELL\\Downloads\\chromedriver-win32\\chromedriver-
win32\\chromedriver.exe");
driver = new ChromeDriver();
driver.get("https://qaebank.ccbp.tech/ebank/login");
}

@AfterMethod
public void tearDown()
{
driver.close();
}

@Test
public void testLoginWithEmptyFields()
{
WebDriverWait wait = new WebDriverWait(driver,Duration.ofSeconds(10));
wait.until(ExpectedConditions.visibilityOfElementLocated(By.cssSelector("button.login-button")));

WebElement loginButton = driver.findElement(By.cssSelector("button.login-button"));


loginButton.click();

wait = new WebDriverWait(driver,Duration.ofSeconds(10));


wait.until(ExpectedConditions.visibilityOfElementLocated(By.cssSelector("p.error-message-text")));

WebElement errorText = driver.findElement(By.cssSelector("p.error-message-text"));


String actualError = errorText.getText();
String expectedError = "Invalid user ID";
Assert.assertEquals(actualError,expectedError,"Error text with empty input fields does not match");
}

@Test
public void testLoginWithEmptyUserId()
{
WebElement pinField = driver.findElement(By.cssSelector("input#pinInput"));
pinField.sendKeys("231225");

WebDriverWait wait = new WebDriverWait(driver,Duration.ofSeconds(10));


wait.until(ExpectedConditions.visibilityOfElementLocated(By.cssSelector("button.login-button")));
WebElement loginButton = driver.findElement(By.cssSelector("button.login-button"));
loginButton.click();

wait = new WebDriverWait(driver,Duration.ofSeconds(10));


wait.until(ExpectedConditions.visibilityOfElementLocated(By.cssSelector("p.error-message-text")));

WebElement errorText = driver.findElement(By.cssSelector("p.error-message-text"));


String actualError = errorText.getText();
String expectedError = "Invalid user ID";
Assert.assertEquals(actualError,expectedError,"Error text with empty input field do not match");
}

@Test
public void testLoginWithEmptyPin()
{
WebElement userIdField = driver.findElement(By.cssSelector("input#userIdInput"));
userIdField.sendKeys("142420");

WebDriverWait wait = new WebDriverWait(driver,Duration.ofSeconds(10));


wait.until(ExpectedConditions.visibilityOfElementLocated(By.cssSelector("button.login-button")));

WebElement loginButton = driver.findElement(By.cssSelector("button.login-button"));


loginButton.click();

wait = new WebDriverWait(driver,Duration.ofSeconds(10));


wait.until(ExpectedConditions.visibilityOfElementLocated(By.cssSelector("p.error-message-text")));

WebElement errorText = driver.findElement(By.cssSelector("p.error-message-text"));


String actualError = errorText.getText();
String expectedError = "Invalid PIN";
Assert.assertEquals(actualError,expectedError,"Error text with empty input field do not match");
}

@Test
public void testLoginWithInvalidPin()
{
WebElement userIdField = driver.findElement(By.cssSelector("input#userIdInput"));
userIdField.sendKeys("142420");

WebElement pinField = driver.findElement(By.cssSelector("input#pinInput"));


pinField.sendKeys("123456");

WebDriverWait wait = new WebDriverWait(driver,Duration.ofSeconds(10));


wait.until(ExpectedConditions.visibilityOfElementLocated(By.cssSelector("button.login-button")));

WebElement loginButton = driver.findElement(By.cssSelector("button.login-button"));


loginButton.click();

wait = new WebDriverWait(driver,Duration.ofSeconds(10));


wait.until(ExpectedConditions.visibilityOfElementLocated(By.cssSelector("p.error-message-text")));

WebElement errorText = driver.findElement(By.cssSelector("p.error-message-text"));


String actualError = errorText.getText();
String expectedError = "User ID and PIN didn't match";
Assert.assertEquals(actualError,expectedError,"Error text with invalid pin do not match");

@Test
public void testLoginWithValidCreds()
{
WebElement userIdField = driver.findElement(By.cssSelector("input#userIdInput"));
userIdField.sendKeys("142420");

WebElement pinField = driver.findElement(By.cssSelector("input#pinInput"));


pinField.sendKeys("231225");

WebDriverWait wait = new WebDriverWait(driver,Duration.ofSeconds(10));


wait.until(ExpectedConditions.visibilityOfElementLocated(By.cssSelector("button.login-button")));

WebElement loginButton = driver.findElement(By.cssSelector("button.login-button"));


loginButton.click();

wait = new WebDriverWait(driver,Duration.ofSeconds(10));


wait.until(ExpectedConditions.urlToBe("https://qaebank.ccbp.tech/"));

String actualURL = driver.getCurrentUrl();


String expectedURL = "https://qaebank.ccbp.tech/";
Assert.assertEquals(actualURL,expectedURL,"URLs do not match");

}
}

HomePageTest.java
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.By;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;
import org.testng.Assert;
import org.testng.annotations.*;
import java.time.Duration;

public class HomePageTest {

public WebDriver driver;


@BeforeMethod
public void setUp()
{
System.setProperty("webdriver.chrome.driver", "C:\\Users\\DELL\\Downloads\\chromedriver-win32\\chromedriver-
win32\\chromedriver.exe");
driver = new ChromeDriver();
driver.get("https://qaebank.ccbp.tech/ebank/login");
}

@AfterMethod
public void tearDown()
{
driver.close();
}

@Test
public void testHomePageHeading()
{
WebElement userIdField = driver.findElement(By.cssSelector("input#userIdInput"));
userIdField.sendKeys("142420");

WebElement pinField = driver.findElement(By.cssSelector("input#pinInput"));


pinField.sendKeys("231225");

WebDriverWait wait = new WebDriverWait(driver,Duration.ofSeconds(10));


wait.until(ExpectedConditions.visibilityOfElementLocated(By.cssSelector("button.login-button")));

WebElement loginButton = driver.findElement(By.cssSelector("button.login-button"));


loginButton.click();

wait = new WebDriverWait(driver,Duration.ofSeconds(10));


wait.until(ExpectedConditions.urlToBe("https://qaebank.ccbp.tech/"));

WebElement headingText = driver.findElement(By.cssSelector("h1.heading"));


String actualText = headingText.getText();
String expectedText = "Your Flexibility, Our Excellence";
Assert.assertEquals(actualText,expectedText,"print \"Heading text does not match");
}

@Test
public void testLogoutFunctionality()
{
WebElement userIdField = driver.findElement(By.cssSelector("input#userIdInput"));
userIdField.sendKeys("142420");

WebElement pinField = driver.findElement(By.cssSelector("input#pinInput"));


pinField.sendKeys("231225");

WebDriverWait wait = new WebDriverWait(driver,Duration.ofSeconds(10));


wait.until(ExpectedConditions.visibilityOfElementLocated(By.cssSelector("button.login-button")));
WebElement loginButton = driver.findElement(By.cssSelector("button.login-button"));
loginButton.click();
wait = new WebDriverWait(driver,Duration.ofSeconds(10));
wait.until(ExpectedConditions.urlToBe("https://qaebank.ccbp.tech/"));
WebElement logoutButton = driver.findElement(By.cssSelector("button.logout-button"));
logoutButton.click();
wait = new WebDriverWait(driver,Duration.ofSeconds(10));
wait.until(ExpectedConditions.urlToBe("https://qaebank.ccbp.tech/ebank/login"));
String actualURL = driver.getCurrentUrl();
String expectedURL = "https://qaebank.ccbp.tech/ebank/login";
Assert.assertEquals(actualURL,expectedURL,"Login URL do not match");
}
}

testng.xml
<!DOCTYPE suite SYSTEM "https://testng.org/testng-1.0.dtd">
<suite name = "EBank Test Suite" parallel="tests" thread-count="2">
<test name = "LoginPage">
<classes>
<class name="LoginPageTest"></class>
</classes>
</test>

<test name = "HomePage">


<classes>
<class name="HomePageTest"></class>
</classes>
</test>
</suite>

You might also like