mirror of
https://github.com/spring-projects/spring-petclinic.git
synced 2025-07-20 06:45:50 +00:00
Merge beaee8e390
into dff45cf70c
This commit is contained in:
commit
4160805f76
18 changed files with 1249 additions and 0 deletions
29
pom.xml
29
pom.xml
|
@ -140,6 +140,35 @@
|
||||||
<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.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>
|
||||||
|
|
98
src/test/java/selenium/TestBase.java
Normal file
98
src/test/java/selenium/TestBase.java
Normal file
|
@ -0,0 +1,98 @@
|
||||||
|
package selenium;
|
||||||
|
|
||||||
|
import org.junit.After;
|
||||||
|
import org.junit.Before;
|
||||||
|
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 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;
|
||||||
|
|
||||||
|
@Before
|
||||||
|
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=new", "-disable-gpu", "-window-size=1920,1080", "--lang=en");
|
||||||
|
|
||||||
|
FirefoxOptions firefoxOptions = new FirefoxOptions();
|
||||||
|
firefoxOptions.addArguments("--headless", "-disable-gpu", "-window-size=1920,1080", "--lang=en");
|
||||||
|
|
||||||
|
EdgeOptions edgeOptions = new EdgeOptions();
|
||||||
|
edgeOptions.addArguments("--headless=new", "-disable-gpu", "-window-size=1920,1080", "--lang=en");
|
||||||
|
|
||||||
|
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");
|
||||||
|
org.junit.Assert.assertEquals(ActualWelcomePhotoSrc, expectedWelcomePhoto);
|
||||||
|
}
|
||||||
|
|
||||||
|
@After
|
||||||
|
public void tearDown() {
|
||||||
|
driver.quit();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
2
src/test/java/selenium/config/config.properties
Normal file
2
src/test/java/selenium/config/config.properties
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
browser=chrome
|
||||||
|
testUrl=http://localhost:8080/
|
64
src/test/java/selenium/config/input.properties
Normal file
64
src/test/java/selenium/config/input.properties
Normal 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
|
36
src/test/java/selenium/config/locators.properties
Normal file
36
src/test/java/selenium/config/locators.properties
Normal 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
|
14
src/test/java/selenium/config/textsAndPhotos.properties
Normal file
14
src/test/java/selenium/config/textsAndPhotos.properties
Normal file
|
@ -0,0 +1,14 @@
|
||||||
|
welcomePhoto=http://localhost:8080/resources/images/pets.png
|
||||||
|
ownerNotFoundText=has not been found
|
||||||
|
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
|
75
src/test/java/selenium/pages/AddOwnerPage.java
Normal file
75
src/test/java/selenium/pages/AddOwnerPage.java
Normal 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();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
74
src/test/java/selenium/pages/AddPetPage.java
Normal file
74
src/test/java/selenium/pages/AddPetPage.java
Normal 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();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
50
src/test/java/selenium/pages/AddVisitPage.java
Normal file
50
src/test/java/selenium/pages/AddVisitPage.java
Normal 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);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
60
src/test/java/selenium/pages/FindOwnersPage.java
Normal file
60
src/test/java/selenium/pages/FindOwnersPage.java
Normal 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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
42
src/test/java/selenium/pages/HomePage.java
Normal file
42
src/test/java/selenium/pages/HomePage.java
Normal 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();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
61
src/test/java/selenium/pages/ListOwnersPage.java
Normal file
61
src/test/java/selenium/pages/ListOwnersPage.java
Normal 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.junit.jupiter.api.Assertions.assertEquals;
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||||
|
import static org.openqa.selenium.support.ui.ExpectedConditions.visibilityOf;
|
||||||
|
|
||||||
|
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 = driver.findElement(By.xpath("(//tr)[2]")).getText();
|
||||||
|
String owner2 = driver.findElement(By.xpath("(//tr)[3]")).getText();
|
||||||
|
|
||||||
|
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(int row) {
|
||||||
|
WebElement firstRow = rows.get(row);
|
||||||
|
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();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
123
src/test/java/selenium/pages/OwnerPage.java
Normal file
123
src/test/java/selenium/pages/OwnerPage.java
Normal 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) {
|
||||||
|
List<WebElement> petDetails = driver.findElements(petDetailsClass);
|
||||||
|
List<String> petDetailsText = petDetails.stream().map(WebElement::getText).toList();
|
||||||
|
String expectedPetName = input.getProperty(petName);
|
||||||
|
return petDetailsText.stream().anyMatch(petDetailsItem -> petDetailsItem.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);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
155
src/test/java/selenium/scenarios/AddOwnerTest.java
Normal file
155
src/test/java/selenium/scenarios/AddOwnerTest.java
Normal file
|
@ -0,0 +1,155 @@
|
||||||
|
package selenium.scenarios;
|
||||||
|
|
||||||
|
import org.junit.Before;
|
||||||
|
import org.junit.Ignore;
|
||||||
|
import org.junit.Test;
|
||||||
|
import selenium.TestBase;
|
||||||
|
import selenium.pages.AddOwnerPage;
|
||||||
|
import selenium.pages.FindOwnersPage;
|
||||||
|
import selenium.pages.ListOwnersPage;
|
||||||
|
import selenium.pages.OwnerPage;
|
||||||
|
|
||||||
|
import static org.junit.Assert.*;
|
||||||
|
|
||||||
|
public class AddOwnerTest extends TestBase {
|
||||||
|
|
||||||
|
private AddOwnerPage addOwnerPage;
|
||||||
|
|
||||||
|
private OwnerPage ownerPage;
|
||||||
|
|
||||||
|
private FindOwnersPage findOwnersPage;
|
||||||
|
|
||||||
|
@Before
|
||||||
|
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(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
|
||||||
|
public void testAddingAnOwner() {
|
||||||
|
navigateToAddOwner();
|
||||||
|
addOrEditAnOwner("add", "firstName", "lastName", "address", "city", "telephone");
|
||||||
|
|
||||||
|
assertTrue(ownerPage.isSuccessMessageDisplayed());
|
||||||
|
assertTrue(ownerPage.isLastNameDisplayed(input.getProperty("lastName")));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testEmptyFields() {
|
||||||
|
navigateToAddOwner();
|
||||||
|
addOwnerPage.clickingOnAddOwnerButton();
|
||||||
|
|
||||||
|
String expectedErrorMessage = tap.getProperty("errorMessage");
|
||||||
|
assertTrue(addOwnerPage.isErrorMessageDisplayedForEmptyFields(expectedErrorMessage));
|
||||||
|
}
|
||||||
|
|
||||||
|
// User is still created after putting numbers in the name fields - REPORT DEFECT!!!
|
||||||
|
@Test
|
||||||
|
@Ignore("Disabled due to defect")
|
||||||
|
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
|
||||||
|
@Ignore("Disabled due to defect")
|
||||||
|
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
|
||||||
|
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
|
||||||
|
public void testUpdateOwner() {
|
||||||
|
findOwnersPage.navigateToFindOwnersPage();
|
||||||
|
findOwnersPage.clickOnFindOwnerButton();
|
||||||
|
|
||||||
|
ListOwnersPage listOwnersPage = new ListOwnersPage(driver, locators);
|
||||||
|
listOwnersPage.clickOnNameFromTable(2);
|
||||||
|
|
||||||
|
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
|
||||||
|
@Ignore("Disabled due to defect")
|
||||||
|
public void testUpdateOwnerWithSameDetailsFromOtherOwner() {
|
||||||
|
findOwnersPage.navigateToFindOwnersPage();
|
||||||
|
findOwnersPage.clickOnFindOwnerButton();
|
||||||
|
|
||||||
|
ListOwnersPage listOwnersPage = new ListOwnersPage(driver, locators);
|
||||||
|
listOwnersPage.clickOnNameFromTable(3);
|
||||||
|
|
||||||
|
ownerPage.clickOnEditOwnerButton();
|
||||||
|
addOwnerPage.clearFields();
|
||||||
|
|
||||||
|
addOrEditAnOwner("update", "firstName", "lastName", "address", "city", "telephone");
|
||||||
|
|
||||||
|
assertFalse("Error message is not displayed", ownerPage.isUpdateMessageDisplayed());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
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")));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
134
src/test/java/selenium/scenarios/AddPetTest.java
Normal file
134
src/test/java/selenium/scenarios/AddPetTest.java
Normal file
|
@ -0,0 +1,134 @@
|
||||||
|
package selenium.scenarios;
|
||||||
|
|
||||||
|
import org.junit.Before;
|
||||||
|
import org.junit.Ignore;
|
||||||
|
import org.junit.Test;
|
||||||
|
import selenium.TestBase;
|
||||||
|
import selenium.pages.*;
|
||||||
|
|
||||||
|
import static org.junit.Assert.*;
|
||||||
|
|
||||||
|
public class AddPetTest extends TestBase {
|
||||||
|
|
||||||
|
private AddOwnerPage addOwnerPage;
|
||||||
|
|
||||||
|
private OwnerPage ownerPage;
|
||||||
|
|
||||||
|
private FindOwnersPage findOwnersPage;
|
||||||
|
|
||||||
|
private AddPetPage addPetPage;
|
||||||
|
|
||||||
|
@Before
|
||||||
|
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(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(int row) {
|
||||||
|
findOwnersPage.navigateToFindOwnersPage();
|
||||||
|
findOwnersPage.clickOnFindOwnerButton();
|
||||||
|
|
||||||
|
ListOwnersPage listOwnersPage = new ListOwnersPage(driver, locators);
|
||||||
|
listOwnersPage.clickOnNameFromTable(row);
|
||||||
|
ownerPage.clickOnAddNewPetButton();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
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
|
||||||
|
public void testAddPetToExistingOwner() {
|
||||||
|
navigateToAddPetForExistingOwner(4);
|
||||||
|
|
||||||
|
addOrEditPet("add", "petName2", "birthDate2", "petType2");
|
||||||
|
assertTrue(ownerPage.isPetAddedSuccessMessageDisplayed());
|
||||||
|
assertTrue(ownerPage.isPetNameDisplayed("petName2"));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testAddingSamePetTwice() {
|
||||||
|
navigateToAddPetForExistingOwner(1);
|
||||||
|
|
||||||
|
addOrEditPet("add", "petName3", "birthDate3", "petType3");
|
||||||
|
driver.navigate().back();
|
||||||
|
addPetPage.clickOnAddPetButton();
|
||||||
|
|
||||||
|
assertTrue(addPetPage.isErrorMessageDisplayedForSamePetName());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testAddPetWithEmptyFields() {
|
||||||
|
navigateToAddPetForExistingOwner(1);
|
||||||
|
|
||||||
|
addPetPage.clickOnAddPetButton();
|
||||||
|
String expectedErrorMessage = tap.getProperty("emptyPetFieldsErrorMessage");
|
||||||
|
assertTrue(addPetPage.isErrorMessageDisplayedForEmptyFields(expectedErrorMessage));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testAddPetWithFutureBirthDate() {
|
||||||
|
navigateToAddPetForExistingOwner(1);
|
||||||
|
|
||||||
|
addOrEditPet("add", "petName4", "futureBirthDate", "petType4");
|
||||||
|
assertTrue(addPetPage.isInvalidDateErrorMessageDisplayed());
|
||||||
|
}
|
||||||
|
|
||||||
|
// Pet is still added after putting numbers in 'Name' field - REPORT DEFECT!!!
|
||||||
|
@Test
|
||||||
|
@Ignore("Disabled due to defect")
|
||||||
|
public void testAddNumbersInNameField() {
|
||||||
|
navigateToAddPetForExistingOwner(1);
|
||||||
|
|
||||||
|
addOrEditPet("add", "numberPetName", "birthDate5", "petType5");
|
||||||
|
assertFalse(ownerPage.isPetAddedSuccessMessageDisplayed());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testUpdatePet() {
|
||||||
|
findOwnersPage.navigateToFindOwnersPage();
|
||||||
|
findOwnersPage.clickOnFindOwnerButton();
|
||||||
|
|
||||||
|
ListOwnersPage listOwnersPage = new ListOwnersPage(driver, locators);
|
||||||
|
listOwnersPage.clickOnNameFromTable(1);
|
||||||
|
ownerPage.clickOnEditPetButton();
|
||||||
|
addPetPage.clearFields();
|
||||||
|
|
||||||
|
addOrEditPet("update", "petName", "birthDate", "petType");
|
||||||
|
assertTrue(ownerPage.isUpdatePetMessageDisplayed());
|
||||||
|
assertTrue(ownerPage.isPetNameDisplayed("petName"));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
71
src/test/java/selenium/scenarios/AddVisitTest.java
Normal file
71
src/test/java/selenium/scenarios/AddVisitTest.java
Normal file
|
@ -0,0 +1,71 @@
|
||||||
|
package selenium.scenarios;
|
||||||
|
|
||||||
|
import org.junit.Before;
|
||||||
|
import org.junit.Test;
|
||||||
|
import selenium.TestBase;
|
||||||
|
import selenium.pages.*;
|
||||||
|
|
||||||
|
import static org.junit.Assert.assertTrue;
|
||||||
|
|
||||||
|
public class AddVisitTest extends TestBase {
|
||||||
|
|
||||||
|
private OwnerPage ownerPage;
|
||||||
|
|
||||||
|
private FindOwnersPage findOwnersPage;
|
||||||
|
|
||||||
|
private AddVisitPage addVisitPage;
|
||||||
|
|
||||||
|
@Before
|
||||||
|
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(1);
|
||||||
|
ownerPage.clickOnAddVisitButton();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testAddVisitForPet() {
|
||||||
|
navigateToVisitPage();
|
||||||
|
|
||||||
|
addVisit("date", "description");
|
||||||
|
assertTrue(ownerPage.isVisitAddedMessageDisplayed());
|
||||||
|
assertTrue(ownerPage.isVisitAdded("description"));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testVisitEmptyFields() {
|
||||||
|
navigateToVisitPage();
|
||||||
|
|
||||||
|
addVisitPage.clickOnAddVisitButton();
|
||||||
|
String expectedErrorMessage = tap.getProperty("emptyFieldInAddVisit");
|
||||||
|
assertTrue(addVisitPage.isErrorMessageDisplayedForEmptyField(expectedErrorMessage));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testInvalidDate() {
|
||||||
|
navigateToVisitPage();
|
||||||
|
|
||||||
|
addVisit("invalidDate", "description");
|
||||||
|
String expectedErrorMessage = tap.getProperty("invalidDateInAddVisit");
|
||||||
|
assertTrue(addVisitPage.isErrorMessageDisplayedForInvalidDate(expectedErrorMessage));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
117
src/test/java/selenium/scenarios/FindOwnersTest.java
Normal file
117
src/test/java/selenium/scenarios/FindOwnersTest.java
Normal file
|
@ -0,0 +1,117 @@
|
||||||
|
package selenium.scenarios;
|
||||||
|
|
||||||
|
import org.junit.Before;
|
||||||
|
import org.junit.Test;
|
||||||
|
import org.openqa.selenium.By;
|
||||||
|
import org.openqa.selenium.WebElement;
|
||||||
|
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.junit.Assert.assertEquals;
|
||||||
|
import static org.junit.Assert.assertTrue;
|
||||||
|
|
||||||
|
public class FindOwnersTest extends TestBase {
|
||||||
|
|
||||||
|
private OwnerPage ownerPage;
|
||||||
|
|
||||||
|
private FindOwnersPage findOwnersPage;
|
||||||
|
|
||||||
|
@Before
|
||||||
|
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
|
||||||
|
public void testFindOwnerByExistingLastName() {
|
||||||
|
setupFindOwnersPage(input.getProperty("existingLastName"));
|
||||||
|
|
||||||
|
assertTrue(ownerPage.isLastNameDisplayed(input.getProperty("existingLastName")));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testFindOwnerByExistingFirstName() {
|
||||||
|
setupFindOwnersPage(input.getProperty("existingFirstName"));
|
||||||
|
|
||||||
|
String ownerNotFoundText = findOwnersPage.getOwnerNotFoundText();
|
||||||
|
String expectedText = tap.getProperty("ownerNotFoundText");
|
||||||
|
assertEquals(expectedText, ownerNotFoundText);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testFindOwnerByNonExistingLastName() {
|
||||||
|
setupFindOwnersPage(input.getProperty("nonExistingLastName"));
|
||||||
|
|
||||||
|
String ownerNotFoundText = findOwnersPage.getOwnerNotFoundText();
|
||||||
|
String expectedText = tap.getProperty("ownerNotFoundText");
|
||||||
|
assertEquals(expectedText, ownerNotFoundText);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testCaseSensitiveLastName() {
|
||||||
|
setupFindOwnersPage(input.getProperty("caseSensitiveLastName"));
|
||||||
|
|
||||||
|
assertTrue(ownerPage.isLastNameDisplayed(input.getProperty("existingLastName")));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testEmptyLastNameField() {
|
||||||
|
setupFindOwnersPage("");
|
||||||
|
|
||||||
|
ListOwnersPage listOwnersPage = new ListOwnersPage(driver, locators);
|
||||||
|
listOwnersPage.tableAppearance();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testNavigateToOwnerPageFromTable() {
|
||||||
|
setupFindOwnersPage("");
|
||||||
|
|
||||||
|
ListOwnersPage listOwnersPage = new ListOwnersPage(driver, locators);
|
||||||
|
listOwnersPage.clickOnNameFromTable(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
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));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
44
src/test/java/selenium/scenarios/HomePageTest.java
Normal file
44
src/test/java/selenium/scenarios/HomePageTest.java
Normal file
|
@ -0,0 +1,44 @@
|
||||||
|
package selenium.scenarios;
|
||||||
|
|
||||||
|
import org.junit.Before;
|
||||||
|
import org.junit.Test;
|
||||||
|
import selenium.TestBase;
|
||||||
|
import selenium.pages.FindOwnersPage;
|
||||||
|
import selenium.pages.HomePage;
|
||||||
|
|
||||||
|
import static org.junit.Assert.assertTrue;
|
||||||
|
|
||||||
|
public class HomePageTest extends TestBase {
|
||||||
|
|
||||||
|
private HomePage homePage;
|
||||||
|
|
||||||
|
private FindOwnersPage findOwnersPage;
|
||||||
|
|
||||||
|
@Before
|
||||||
|
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
|
||||||
|
public void testNavigateHomeFromHeader() {
|
||||||
|
findOwnersPage.navigateToFindOwnersPage();
|
||||||
|
|
||||||
|
homePage.clickOnHomePageLink();
|
||||||
|
checkForCorrectWelcomePhoto();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void navigateHomeFromLogo() {
|
||||||
|
findOwnersPage.navigateToFindOwnersPage();
|
||||||
|
|
||||||
|
homePage.clickOnLogoLink();
|
||||||
|
checkForCorrectWelcomePhoto();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in a new issue