|
| 1 | +package tests.integration; |
| 2 | + |
| 3 | +import aquality.selenium.elements.interfaces.ILabel; |
| 4 | +import org.openqa.selenium.By; |
| 5 | +import org.openqa.selenium.WebElement; |
| 6 | +import org.openqa.selenium.support.locators.RelativeLocator; |
| 7 | +import org.testng.annotations.Test; |
| 8 | +import org.testng.asserts.SoftAssert; |
| 9 | +import tests.BaseTest; |
| 10 | +import theinternet.TheInternetPage; |
| 11 | + |
| 12 | +import static aquality.selenium.locators.RelativeBySupplier.with; |
| 13 | + |
| 14 | +public class LocatorTests extends BaseTest { |
| 15 | + private final String labelLocatorCell = "//td"; |
| 16 | + private final String labelLocatorCellRow5Column5 = "//tr[5]/td[5]"; |
| 17 | + private final String labelLocatorCellRow3Column5 = "//tr[3]/td[5]"; |
| 18 | + private final String nameElementRow3Column5 = "expectedRow3Column5GotWithByXpath"; |
| 19 | + private final String friendlyMessage = "Actual cell text is not equal expected"; |
| 20 | + |
| 21 | + @Test |
| 22 | + public void testAboveLocatorWithDifferentAboveParametersType() { |
| 23 | + navigate(TheInternetPage.CHALLENGING_DOM); |
| 24 | + |
| 25 | + ILabel cellInRow3Column5 = elementFactory.getLabel(By.xpath(labelLocatorCellRow3Column5), "CellInRow4Column5"); |
| 26 | + ILabel cellInRow5Column5 = elementFactory.getLabel(By.xpath(labelLocatorCellRow5Column5), "CellInRow5Column5"); |
| 27 | + |
| 28 | + ILabel actualCellRaw3Column5GotWithByXpath = |
| 29 | + elementFactory.getLabel(with(By.xpath(labelLocatorCell)).above(By.xpath(labelLocatorCellRow5Column5)), |
| 30 | + nameElementRow3Column5); |
| 31 | + |
| 32 | + ILabel actualCellRaw3Column5GotWithWebElement = |
| 33 | + elementFactory.getLabel(with(By.xpath(labelLocatorCell)).above(cellInRow5Column5.getElement()), |
| 34 | + nameElementRow3Column5); |
| 35 | + |
| 36 | + ILabel actualCellRaw3Column5GotWithAqualityElement = |
| 37 | + elementFactory.getLabel(with(By.xpath(labelLocatorCell)).above(cellInRow5Column5), |
| 38 | + nameElementRow3Column5); |
| 39 | + |
| 40 | + WebElement actualWebElementCellRaw3Column5GotBySeleniumRelative = |
| 41 | + getBrowser().getDriver().findElement(RelativeLocator.with(By.xpath(labelLocatorCell)).above(By.xpath(labelLocatorCellRow5Column5))); |
| 42 | + |
| 43 | + checkDifferentTypesWithSoftAssert( |
| 44 | + actualCellRaw3Column5GotWithAqualityElement.getText(), |
| 45 | + actualCellRaw3Column5GotWithWebElement.getText(), |
| 46 | + actualCellRaw3Column5GotWithByXpath.getText(), |
| 47 | + actualWebElementCellRaw3Column5GotBySeleniumRelative.getText(), |
| 48 | + cellInRow3Column5.getText()); |
| 49 | + } |
| 50 | + |
| 51 | + public void checkDifferentTypesWithSoftAssert(String textAquality, String textWebElement, String textByXpath, String textSelenium, String expectedText) { |
| 52 | + SoftAssert softAssert = new SoftAssert(); |
| 53 | + softAssert.assertEquals(textAquality, expectedText, friendlyMessage); |
| 54 | + softAssert.assertEquals(textByXpath, expectedText, friendlyMessage); |
| 55 | + softAssert.assertEquals(textWebElement, expectedText, friendlyMessage); |
| 56 | + softAssert.assertEquals(textSelenium, expectedText, friendlyMessage); |
| 57 | + softAssert.assertAll(); |
| 58 | + } |
| 59 | +} |
0 commit comments