Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implemented selenium automation tests for all functionalities #1533

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 32 additions & 3 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,35 @@
<artifactId>jakarta.xml.bind-api</artifactId>
</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>

<build>
Expand Down Expand Up @@ -220,7 +249,7 @@
<artifactId>spring-boot-maven-plugin</artifactId>
<executions>
<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 -->
<goals>
<goal>build-info</goal>
Expand Down Expand Up @@ -378,7 +407,7 @@
<build>
<pluginManagement>
<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. -->
<plugin>
<groupId>org.eclipse.m2e</groupId>
Expand Down Expand Up @@ -436,4 +465,4 @@
</profile>
</profiles>

</project>
</project>
98 changes: 98 additions & 0 deletions src/test/java/selenium/TestBase.java
Original file line number Diff line number Diff line change
@@ -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 changes: 2 additions & 0 deletions src/test/java/selenium/config/config.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
browser=chrome
testUrl=http://localhost:8080/
64 changes: 64 additions & 0 deletions src/test/java/selenium/config/input.properties
Original file line number Diff line number Diff line change
@@ -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 changes: 36 additions & 0 deletions src/test/java/selenium/config/locators.properties
Original file line number Diff line number Diff line change
@@ -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 changes: 14 additions & 0 deletions src/test/java/selenium/config/textsAndPhotos.properties
Original file line number Diff line number Diff line change
@@ -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 changes: 75 additions & 0 deletions src/test/java/selenium/pages/AddOwnerPage.java
Original file line number Diff line number Diff line change
@@ -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();
}

}
Loading