diff --git a/pom.xml b/pom.xml index 3739fb635c5..1b8ae66f48c 100644 --- a/pom.xml +++ b/pom.xml @@ -146,14 +146,6 @@ 4.20.0 - - - org.testng - testng - 7.9.0 - test - - org.uncommons diff --git a/src/test/java/selenium/TestBase.java b/src/test/java/selenium/TestBase.java index 214eca7203c..c977fa359e0 100644 --- a/src/test/java/selenium/TestBase.java +++ b/src/test/java/selenium/TestBase.java @@ -1,5 +1,7 @@ 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; @@ -9,9 +11,6 @@ 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; @@ -37,7 +36,7 @@ public class TestBase { public static FileReader frInput; - @BeforeMethod + @Before public void setUp() throws IOException { String userDirectory = System.getProperty("user.dir"); String basePath = "\\src\\test\\java\\selenium\\config\\"; @@ -86,12 +85,11 @@ public void setUp() throws IOException { WebElement welcomePhoto = driver.findElement(By.className(locators.getProperty("welcomePhoto"))); String ActualWelcomePhotoSrc = welcomePhoto.getAttribute("src"); String expectedWelcomePhoto = tap.getProperty("welcomePhoto"); - Assert.assertEquals(ActualWelcomePhotoSrc, expectedWelcomePhoto); + org.junit.Assert.assertEquals(ActualWelcomePhotoSrc, expectedWelcomePhoto); } - @AfterMethod + @After public void tearDown() { driver.quit(); } - } diff --git a/src/test/java/selenium/pages/ListOwnersPage.java b/src/test/java/selenium/pages/ListOwnersPage.java index 272b2ace789..19941ddf21e 100644 --- a/src/test/java/selenium/pages/ListOwnersPage.java +++ b/src/test/java/selenium/pages/ListOwnersPage.java @@ -10,9 +10,10 @@ 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; -import static org.testng.Assert.assertEquals; -import static org.testng.Assert.assertTrue; + public class ListOwnersPage extends TestBase { @@ -35,15 +36,15 @@ public void tableAppearance() { 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"); + 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() { - WebElement firstRow = rows.get(1); + public void clickOnNameFromTable(int row) { + WebElement firstRow = rows.get(row); List name = firstRow.findElements(By.tagName("td")); WebElement firstName = name.get(0); String firstNameText = firstName.getText(); diff --git a/src/test/java/selenium/scenarios/TS02AddOwnerTest.java b/src/test/java/selenium/scenarios/AddOwnerTest.java similarity index 73% rename from src/test/java/selenium/scenarios/TS02AddOwnerTest.java rename to src/test/java/selenium/scenarios/AddOwnerTest.java index df910859578..8f475e9d522 100644 --- a/src/test/java/selenium/scenarios/TS02AddOwnerTest.java +++ b/src/test/java/selenium/scenarios/AddOwnerTest.java @@ -1,26 +1,22 @@ package selenium.scenarios; -import jdk.jfr.Description; -import org.jetbrains.annotations.NotNull; -import org.testng.annotations.BeforeMethod; -import org.testng.annotations.Test; +import org.junit.Before; +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.testng.AssertJUnit.*; +import static org.junit.Assert.*; -public class TS02AddOwnerTest extends TestBase { +public class AddOwnerTest extends TestBase { private AddOwnerPage addOwnerPage; - private OwnerPage ownerPage; - private FindOwnersPage findOwnersPage; - @BeforeMethod + @Before public void setObjects() { addOwnerPage = new AddOwnerPage(driver, locators); ownerPage = new OwnerPage(driver, locators); @@ -32,8 +28,8 @@ public void navigateToAddOwner() { findOwnersPage.clickOnAddOwnerButton(); } - public void addOrEditAnOwner(@NotNull String action, String firstName, String lastName, String address, String city, - String telephone) { + 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); @@ -43,14 +39,12 @@ public void addOrEditAnOwner(@NotNull String action, String firstName, String la addOwnerPage.setTextInFields(firstNameText, lastNameText, addressText, cityText, telephoneText); if (action.equalsIgnoreCase("add")) { addOwnerPage.clickingOnAddOwnerButton(); - } - else if (action.equalsIgnoreCase("update")) { + } 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"); @@ -59,8 +53,7 @@ public void testAddingAnOwner() { assertTrue(ownerPage.isLastNameDisplayed(input.getProperty("lastName"))); } - @Test(priority = 1) - @Description("Validate adding an owner without filling any of the fields") + @Test public void testEmptyFields() { navigateToAddOwner(); addOwnerPage.clickingOnAddOwnerButton(); @@ -69,9 +62,8 @@ public void testEmptyFields() { 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") + // User is still created after putting numbers in the name fields - REPORT DEFECT!!! + @Test public void testNumbersInNameFields() { navigateToAddOwner(); @@ -81,8 +73,7 @@ public void testNumbersInNameFields() { } // You can add the same owner twice - REPORT DEFECT!!! - @Test(priority = 3) - @Description("Validate if you can add the same owner twice") + @Test public void testCreateSameOwnerTwice() { navigateToAddOwner(); @@ -93,8 +84,7 @@ public void testCreateSameOwnerTwice() { 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") + @Test public void testTextInTelephoneField() { navigateToAddOwner(); @@ -102,37 +92,35 @@ public void testTextInTelephoneField() { String expectedErrorMessage = tap.getProperty("errorMessageTelephoneField"); assertTrue("Error message should be displayed for invalid telephone number", - addOwnerPage.isErrorMessageDisplayedForTextInTelephoneField(expectedErrorMessage)); + addOwnerPage.isErrorMessageDisplayedForTextInTelephoneField(expectedErrorMessage)); } - @Test(priority = 5) - @Description("Validate updating an owner") + @Test public void testUpdateOwner() { findOwnersPage.navigateToFindOwnersPage(); findOwnersPage.clickOnFindOwnerButton(); ListOwnersPage listOwnersPage = new ListOwnersPage(driver, locators); - listOwnersPage.clickOnNameFromTable(); + listOwnersPage.clickOnNameFromTable(2); ownerPage.clickOnEditOwnerButton(); addOwnerPage.clearFields(); addOrEditAnOwner("update", "updateFirstName", "updateLastName", "updateAddress", "updateCity", - "updateTelephone"); + "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() { + @Test + public void testUpdateOwnerWithSameDetailsFromOtherOwner() { findOwnersPage.navigateToFindOwnersPage(); findOwnersPage.clickOnFindOwnerButton(); ListOwnersPage listOwnersPage = new ListOwnersPage(driver, locators); - listOwnersPage.clickOnNameFromTable(); + listOwnersPage.clickOnNameFromTable(3); ownerPage.clickOnEditOwnerButton(); addOwnerPage.clearFields(); @@ -142,8 +130,7 @@ public void testUpdateOwnerWithExistingDetails() { assertFalse("Error message is not displayed", ownerPage.isUpdateMessageDisplayed()); } - @Test(priority = 7) - @Description("Validate if a newly added owner can be updated") + @Test public void testUpdateNewlyAddedOwner() { navigateToAddOwner(); addOrEditAnOwner("add", "firstName3", "lastName3", "address3", "city3", "telephone3"); @@ -152,10 +139,9 @@ public void testUpdateNewlyAddedOwner() { addOwnerPage.clearFields(); addOrEditAnOwner("update", "updateFirstName2", "updateLastName2", "updateAddress2", "updateCity2", - "updateTelephone2"); + "updateTelephone2"); assertTrue(ownerPage.isUpdateMessageDisplayed()); assertTrue(ownerPage.isLastNameDisplayed(input.getProperty("updateLastName2"))); } - } diff --git a/src/test/java/selenium/scenarios/TS03AddPetTest.java b/src/test/java/selenium/scenarios/AddPetTest.java similarity index 72% rename from src/test/java/selenium/scenarios/TS03AddPetTest.java rename to src/test/java/selenium/scenarios/AddPetTest.java index 977ee46ddd2..628b4a38f3d 100644 --- a/src/test/java/selenium/scenarios/TS03AddPetTest.java +++ b/src/test/java/selenium/scenarios/AddPetTest.java @@ -1,25 +1,20 @@ package selenium.scenarios; -import jdk.jfr.Description; -import org.jetbrains.annotations.NotNull; -import org.testng.annotations.BeforeMethod; -import org.testng.annotations.Test; +import org.junit.Before; +import org.junit.Test; import selenium.TestBase; import selenium.pages.*; -import static org.testng.AssertJUnit.*; +import static org.junit.Assert.*; -public class TS03AddPetTest extends TestBase { +public class AddPetTest extends TestBase { private AddOwnerPage addOwnerPage; - private OwnerPage ownerPage; - private FindOwnersPage findOwnersPage; - private AddPetPage addPetPage; - @BeforeMethod + @Before public void setObjects() { addOwnerPage = new AddOwnerPage(driver, locators); ownerPage = new OwnerPage(driver, locators); @@ -27,7 +22,7 @@ public void setObjects() { addPetPage = new AddPetPage(driver, locators); } - public void addOrEditPet(@NotNull String action, String petName, String birthDate, String petType) { + 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); @@ -35,23 +30,21 @@ public void addOrEditPet(@NotNull String action, String petName, String birthDat addPetPage.fillTheFields(petNameText, petBirthDateText, petTypeOption); if (action.equalsIgnoreCase("add")) { addPetPage.clickOnAddPetButton(); - } - else if (action.equalsIgnoreCase("update")) { + } else if (action.equalsIgnoreCase("update")) { addPetPage.clickOnUpdatePetButton(); } } - public void navigateToAddPetForExistingOwner() { + public void navigateToAddPetForExistingOwner(int row) { findOwnersPage.navigateToFindOwnersPage(); findOwnersPage.clickOnFindOwnerButton(); ListOwnersPage listOwnersPage = new ListOwnersPage(driver, locators); - listOwnersPage.clickOnNameFromTable(); + listOwnersPage.clickOnNameFromTable(row); ownerPage.clickOnAddNewPetButton(); } @Test - @Description("Validate adding a pet to a newly added owner") public void testAddPetToNewlyAddedOwner() { findOwnersPage.navigateToFindOwnersPage(); findOwnersPage.clickOnAddOwnerButton(); @@ -71,20 +64,18 @@ public void testAddPetToNewlyAddedOwner() { assertTrue(ownerPage.isPetNameDisplayed("petName")); } - @Test(priority = 1) - @Description("Validate adding a new pet to an already existing owner") + @Test public void testAddPetToExistingOwner() { - navigateToAddPetForExistingOwner(); + navigateToAddPetForExistingOwner(4); addOrEditPet("add", "petName2", "birthDate2", "petType2"); assertTrue(ownerPage.isPetAddedSuccessMessageDisplayed()); assertTrue(ownerPage.isPetNameDisplayed("petName2")); } - @Test(priority = 2) - @Description("Validate adding the same pet twice") + @Test public void testAddingSamePetTwice() { - navigateToAddPetForExistingOwner(); + navigateToAddPetForExistingOwner(1); addOrEditPet("add", "petName3", "birthDate3", "petType3"); driver.navigate().back(); @@ -93,43 +84,39 @@ public void testAddingSamePetTwice() { assertTrue(addPetPage.isErrorMessageDisplayedForSamePetName()); } - @Test(priority = 3) - @Description("Validate adding a pet without filling any of the fields") + @Test public void testAddPetWithEmptyFields() { - navigateToAddPetForExistingOwner(); + navigateToAddPetForExistingOwner(1); addPetPage.clickOnAddPetButton(); String expectedErrorMessage = tap.getProperty("emptyPetFieldsErrorMessage"); assertTrue(addPetPage.isErrorMessageDisplayedForEmptyFields(expectedErrorMessage)); } - @Test(priority = 4) - @Description("Validate adding a pet with a future birth date") + @Test public void testAddPetWithFutureBirthDate() { - navigateToAddPetForExistingOwner(); + navigateToAddPetForExistingOwner(1); 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") + @Test public void testAddNumbersInNameField() { - navigateToAddPetForExistingOwner(); + navigateToAddPetForExistingOwner(1); addOrEditPet("add", "numberPetName", "birthDate5", "petType5"); assertFalse(ownerPage.isPetAddedSuccessMessageDisplayed()); } - @Test(priority = 6) - @Description("Validate updating a pet") + @Test public void testUpdatePet() { findOwnersPage.navigateToFindOwnersPage(); findOwnersPage.clickOnFindOwnerButton(); ListOwnersPage listOwnersPage = new ListOwnersPage(driver, locators); - listOwnersPage.clickOnNameFromTable(); + listOwnersPage.clickOnNameFromTable(1); ownerPage.clickOnEditPetButton(); addPetPage.clearFields(); diff --git a/src/test/java/selenium/scenarios/TS04AddVisitTest.java b/src/test/java/selenium/scenarios/AddVisitTest.java similarity index 76% rename from src/test/java/selenium/scenarios/TS04AddVisitTest.java rename to src/test/java/selenium/scenarios/AddVisitTest.java index a52d480d45f..c175caf5f37 100644 --- a/src/test/java/selenium/scenarios/TS04AddVisitTest.java +++ b/src/test/java/selenium/scenarios/AddVisitTest.java @@ -1,22 +1,19 @@ package selenium.scenarios; -import jdk.jfr.Description; -import org.testng.annotations.BeforeMethod; -import org.testng.annotations.Test; +import org.junit.Before; +import org.junit.Test; import selenium.TestBase; import selenium.pages.*; -import static org.testng.AssertJUnit.assertTrue; +import static org.junit.Assert.assertTrue; -public class TS04AddVisitTest extends TestBase { +public class AddVisitTest extends TestBase { private OwnerPage ownerPage; - private FindOwnersPage findOwnersPage; - private AddVisitPage addVisitPage; - @BeforeMethod + @Before public void setObjects() { ownerPage = new OwnerPage(driver, locators); findOwnersPage = new FindOwnersPage(driver, locators); @@ -38,13 +35,11 @@ public void navigateToVisitPage() { findOwnersPage.clickOnFindOwnerButton(); ListOwnersPage listOwnersPage = new ListOwnersPage(driver, locators); - listOwnersPage.clickOnNameFromTable(); + listOwnersPage.clickOnNameFromTable(1); ownerPage.clickOnAddVisitButton(); } - // Spelling mistake in success message - Report @Test - @Description("Validate adding a visit for a pet") public void testAddVisitForPet() { navigateToVisitPage(); @@ -53,8 +48,7 @@ public void testAddVisitForPet() { assertTrue(ownerPage.isVisitAdded("description")); } - @Test(priority = 1) - @Description("Validate adding a visit without filling any of the fields") + @Test public void testVisitEmptyFields() { navigateToVisitPage(); @@ -63,8 +57,7 @@ public void testVisitEmptyFields() { assertTrue(addVisitPage.isErrorMessageDisplayedForEmptyField(expectedErrorMessage)); } - @Test(priority = 2) - @Description("Validate adding a visit with an invalid date") + @Test public void testInvalidDate() { navigateToVisitPage(); diff --git a/src/test/java/selenium/scenarios/TS01FindOwnersTest.java b/src/test/java/selenium/scenarios/FindOwnersTest.java similarity index 68% rename from src/test/java/selenium/scenarios/TS01FindOwnersTest.java rename to src/test/java/selenium/scenarios/FindOwnersTest.java index 19080f019ab..90cf88b9332 100644 --- a/src/test/java/selenium/scenarios/TS01FindOwnersTest.java +++ b/src/test/java/selenium/scenarios/FindOwnersTest.java @@ -1,10 +1,9 @@ package selenium.scenarios; -import jdk.jfr.Description; +import org.junit.Before; +import org.junit.Test; 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; @@ -13,16 +12,16 @@ import java.util.List; -import static org.testng.Assert.assertEquals; -import static org.testng.Assert.assertTrue; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; -public class TS01FindOwnersTest extends TestBase { +public class FindOwnersTest extends TestBase { private OwnerPage ownerPage; private FindOwnersPage findOwnersPage; - @BeforeMethod + @Before public void setObjects() { ownerPage = new OwnerPage(driver, locators); findOwnersPage = new FindOwnersPage(driver, locators); @@ -35,46 +34,38 @@ private void setupFindOwnersPage(String lastName) { } @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"); + assertTrue(ownerPage.isLastNameDisplayed(input.getProperty("existingLastName"))); } - @Test(priority = 1) - @Description("Validate if an owner is displayed after searching by an existing first name") + @Test public void testFindOwnerByExistingFirstName() { setupFindOwnersPage(input.getProperty("existingFirstName")); String ownerNotFoundText = findOwnersPage.getOwnerNotFoundText(); String expectedText = tap.getProperty("ownerNotFoundText"); - assertEquals(ownerNotFoundText, expectedText, "Expected text has been displayed"); + assertEquals(expectedText, ownerNotFoundText); } - @Test(priority = 2) - @Description("Validate if an owner is displayed after searching for a non-existing last name") + @Test public void testFindOwnerByNonExistingLastName() { setupFindOwnersPage(input.getProperty("nonExistingLastName")); String ownerNotFoundText = findOwnersPage.getOwnerNotFoundText(); String expectedText = tap.getProperty("ownerNotFoundText"); - assertEquals(ownerNotFoundText, expectedText, "Expected text has been displayed"); + assertEquals(expectedText, ownerNotFoundText); } - @Test(priority = 3) - @Description("Validate case sensitivity after searching by an existing last name") + @Test public void testCaseSensitiveLastName() { setupFindOwnersPage(input.getProperty("caseSensitiveLastName")); - assertTrue(ownerPage.isLastNameDisplayed(input.getProperty("existingLastName")), - "The last name should be displayed on the Owner page"); + assertTrue(ownerPage.isLastNameDisplayed(input.getProperty("existingLastName"))); } - @Test(priority = 4) - @Description("Validate if all owners are displayed after clicking the 'Find Owner' button " - + "without filling the 'Last name' field") + @Test public void testEmptyLastNameField() { setupFindOwnersPage(""); @@ -82,17 +73,15 @@ public void testEmptyLastNameField() { listOwnersPage.tableAppearance(); } - @Test(priority = 5) - @Description("Validate if you can navigate to the Owner page after clicking on a name from the table") + @Test public void testNavigateToOwnerPageFromTable() { setupFindOwnersPage(""); ListOwnersPage listOwnersPage = new ListOwnersPage(driver, locators); - listOwnersPage.clickOnNameFromTable(); + listOwnersPage.clickOnNameFromTable(1); } - @Test(priority = 6) - @Description("Validate finding a newly added owner") + @Test public void testFindNewlyAddedOwner() { findOwnersPage.navigateToFindOwnersPage(); findOwnersPage.clickOnAddOwnerButton(); diff --git a/src/test/java/selenium/scenarios/TS05HomePageTest.java b/src/test/java/selenium/scenarios/HomePageTest.java similarity index 63% rename from src/test/java/selenium/scenarios/TS05HomePageTest.java rename to src/test/java/selenium/scenarios/HomePageTest.java index ab95a19025a..b282699c131 100644 --- a/src/test/java/selenium/scenarios/TS05HomePageTest.java +++ b/src/test/java/selenium/scenarios/HomePageTest.java @@ -1,21 +1,19 @@ package selenium.scenarios; -import org.springframework.context.annotation.Description; -import org.testng.annotations.BeforeMethod; -import org.testng.annotations.Test; +import org.junit.Before; +import org.junit.Test; import selenium.TestBase; import selenium.pages.FindOwnersPage; import selenium.pages.HomePage; -import static org.testng.AssertJUnit.assertTrue; +import static org.junit.Assert.assertTrue; -public class TS05HomePageTest extends TestBase { +public class HomePageTest extends TestBase { private HomePage homePage; - private FindOwnersPage findOwnersPage; - @BeforeMethod + @Before public void setObjects() { homePage = new HomePage(driver, locators); findOwnersPage = new FindOwnersPage(driver, locators); @@ -27,7 +25,6 @@ public void checkForCorrectWelcomePhoto() { } @Test - @Description("Validate if you can navigate to home page by clicking on the 'Home' header") public void testNavigateHomeFromHeader() { findOwnersPage.navigateToFindOwnersPage(); @@ -35,8 +32,7 @@ public void testNavigateHomeFromHeader() { checkForCorrectWelcomePhoto(); } - @Test(priority = 1) - @Description("Validate if you can navigate to home by page by clicking on the logo of the application") + @Test public void navigateHomeFromLogo() { findOwnersPage.navigateToFindOwnersPage(); diff --git a/testng.xml b/testng.xml deleted file mode 100644 index 03cb8aa9cd6..00000000000 --- a/testng.xml +++ /dev/null @@ -1,9 +0,0 @@ - - - - - - - - -