Implemented selenium automation tests for all functionalities

This commit is contained in:
Marko 2024-05-11 15:20:29 +02:00
parent 516722647a
commit c8386f6311
19 changed files with 1302 additions and 3 deletions

43
pom.xml
View file

@ -139,6 +139,43 @@
<artifactId>jakarta.xml.bind-api</artifactId> <artifactId>jakarta.xml.bind-api</artifactId>
</dependency> </dependency>
<!-- https://mvnrepository.com/artifact/org.seleniumhq.selenium/selenium-java -->
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>4.20.0</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.testng/testng -->
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<version>7.9.0</version>
<scope>test</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/org.uncommons/reportng -->
<dependency>
<groupId>org.uncommons</groupId>
<artifactId>reportng</artifactId>
<version>1.1.4</version>
<scope>test</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/org.apache.poi/poi -->
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi</artifactId>
<version>5.2.5</version>
</dependency>
<dependency>
<groupId>io.github.bonigarcia</groupId>
<artifactId>webdrivermanager</artifactId>
<version>5.7.0</version>
<scope>test</scope>
</dependency>
</dependencies> </dependencies>
<build> <build>
@ -220,7 +257,7 @@
<artifactId>spring-boot-maven-plugin</artifactId> <artifactId>spring-boot-maven-plugin</artifactId>
<executions> <executions>
<execution> <execution>
<!-- Spring Boot Actuator displays build-related information <!-- Spring Boot Actuator displays build-related information
if a META-INF/build-info.properties file is present --> if a META-INF/build-info.properties file is present -->
<goals> <goals>
<goal>build-info</goal> <goal>build-info</goal>
@ -378,7 +415,7 @@
<build> <build>
<pluginManagement> <pluginManagement>
<plugins> <plugins>
<!-- This plugin's configuration is used to store Eclipse m2e settings <!-- This plugin's configuration is used to store Eclipse m2e settings
only. It has no influence on the Maven build itself. --> only. It has no influence on the Maven build itself. -->
<plugin> <plugin>
<groupId>org.eclipse.m2e</groupId> <groupId>org.eclipse.m2e</groupId>
@ -436,4 +473,4 @@
</profile> </profile>
</profiles> </profiles>
</project> </project>

View file

@ -0,0 +1,97 @@
package selenium;
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.chrome.ChromeOptions;
import org.openqa.selenium.edge.EdgeDriver;
import org.openqa.selenium.edge.EdgeOptions;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.firefox.FirefoxOptions;
import org.testng.Assert;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeMethod;
import java.io.FileReader;
import java.io.IOException;
import java.util.Properties;
public class TestBase {
public static WebDriver driver;
public static Properties prop = new Properties();
public static Properties locators = new Properties();
public static Properties tap = new Properties();
public static Properties input = new Properties();
public static FileReader frProp;
public static FileReader frLoc;
public static FileReader frTap;
public static FileReader frInput;
@BeforeMethod
public void setUp() throws IOException {
String userDirectory = System.getProperty("user.dir");
String basePath = "\\src\\test\\java\\selenium\\config\\";
String propPath = basePath + "config.properties";
String locPath = basePath + "locators.properties";
String tapPath = basePath + "textsAndPhotos.properties";
String inputPath = basePath + "input.properties";
if (driver == null) {
frProp = new FileReader(userDirectory + propPath);
frLoc = new FileReader(userDirectory + locPath);
frTap = new FileReader(userDirectory + tapPath);
frInput = new FileReader(userDirectory + inputPath);
prop.load(frProp);
locators.load(frLoc);
tap.load(frTap);
input.load(frInput);
}
String browser = prop.getProperty("browser").toLowerCase();
ChromeOptions chromeOptions = new ChromeOptions();
chromeOptions.addArguments("--headless", "-disable-gpu", "-window-size=1920,1080");
FirefoxOptions firefoxOptions = new FirefoxOptions();
firefoxOptions.addArguments("--headless", "-disable-gpu", "-window-size=1920,1080");
EdgeOptions edgeOptions = new EdgeOptions();
edgeOptions.addArguments("--headless", "-disable-gpu", "-window-size=1920,1080");
switch (browser) {
case "chrome":
driver = new ChromeDriver(chromeOptions);
break;
case "firefox":
driver = new FirefoxDriver(firefoxOptions);
break;
case "edge":
driver = new EdgeDriver(edgeOptions);
break;
default:
throw new IllegalArgumentException("Unsupported browser: " + browser);
}
// driver.manage().window().maximize();
driver.get(prop.getProperty("testUrl"));
WebElement welcomePhoto = driver.findElement(By.className(locators.getProperty("welcomePhoto")));
String ActualWelcomePhotoSrc = welcomePhoto.getAttribute("src");
String expectedWelcomePhoto = tap.getProperty("welcomePhoto");
Assert.assertEquals(ActualWelcomePhotoSrc, expectedWelcomePhoto);
}
@AfterMethod
public void tearDown() {
driver.quit();
}
}

View file

@ -0,0 +1,2 @@
browser=chrome
testUrl=http://localhost:8080/

View file

