-
Notifications
You must be signed in to change notification settings - Fork 24.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implemented selenium automation tests for all functionalities
- Loading branch information
1 parent
5167226
commit c8386f6
Showing
19 changed files
with
1,302 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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(); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
browser=chrome | ||
testUrl=http://localhost:8080/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
|
||
} |
Oops, something went wrong.