@ -0,0 +1,64 @@
existingLastName=Franklin
existingFirstName=George
nonExistingLastName=White
caseSensitiveLastName=franklin
firstName=Mark
lastName=Jack
address=Red Boulevard 16
city=Skopje
telephone=075500000
numbersInFirstName=1234
numbersInLastName=5678
firstName2=Jack
lastName2=Bryan
address2=Grey Street 12
city2=London
telephone2=123456789
textInTelephoneField=telephones
updateFirstName = John
updateLastName = Doe
updateAddress = 123 Main St
updateCity = New York
updateTelephone = 55501234
firstName3=Kix
lastName3=Exe
address3=Rouge St 999
city3=Johannesburg
telephone3=098765432
updateFirstName2=John
updateLastName2=Do
updateAddress2=124 Main St
updateCity2=Nevada
updateTelephone2=55501235
petName=Rodrigo
birthDate=03202021
petType=bird
petName2=Benji
birthDate2=10022020
petType2=dog
petName3=Naila
birthDate3=05052018
petType3=snake
petName4=Scar
futureBirthDate=01012500
petType4=lizard
numberPetName=16
birthDate5=01102022
petType5=cat
date=05042023
description=Needs more care and love
invalidDate=0101123123

View file

@ -0,0 +1,36 @@
welcomePhoto=img-responsive
findOwnersLink=//span[normalize-space()='Find owners']
lastNameField=lastName
findOwnerButton=button[type='submit']
addOwnerButton=//a[normalize-space()='Add Owner']
editOwnerButton=//a[@class='btn btn-primary'][contains(text(),'Edit')]
addNewPetButton=//a[@class='btn btn-primary'][contains(text(),'Add')]
editPetButton=//a[normalize-space()='Edit Pet']
addVisitButton=//a[normalize-space()='Add Visit']
nameLocator=(//td)[1]
ownerNotFound=span[class='help-inline'] div p
tableId=owners
firstNameField=firstName
address=address
city=city
telephone=telephone
successMessageAlert=success-message
addOwnerButton2=//*[@id="add-owner-form"]/div[2]/div/button
thirdPage=//a[normalize-space()='3']
updateOwnerButton=//button[normalize-space()='Update Owner']
updateMessageAlert=success-message
namePetField=name
birthDateField=birthDate
petTypeField=type
addPetButton=//button[normalize-space()='Add Pet']
newPetAddedMessageAlert=success-message
petDetails=dl-horizontal
addPetPageErrorMessage=help-inline
updatePetButton=//button[normalize-space()='Update Pet']
visitDate=date
descriptionField=description
addVisit=/html/body/div/div/form/div[2]/div/button
visitAddedMessage=success-message
visitDetails=table-condensed
homePageLink=//span[normalize-space()='Home']
logoLink=//a[@class='navbar-brand']//span

View file

@ -0,0 +1,16 @@
welcomePhoto=http://localhost:8080/resources/images/pets.png
ownerNotFoundText=has not been found
Owner1=George Franklin 110 W. Liberty St. Madison 6085551023 Leo
Owner2=Betty Davis 638 Cardinal Ave. Sun Prairie 6085551749 Basil
successMessage=New Owner Created
errorMessage=must not be blank
errorMessageTelephoneField=numeric value out of bounds (<10 digits>.<0 digits> expected)
updateMessage=Owner Values Updated
newPetAddedMessage=New Pet has been Added
samePetNameErrorMessage=is already in use
emptyPetFieldsErrorMessage=is required
invalidDateErrorMessage=invalid date
petUpdateMessage=Pet details has been edited
visitAddedMessage=Your vist has been boked
emptyFieldInAddVisit=must not be blank
invalidDateInAddVisit=invalid date

View file

@ -0,0 +1,75 @@
package selenium.pages;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.ui.WebDriverWait;
import selenium.TestBase;
import java.time.Duration;
import java.util.List;
import java.util.Properties;
import static org.openqa.selenium.support.ui.ExpectedConditions.visibilityOf;
import static org.openqa.selenium.support.ui.ExpectedConditions.visibilityOfAllElements;
public class AddOwnerPage extends TestBase {
public AddOwnerPage(WebDriver driver, Properties loc) {
TestBase.driver = driver;
TestBase.locators = loc;
}
WebDriverWait wait = new WebDriverWait(driver, Duration.ofSeconds(2));
By firstNameField = By.id(locators.getProperty("firstNameField"));
By lastNameField = By.id(locators.getProperty("lastNameField"));
By addressField = By.id(locators.getProperty("address"));
By cityField = By.id(locators.getProperty("city"));
By telephoneField = By.id(locators.getProperty("telephone"));
By addOwnerButton = By.xpath(locators.getProperty("addOwnerButton2"));
By updateOwnerButton = By.xpath(locators.getProperty("updateOwnerButton"));
public void setTextInFields(String firstName, String lastName, String address, String city, String telephone) {
driver.findElement(firstNameField).sendKeys(firstName);
driver.findElement(lastNameField).sendKeys(lastName);
driver.findElement(addressField).sendKeys(address);
driver.findElement(cityField).sendKeys(city);
driver.findElement(telephoneField).sendKeys(telephone);
}
public void clickingOnAddOwnerButton() {
driver.findElement(addOwnerButton).click();
}
public boolean isErrorMessageDisplayedForEmptyFields(String message) {
List<WebElement> messages = driver.findElements(By.xpath("//*[contains(text(),'" + message + "')]"));
wait.until(visibilityOfAllElements(messages));
return messages.size() >= 4;
}
public boolean isErrorMessageDisplayedForTextInTelephoneField(String message) {
WebElement ErrorMessage = driver.findElement(By.xpath("//*[contains(text(),'" + message + "')]"));
wait.until(visibilityOf(ErrorMessage));
return ErrorMessage.getText().equals(message);
}
public void clearFields() {
driver.findElement(firstNameField).clear();
driver.findElement(lastNameField).clear();
driver.findElement(addressField).clear();
driver.findElement(cityField).clear();
driver.findElement(telephoneField).clear();
}
public void clickOnUpdateOwnerButton() {
driver.findElement(updateOwnerButton).click();
}
}

View file

@ -0,0 +1,74 @@
package selenium.pages;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.ui.Select;
import org.openqa.selenium.support.ui.WebDriverWait;
import selenium.TestBase;
import java.time.Duration;
import java.util.List;
import java.util.Properties;
import static org.openqa.selenium.support.ui.ExpectedConditions.visibilityOfAllElements;
public class AddPetPage extends TestBase {
public AddPetPage(WebDriver driver, Properties loc) {
TestBase.driver = driver;
TestBase.locators = loc;
}
WebDriverWait wait = new WebDriverWait(driver, Duration.ofSeconds(3));
By namePetField = By.id(locators.getProperty("namePetField"));
By birthDateField = By.id(locators.getProperty("birthDateField"));
By petTypeField = By.id(locators.getProperty("petTypeField"));
By addPetButton = By.xpath(locators.getProperty("addPetButton"));
By updatePetButton = By.xpath(locators.getProperty("updatePetButton"));
public void fillTheFields(String namePet, String birthDate, String petType) {
driver.findElement(namePetField).sendKeys(namePet);
driver.findElement(birthDateField).sendKeys(birthDate);
WebElement dropdownElement = driver.findElement(petTypeField);
Select dropdown = new Select(dropdownElement);
dropdown.selectByValue(petType);
}
public void clickOnAddPetButton() {
driver.findElement(addPetButton).click();
}
public boolean isErrorMessageDisplayedForSamePetName() {
WebElement error = driver.findElement(By.className(locators.getProperty("addPetPageErrorMessage")));
String expectedErrorText = tap.getProperty("samePetNameErrorMessage");
return error.getText().equals(expectedErrorText);
}
public boolean isErrorMessageDisplayedForEmptyFields(String message) {
List<WebElement> messages = driver.findElements(By.xpath("//*[contains(text(),'" + message + "')]"));
wait.until(visibilityOfAllElements(messages));
return messages.size() == 2;
}
public boolean isInvalidDateErrorMessageDisplayed() {
WebElement error = driver.findElement(By.className(locators.getProperty("addPetPageErrorMessage")));
String expectedErrorText = tap.getProperty("invalidDateErrorMessage");
return error.getText().equals(expectedErrorText);
}
public void clearFields() {
driver.findElement(namePetField).clear();
driver.findElement(birthDateField).clear();
}
public void clickOnUpdatePetButton() {
driver.findElement(updatePetButton).click();
}
}

View file

@ -0,0 +1,50 @@
package selenium.pages;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.ui.WebDriverWait;
import selenium.TestBase;
import java.time.Duration;
import java.util.Properties;
import static org.openqa.selenium.support.ui.ExpectedConditions.visibilityOf;
public class AddVisitPage extends TestBase {
public AddVisitPage(WebDriver driver, Properties loc) {
TestBase.driver = driver;
TestBase.locators = loc;
}
WebDriverWait wait = new WebDriverWait(driver, Duration.ofSeconds(4));
By visitDateField = By.id(locators.getProperty("visitDate"));
By descriptionField = By.id(locators.getProperty("descriptionField"));
By addVisitButton = By.xpath(locators.getProperty("addVisit"));
public void fillTheFields(String visitDate, String description) {
driver.findElement(visitDateField).sendKeys(visitDate);
driver.findElement(descriptionField).sendKeys(description);
}
public void clickOnAddVisitButton() {
driver.findElement(addVisitButton).click();
}
public boolean isErrorMessageDisplayedForEmptyField(String message) {
WebElement ErrorMessage = driver.findElement(By.xpath("//*[contains(text(),'" + message + "')]"));
wait.until(visibilityOf(ErrorMessage));
return ErrorMessage.getText().equals(message);
}
public boolean isErrorMessageDisplayedForInvalidDate(String message) {
WebElement ErrorMessage = driver.findElement(By.xpath("//*[contains(text(),'" + message + "')]"));
wait.until(visibilityOf(ErrorMessage));
return ErrorMessage.getText().equals(message);
}
}

View file

@ -0,0 +1,60 @@
package selenium.pages;
import org.openqa.selenium.*;
import org.openqa.selenium.support.ui.WebDriverWait;
import selenium.TestBase;
import java.time.Duration;
import java.util.Properties;
import static org.openqa.selenium.support.ui.ExpectedConditions.visibilityOfElementLocated;
public class FindOwnersPage extends TestBase {
public FindOwnersPage(WebDriver driver, Properties loc) {
TestBase.driver = driver;
TestBase.locators = loc;
}
WebDriverWait wait = new WebDriverWait(driver, Duration.ofSeconds(3));
By findOwnersPageLink = By.xpath(locators.getProperty("findOwnersLink"));
By lastNameField = By.id(locators.getProperty("lastNameField"));
By findOwnerButton = By.cssSelector(locators.getProperty("findOwnerButton"));
By addOwnerButton = By.xpath(locators.getProperty("addOwnerButton"));
By ownerNotFound = By.cssSelector(locators.getProperty("ownerNotFound"));
public void navigateToFindOwnersPage() {
wait.until(visibilityOfElementLocated(findOwnersPageLink));
driver.findElement(findOwnersPageLink).click();
}
public void setTextInLastNameField(String text) {
wait.until(visibilityOfElementLocated(lastNameField));
driver.findElement(lastNameField).sendKeys(text);
}
public void clickOnFindOwnerButton() {
driver.findElement(findOwnerButton).sendKeys(Keys.RETURN);
}
public void clickOnAddOwnerButton() {
driver.findElement(addOwnerButton).click();
wait.until(visibilityOfElementLocated(By.tagName("h2")));
}
public String getOwnerNotFoundText() {
try {
WebElement ownerNotFoundElement = driver.findElement(ownerNotFound);
return ownerNotFoundElement.getText();
}
catch (NoSuchElementException e) {
return null;
}
}
}

View file

@ -0,0 +1,42 @@
package selenium.pages;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.ui.WebDriverWait;
import selenium.TestBase;
import java.time.Duration;
import java.util.Properties;
import static org.openqa.selenium.support.ui.ExpectedConditions.visibilityOfElementLocated;
public class HomePage extends TestBase {
public HomePage(WebDriver driver, Properties loc) {
TestBase.driver = driver;
TestBase.locators = loc;
}
By welcomePhoto = By.className(locators.getProperty("welcomePhoto"));
By homePageLink = By.xpath(locators.getProperty("homePageLink"));
By logoLink = By.xpath(locators.getProperty("logoLink"));
public void clickOnHomePageLink() {
driver.findElement(homePageLink).click();
}
public boolean isWelcomePhotoVisible(String src) {
WebDriverWait wait = new WebDriverWait(driver, Duration.ofSeconds(3));
wait.until(visibilityOfElementLocated(welcomePhoto));
WebElement welcomePicture = driver.findElement(welcomePhoto);
return welcomePicture.getAttribute("src").equals(src);
}
public void clickOnLogoLink() {
driver.findElement(logoLink).click();
}
}

View file

@ -0,0 +1,61 @@
package selenium.pages;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.ui.WebDriverWait;
import selenium.TestBase;
import java.time.Duration;
import java.util.List;
import java.util.Properties;
import static org.openqa.selenium.support.ui.ExpectedConditions.visibilityOf;
import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertTrue;
public class ListOwnersPage extends TestBase {
public ListOwnersPage(WebDriver driver, Properties loc) {
TestBase.driver = driver;
TestBase.locators = loc;
}
WebDriverWait wait = new WebDriverWait(driver, Duration.ofSeconds(3));
By table = By.id(locators.getProperty("tableId"));
WebElement tableElement = driver.findElement(table);
List<WebElement> rows = tableElement.findElements(By.tagName("tr"));
public void tableAppearance() {
wait.until(visibilityOf(tableElement));
assertTrue(tableElement.isDisplayed(), "Table is displayed");
assertEquals(rows.size(), 6, "Expected 6 rows in the table");
String owner1 = tap.getProperty("Owner1");
String owner2 = tap.getProperty("Owner2");
assertEquals(rows.get(1).getText(), owner1, "Incorrect data in row 1");
assertEquals(rows.get(2).getText(), owner2, "Incorrect data in row 2");
}
public void clickOnNameFromTable() {
WebElement firstRow = rows.get(1);
List<WebElement> name = firstRow.findElements(By.tagName("td"));
WebElement firstName = name.get(0);
String firstNameText = firstName.getText();
firstName.click();
WebElement ownerName = driver.findElement(By.xpath("(//td)[1]"));
String ownerNameText = ownerName.getText();
assertEquals(ownerNameText, firstNameText);
}
public void clickOnDifferentPage(String page) {
driver.findElement(By.xpath(page)).click();
}
}

View file

@ -0,0 +1,123 @@
package selenium.pages;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.ui.WebDriverWait;
import selenium.TestBase;
import java.time.Duration;
import java.util.List;
import java.util.Properties;
import static org.openqa.selenium.support.ui.ExpectedConditions.visibilityOf;
import static org.openqa.selenium.support.ui.ExpectedConditions.visibilityOfElementLocated;
public class OwnerPage extends TestBase {
public OwnerPage(WebDriver driver, Properties loc) {
TestBase.driver = driver;
TestBase.locators = loc;
}
WebDriverWait wait = new WebDriverWait(driver, Duration.ofSeconds(3));
By editOwnerButton = By.xpath(locators.getProperty("editOwnerButton"));
By addNewPetButton = By.xpath(locators.getProperty("addNewPetButton"));
By editPetButton = By.xpath(locators.getProperty("editPetButton"));
By addVisitButton = By.xpath(locators.getProperty("addVisitButton"));
By nameLocator = By.xpath(locators.getProperty("nameLocator"));
By successMessage = By.id(locators.getProperty("successMessageAlert"));
By updateMessage = By.id(locators.getProperty("updateMessageAlert"));
By newPetAddedMessage = By.id(locators.getProperty("newPetAddedMessageAlert"));
By petDetailsClass = By.className(locators.getProperty("petDetails"));
By petUpdateMessage = By.id(locators.getProperty("updateMessageAlert"));
By visitAddedMessage = By.id(locators.getProperty("visitAddedMessage"));
By visitDetailsClass = By.className(locators.getProperty("visitDetails"));
public boolean isLastNameDisplayed(String lastName) {
WebElement element = driver.findElement(nameLocator);
return element.getText().contains(lastName);
}
public boolean isSuccessMessageDisplayed() {
wait.until(visibilityOfElementLocated(successMessage));
WebElement message = driver.findElement(successMessage);
String expectedSuccessMessage = tap.getProperty("successMessage");
return message.getText().equals(expectedSuccessMessage);
}
public void clickOnEditOwnerButton() {
driver.findElement(editOwnerButton).click();
wait.until(visibilityOf(driver.findElement(By.tagName("h2"))));
}
public boolean isUpdateMessageDisplayed() {
wait.until(visibilityOfElementLocated(updateMessage));
WebElement message = driver.findElement(updateMessage);
String expectedUpdateMessage = tap.getProperty("updateMessage");
return message.getText().equals(expectedUpdateMessage);
}
public void clickOnAddNewPetButton() {
driver.findElement(addNewPetButton).click();
wait.until(visibilityOf(driver.findElement(By.tagName("h2"))));
}
public boolean isPetAddedSuccessMessageDisplayed() {
wait.until(visibilityOfElementLocated(newPetAddedMessage));
WebElement message = driver.findElement(newPetAddedMessage);
String expectedMessage = tap.getProperty("newPetAddedMessage");
return message.getText().equals(expectedMessage);
}
public boolean isPetNameDisplayed(String petName) {
WebElement petDetails = driver.findElement(petDetailsClass);
String petDetailsText = petDetails.getText();
String expectedPetName = input.getProperty(petName);
return petDetailsText.contains(expectedPetName);
}
public void clickOnEditPetButton() {
List<WebElement> editButtons = driver.findElements(editPetButton);
if (!editButtons.isEmpty()) {
editButtons.get(0).click();
}
}
public boolean isUpdatePetMessageDisplayed() {
wait.until(visibilityOfElementLocated(petUpdateMessage));
WebElement message = driver.findElement(petUpdateMessage);
String expectedUpdateMessage = tap.getProperty("petUpdateMessage");
return message.getText().equals(expectedUpdateMessage);
}
public void clickOnAddVisitButton() {
driver.findElement(addVisitButton).click();
}
public boolean isVisitAddedMessageDisplayed() {
wait.until(visibilityOfElementLocated(visitAddedMessage));
WebElement message = driver.findElement(visitAddedMessage);
String expectedUpdateMessage = tap.getProperty("visitAddedMessage");
return message.getText().equals(expectedUpdateMessage);
}
public boolean isVisitAdded(String description) {
WebElement visitDetails = driver.findElement(visitDetailsClass);
String expectedDescription = input.getProperty(description);
return visitDetails.getText().contains(expectedDescription);
}
}

View file

@ -0,0 +1,128 @@
package selenium.scenarios;
import jdk.jfr.Description;
import org.openqa.selenium.By;
import org.openqa.selenium.WebElement;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
import selenium.TestBase;
import selenium.pages.AddOwnerPage;
import selenium.pages.FindOwnersPage;
import selenium.pages.ListOwnersPage;
import selenium.pages.OwnerPage;
import java.util.List;
import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertTrue;
public class TS01FindOwnersTest extends TestBase {
private OwnerPage ownerPage;
private FindOwnersPage findOwnersPage;
@BeforeMethod
public void setObjects() {
ownerPage = new OwnerPage(driver, locators);
findOwnersPage = new FindOwnersPage(driver, locators);
}
private void setupFindOwnersPage(String lastName) {
findOwnersPage.navigateToFindOwnersPage();
findOwnersPage.setTextInLastNameField(lastName);
findOwnersPage.clickOnFindOwnerButton();
}
@Test
@Description("Validate if the correct owner is displayed after searching by an existing last name")
public void testFindOwnerByExistingLastName() {
setupFindOwnersPage(input.getProperty("existingLastName"));
assertTrue(ownerPage.isLastNameDisplayed(input.getProperty("existingLastName")),
"The last name should be displayed on the Owner page");
}
@Test(priority = 1)
@Description("Validate if an owner is displayed after searching by an existing first name")
public void testFindOwnerByExistingFirstName() {
setupFindOwnersPage(input.getProperty("existingFirstName"));
String ownerNotFoundText = findOwnersPage.getOwnerNotFoundText();
String expectedText = tap.getProperty("ownerNotFoundText");
assertEquals(ownerNotFoundText, expectedText, "Expected text has been displayed");
}
@Test(priority = 2)
@Description("Validate if an owner is displayed after searching for a non-existing last name")
public void testFindOwnerByNonExistingLastName() {
setupFindOwnersPage(input.getProperty("nonExistingLastName"));
String ownerNotFoundText = findOwnersPage.getOwnerNotFoundText();
String expectedText = tap.getProperty("ownerNotFoundText");
assertEquals(ownerNotFoundText, expectedText, "Expected text has been displayed");
}
@Test(priority = 3)
@Description("Validate case sensitivity after searching by an existing last name")
public void testCaseSensitiveLastName() {
setupFindOwnersPage(input.getProperty("caseSensitiveLastName"));
assertTrue(ownerPage.isLastNameDisplayed(input.getProperty("existingLastName")),
"The last name should be displayed on the Owner page");
}
@Test(priority = 4)
@Description("Validate if all owners are displayed after clicking the 'Find Owner' button "
+ "without filling the 'Last name' field")
public void testEmptyLastNameField() {
setupFindOwnersPage("");
ListOwnersPage listOwnersPage = new ListOwnersPage(driver, locators);
listOwnersPage.tableAppearance();
}
@Test(priority = 5)
@Description("Validate if you can navigate to the Owner page after clicking on a name from the table")
public void testNavigateToOwnerPageFromTable() {
setupFindOwnersPage("");
ListOwnersPage listOwnersPage = new ListOwnersPage(driver, locators);
listOwnersPage.clickOnNameFromTable();
}
@Test(priority = 6)
@Description("Validate finding a newly added owner")
public void testFindNewlyAddedOwner() {
findOwnersPage.navigateToFindOwnersPage();
findOwnersPage.clickOnAddOwnerButton();
String firstName = input.getProperty("firstName");
String lastName = input.getProperty("lastName");
String address = input.getProperty("address");
String city = input.getProperty("city");
String telephone = input.getProperty("telephone");
AddOwnerPage addOwnerPage = new AddOwnerPage(driver, locators);
addOwnerPage.setTextInFields(firstName, lastName, address, city, telephone);
addOwnerPage.clickingOnAddOwnerButton();
assertTrue(ownerPage.isSuccessMessageDisplayed());
assertTrue(ownerPage.isLastNameDisplayed(lastName));
findOwnersPage.navigateToFindOwnersPage();
findOwnersPage.clickOnFindOwnerButton();
ListOwnersPage listOwnersPage = new ListOwnersPage(driver, locators);
listOwnersPage.clickOnDifferentPage(locators.getProperty("thirdPage"));
List<WebElement> cells = driver.findElements(By.xpath("(//td)"));
cells.stream()
.filter(cell -> cell.getText().equals(firstName + " " + lastName))
.findFirst()
.ifPresent(WebElement::click);
assertTrue(ownerPage.isLastNameDisplayed(lastName));
}
}

View file

@ -0,0 +1,161 @@
package selenium.scenarios;
import jdk.jfr.Description;
import org.jetbrains.annotations.NotNull;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
import selenium.TestBase;
import selenium.pages.AddOwnerPage;
import selenium.pages.FindOwnersPage;
import selenium.pages.ListOwnersPage;
import selenium.pages.OwnerPage;
import static org.testng.AssertJUnit.*;
public class TS02AddOwnerTest extends TestBase {
private AddOwnerPage addOwnerPage;
private OwnerPage ownerPage;
private FindOwnersPage findOwnersPage;
@BeforeMethod
public void setObjects() {
addOwnerPage = new AddOwnerPage(driver, locators);
ownerPage = new OwnerPage(driver, locators);
findOwnersPage = new FindOwnersPage(driver, locators);
}
public void navigateToAddOwner() {
findOwnersPage.navigateToFindOwnersPage();
findOwnersPage.clickOnAddOwnerButton();
}
public void addOrEditAnOwner(@NotNull String action, String firstName, String lastName, String address, String city,
String telephone) {
String firstNameText = input.getProperty(firstName);
String lastNameText = input.getProperty(lastName);
String addressText = input.getProperty(address);
String cityText = input.getProperty(city);
String telephoneText = input.getProperty(telephone);
addOwnerPage.setTextInFields(firstNameText, lastNameText, addressText, cityText, telephoneText);
if (action.equalsIgnoreCase("add")) {
addOwnerPage.clickingOnAddOwnerButton();
}
else if (action.equalsIgnoreCase("update")) {
addOwnerPage.clickOnUpdateOwnerButton();
}
}
@Test
@Description("Validate successfully adding an owner")
public void testAddingAnOwner() {
navigateToAddOwner();
addOrEditAnOwner("add", "firstName", "lastName", "address", "city", "telephone");
assertTrue(ownerPage.isSuccessMessageDisplayed());
assertTrue(ownerPage.isLastNameDisplayed(input.getProperty("lastName")));
}
@Test(priority = 1)
@Description("Validate adding an owner without filling any of the fields")
public void testEmptyFields() {
navigateToAddOwner();
addOwnerPage.clickingOnAddOwnerButton();
String expectedErrorMessage = tap.getProperty("errorMessage");
assertTrue(addOwnerPage.isErrorMessageDisplayedForEmptyFields(expectedErrorMessage));
}
// User is still created - REPORT DEFECT!!!
@Test(priority = 2)
@Description("Validate if an owner is added after putting numbers in the name fields")
public void testNumbersInNameFields() {
navigateToAddOwner();
addOrEditAnOwner("add", "numbersInFirstName", "numbersInLastName", "address", "city", "telephone");
assertFalse("Message should not be visible", ownerPage.isSuccessMessageDisplayed());
}
// You can add the same owner twice - REPORT DEFECT!!!
@Test(priority = 3)
@Description("Validate if you can add the same owner twice")
public void testCreateSameOwnerTwice() {
navigateToAddOwner();
addOrEditAnOwner("add", "firstName2", "lastName2", "address2", "city2", "telephone2");
driver.navigate().back();
addOwnerPage.clickingOnAddOwnerButton();
assertFalse("Message should not be visible", ownerPage.isSuccessMessageDisplayed());
}
@Test(priority = 4)
@Description("Validate if an owner is added after putting text in the 'Telephone' field")
public void testTextInTelephoneField() {
navigateToAddOwner();
addOrEditAnOwner("add", "firstName", "lastName", "address", "city", "textInTelephoneField");
String expectedErrorMessage = tap.getProperty("errorMessageTelephoneField");
assertTrue("Error message should be displayed for invalid telephone number",
addOwnerPage.isErrorMessageDisplayedForTextInTelephoneField(expectedErrorMessage));
}
@Test(priority = 5)
@Description("Validate updating an owner")
public void testUpdateOwner() {
findOwnersPage.navigateToFindOwnersPage();
findOwnersPage.clickOnFindOwnerButton();
ListOwnersPage listOwnersPage = new ListOwnersPage(driver, locators);
listOwnersPage.clickOnNameFromTable();
ownerPage.clickOnEditOwnerButton();
addOwnerPage.clearFields();
addOrEditAnOwner("update", "updateFirstName", "updateLastName", "updateAddress", "updateCity",
"updateTelephone");
assertTrue(ownerPage.isUpdateMessageDisplayed());
assertTrue(ownerPage.isLastNameDisplayed(input.getProperty("updateLastName")));
}
// User can still be updated - REPORT DEFECT!!!
@Test(priority = 6)
@Description("Validate updating an owner with the details of an already existing owner")
public void testUpdateOwnerWithExistingDetails() {
findOwnersPage.navigateToFindOwnersPage();
findOwnersPage.clickOnFindOwnerButton();
ListOwnersPage listOwnersPage = new ListOwnersPage(driver, locators);
listOwnersPage.clickOnNameFromTable();
ownerPage.clickOnEditOwnerButton();
addOwnerPage.clearFields();
addOrEditAnOwner("update", "firstName", "lastName", "address", "city", "telephone");
assertFalse("Error message is not displayed", ownerPage.isUpdateMessageDisplayed());
}
@Test(priority = 7)
@Description("Validate if a newly added owner can be updated")
public void testUpdateNewlyAddedOwner() {
navigateToAddOwner();
addOrEditAnOwner("add", "firstName3", "lastName3", "address3", "city3", "telephone3");
ownerPage.clickOnEditOwnerButton();
addOwnerPage.clearFields();
addOrEditAnOwner("update", "updateFirstName2", "updateLastName2", "updateAddress2", "updateCity2",
"updateTelephone2");
assertTrue(ownerPage.isUpdateMessageDisplayed());
assertTrue(ownerPage.isLastNameDisplayed(input.getProperty("updateLastName2")));
}
}

View file

@ -0,0 +1,141 @@
package selenium.scenarios;
import jdk.jfr.Description;
import org.jetbrains.annotations.NotNull;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
import selenium.TestBase;
import selenium.pages.*;
import static org.testng.AssertJUnit.*;
public class TS03AddPetTest extends TestBase {
private AddOwnerPage addOwnerPage;
private OwnerPage ownerPage;
private FindOwnersPage findOwnersPage;
private AddPetPage addPetPage;
@BeforeMethod
public void setObjects() {
addOwnerPage = new AddOwnerPage(driver, locators);
ownerPage = new OwnerPage(driver, locators);
findOwnersPage = new FindOwnersPage(driver, locators);
addPetPage = new AddPetPage(driver, locators);
}
public void addOrEditPet(@NotNull String action, String petName, String birthDate, String petType) {
String petNameText = input.getProperty(petName);
String petBirthDateText = input.getProperty(birthDate);
String petTypeOption = input.getProperty(petType);
addPetPage.fillTheFields(petNameText, petBirthDateText, petTypeOption);
if (action.equalsIgnoreCase("add")) {
addPetPage.clickOnAddPetButton();
}
else if (action.equalsIgnoreCase("update")) {
addPetPage.clickOnUpdatePetButton();
}
}
public void navigateToAddPetForExistingOwner() {
findOwnersPage.navigateToFindOwnersPage();
findOwnersPage.clickOnFindOwnerButton();
ListOwnersPage listOwnersPage = new ListOwnersPage(driver, locators);
listOwnersPage.clickOnNameFromTable();
ownerPage.clickOnAddNewPetButton();
}
@Test
@Description("Validate adding a pet to a newly added owner")
public void testAddPetToNewlyAddedOwner() {
findOwnersPage.navigateToFindOwnersPage();
findOwnersPage.clickOnAddOwnerButton();
String firstName = input.getProperty("firstName");
String lastName = input.getProperty("lastName");
String address = input.getProperty("address");
String city = input.getProperty("city");
String telephone = input.getProperty("telephone");
addOwnerPage.setTextInFields(firstName, lastName, address, city, telephone);
addOwnerPage.clickingOnAddOwnerButton();
ownerPage.clickOnAddNewPetButton();
addOrEditPet("add", "petName", "birthDate", "petType");
assertTrue(ownerPage.isPetAddedSuccessMessageDisplayed());
assertTrue(ownerPage.isPetNameDisplayed("petName"));
}
@Test(priority = 1)
@Description("Validate adding a new pet to an already existing owner")
public void testAddPetToExistingOwner() {
navigateToAddPetForExistingOwner();
addOrEditPet("add", "petName2", "birthDate2", "petType2");
assertTrue(ownerPage.isPetAddedSuccessMessageDisplayed());
assertTrue(ownerPage.isPetNameDisplayed("petName2"));
}
@Test(priority = 2)
@Description("Validate adding the same pet twice")
public void testAddingSamePetTwice() {
navigateToAddPetForExistingOwner();
addOrEditPet("add", "petName3", "birthDate3", "petType3");
driver.navigate().back();
addPetPage.clickOnAddPetButton();
assertTrue(addPetPage.isErrorMessageDisplayedForSamePetName());
}
@Test(priority = 3)
@Description("Validate adding a pet without filling any of the fields")
public void testAddPetWithEmptyFields() {
navigateToAddPetForExistingOwner();
addPetPage.clickOnAddPetButton();
String expectedErrorMessage = tap.getProperty("emptyPetFieldsErrorMessage");
assertTrue(addPetPage.isErrorMessageDisplayedForEmptyFields(expectedErrorMessage));
}
@Test(priority = 4)
@Description("Validate adding a pet with a future birth date")
public void testAddPetWithFutureBirthDate() {
navigateToAddPetForExistingOwner();
addOrEditPet("add", "petName4", "futureBirthDate", "petType4");
assertTrue(addPetPage.isInvalidDateErrorMessageDisplayed());
}
// Pet is still added after putting numbers in 'Name' field - REPORT DEFECT!!!
@Test(priority = 5)
@Description("Validate adding numbers in the 'Name' field")
public void testAddNumbersInNameField() {
navigateToAddPetForExistingOwner();
addOrEditPet("add", "numberPetName", "birthDate5", "petType5");
assertFalse(ownerPage.isPetAddedSuccessMessageDisplayed());
}
@Test(priority = 6)
@Description("Validate updating a pet")
public void testUpdatePet() {
findOwnersPage.navigateToFindOwnersPage();
findOwnersPage.clickOnFindOwnerButton();
ListOwnersPage listOwnersPage = new ListOwnersPage(driver, locators);
listOwnersPage.clickOnNameFromTable();
ownerPage.clickOnEditPetButton();
addPetPage.clearFields();
addOrEditPet("update", "petName", "birthDate", "petType");
assertTrue(ownerPage.isUpdatePetMessageDisplayed());
assertTrue(ownerPage.isPetNameDisplayed("petName"));
}
}

View file

@ -0,0 +1,76 @@
package selenium.scenarios;
import jdk.jfr.Description;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
import selenium.TestBase;
import selenium.pages.*;
import static org.testng.AssertJUnit.assertTrue;
public class TS04AddVisitTest extends TestBase {
private OwnerPage ownerPage;
private FindOwnersPage findOwnersPage;
private AddVisitPage addVisitPage;
@BeforeMethod
public void setObjects() {
ownerPage = new OwnerPage(driver, locators);
findOwnersPage = new FindOwnersPage(driver, locators);
addVisitPage = new AddVisitPage(driver, locators);
}
public void addVisit(String date, String description) {
String dateText = input.getProperty(date);
String descriptionText = input.getProperty(description);
addVisitPage.fillTheFields(dateText, descriptionText);
addVisitPage.clickOnAddVisitButton();
}
public void navigateToVisitPage() {
findOwnersPage.navigateToFindOwnersPage();
findOwnersPage.clickOnFindOwnerButton();
findOwnersPage.navigateToFindOwnersPage();
findOwnersPage.clickOnFindOwnerButton();
ListOwnersPage listOwnersPage = new ListOwnersPage(driver, locators);
listOwnersPage.clickOnNameFromTable();
ownerPage.clickOnAddVisitButton();
}
// Spelling mistake in success message - Report
@Test
@Description("Validate adding a visit for a pet")
public void testAddVisitForPet() {
navigateToVisitPage();
addVisit("date", "description");
assertTrue(ownerPage.isVisitAddedMessageDisplayed());
assertTrue(ownerPage.isVisitAdded("description"));
}
@Test(priority = 1)
@Description("Validate adding a visit without filling any of the fields")
public void testVisitEmptyFields() {
navigateToVisitPage();
addVisitPage.clickOnAddVisitButton();
String expectedErrorMessage = tap.getProperty("emptyFieldInAddVisit");
assertTrue(addVisitPage.isErrorMessageDisplayedForEmptyField(expectedErrorMessage));
}
@Test(priority = 2)
@Description("Validate adding a visit with an invalid date")
public void testInvalidDate() {
navigateToVisitPage();
addVisit("invalidDate", "description");
String expectedErrorMessage = tap.getProperty("invalidDateInAddVisit");
assertTrue(addVisitPage.isErrorMessageDisplayedForInvalidDate(expectedErrorMessage));
}
}

View file

@ -0,0 +1,47 @@
package selenium.scenarios;
import org.springframework.context.annotation.Description;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
import selenium.TestBase;
import selenium.pages.FindOwnersPage;
import selenium.pages.HomePage;
import static org.testng.AssertJUnit.assertTrue;
public class TS05HomePageTest extends TestBase {
private HomePage homePage;
private FindOwnersPage findOwnersPage;
@BeforeMethod
public void setObjects() {
homePage = new HomePage(driver, locators);
findOwnersPage = new FindOwnersPage(driver, locators);
}
public void checkForCorrectWelcomePhoto() {
String expectedPhotoSrc = tap.getProperty("welcomePhoto");
assertTrue(homePage.isWelcomePhotoVisible(expectedPhotoSrc));
}
@Test
@Description("Validate if you can navigate to home page by clicking on the 'Home' header")
public void testNavigateHomeFromHeader() {
findOwnersPage.navigateToFindOwnersPage();
homePage.clickOnHomePageLink();
checkForCorrectWelcomePhoto();
}
@Test(priority = 1)
@Description("Validate if you can navigate to home by page by clicking on the logo of the application")
public void navigateHomeFromLogo() {
findOwnersPage.navigateToFindOwnersPage();
homePage.clickOnLogoLink();
checkForCorrectWelcomePhoto();
}
}

9
testng.xml Normal file
View file

@ -0,0 +1,9 @@
<!DOCTYPE suite SYSTEM "https://testng.org/testng-1.0.dtd" >
<suite name="SpringPetClinic">
<test name="SpringPetClinicTest">
<packages>
<package name="selenium.scenarios"/>
</packages>
</test>
</suite>