diff --git a/pom.xml b/pom.xml index 28e5708..246c0eb 100644 --- a/pom.xml +++ b/pom.xml @@ -82,7 +82,7 @@ com.github.aquality-automation aquality-selenium-core - 4.5.0 + 4.6.0 org.apache.commons diff --git a/src/main/java/aquality/selenium/browser/devtools/DevToolsHandling.java b/src/main/java/aquality/selenium/browser/devtools/DevToolsHandling.java index b9de2d8..87cc5b3 100644 --- a/src/main/java/aquality/selenium/browser/devtools/DevToolsHandling.java +++ b/src/main/java/aquality/selenium/browser/devtools/DevToolsHandling.java @@ -9,8 +9,8 @@ import org.openqa.selenium.devtools.DevTools; import org.openqa.selenium.devtools.Event; import org.openqa.selenium.devtools.HasDevTools; -import org.openqa.selenium.devtools.v85.performance.Performance; -import org.openqa.selenium.devtools.v85.performance.model.Metric; +import org.openqa.selenium.devtools.v137.performance.Performance; +import org.openqa.selenium.devtools.v137.performance.model.Metric; import java.util.List; import java.util.Map; diff --git a/src/main/java/aquality/selenium/browser/devtools/EmulationHandling.java b/src/main/java/aquality/selenium/browser/devtools/EmulationHandling.java index df982cf..93f4982 100644 --- a/src/main/java/aquality/selenium/browser/devtools/EmulationHandling.java +++ b/src/main/java/aquality/selenium/browser/devtools/EmulationHandling.java @@ -2,10 +2,10 @@ import org.apache.commons.lang3.StringUtils; import org.openqa.selenium.devtools.Command; -import org.openqa.selenium.devtools.v85.dom.model.RGBA; -import org.openqa.selenium.devtools.v85.emulation.Emulation; -import org.openqa.selenium.devtools.v85.emulation.model.MediaFeature; -import org.openqa.selenium.devtools.v85.emulation.model.ScreenOrientation; +import org.openqa.selenium.devtools.v137.dom.model.RGBA; +import org.openqa.selenium.devtools.v137.emulation.Emulation; +import org.openqa.selenium.devtools.v137.emulation.model.MediaFeature; +import org.openqa.selenium.devtools.v137.emulation.model.ScreenOrientation; import java.util.Collections; import java.util.List; @@ -45,7 +45,8 @@ public boolean canEmulate() { * @param accuracy Accuracy of the location */ public void setGeolocationOverride(double latitude, double longitude, double accuracy) { - setGeolocationOverride(Optional.of(latitude), Optional.of(longitude), Optional.of(accuracy)); + setGeolocationOverride(Optional.of(latitude), Optional.of(longitude), Optional.of(accuracy), Optional.empty(), + Optional.empty(), Optional.empty(), Optional.empty()); } /** @@ -64,8 +65,10 @@ public void setGeolocationOverride(double latitude, double longitude) { * @param longitude Longitude of location * @param accuracy Accuracy of the location */ - public void setGeolocationOverride(Optional latitude, Optional longitude, Optional accuracy) { - tools.sendCommand(Emulation.setGeolocationOverride(latitude, longitude, accuracy)); + public void setGeolocationOverride(Optional latitude, Optional longitude, Optional accuracy, + Optional altitude, Optional altitudeAccuracy, Optional heading, + Optional speed) { + tools.sendCommand(Emulation.setGeolocationOverride(latitude, longitude, accuracy, altitude, altitudeAccuracy, heading, speed)); } /** @@ -115,7 +118,7 @@ public void setDeviceMetricsOverride(Integer width, Integer height, Number devic screenOrientation = Optional.of(new ScreenOrientation(ScreenOrientation.Type.fromString(screenOrientationType.get()), angle)); } tools.sendCommand(Emulation.setDeviceMetricsOverride(width, height, deviceScaleFactor, mobile, Optional.empty(), Optional.empty(), Optional.empty(), - Optional.empty(), Optional.empty(), Optional.empty(), screenOrientation, Optional.empty())); + Optional.empty(), Optional.empty(), Optional.empty(), screenOrientation, Optional.empty(), Optional.empty(), Optional.empty())); } /** diff --git a/src/main/java/aquality/selenium/browser/devtools/JavaScriptHandling.java b/src/main/java/aquality/selenium/browser/devtools/JavaScriptHandling.java index 64f3354..6e72d15 100644 --- a/src/main/java/aquality/selenium/browser/devtools/JavaScriptHandling.java +++ b/src/main/java/aquality/selenium/browser/devtools/JavaScriptHandling.java @@ -12,9 +12,9 @@ import org.openqa.selenium.devtools.idealized.Javascript; import org.openqa.selenium.devtools.idealized.ScriptId; import org.openqa.selenium.devtools.idealized.target.model.SessionID; -import org.openqa.selenium.devtools.v85.page.Page; -import org.openqa.selenium.devtools.v85.page.model.ScriptIdentifier; -import org.openqa.selenium.devtools.v85.runtime.Runtime; +import org.openqa.selenium.devtools.v137.page.Page; +import org.openqa.selenium.devtools.v137.page.model.ScriptIdentifier; +import org.openqa.selenium.devtools.v137.runtime.Runtime; import org.openqa.selenium.logging.EventType; import org.openqa.selenium.logging.HasLogEvents; import org.openqa.selenium.remote.Augmenter; @@ -55,7 +55,7 @@ public JavaScriptHandling(DevToolsHandling tools) { public void addScriptCallbackBinding(String scriptName) { logger.info("loc.browser.javascript.scriptcallbackbinding.add", scriptName); bindings.add(scriptName); - tools.sendCommand(Runtime.addBinding(scriptName, Optional.empty())); + tools.sendCommand(Runtime.addBinding(scriptName, Optional.empty(), Optional.empty())); } /** diff --git a/src/main/java/aquality/selenium/browser/devtools/NetworkHandling.java b/src/main/java/aquality/selenium/browser/devtools/NetworkHandling.java index 3e62512..4ab8381 100644 --- a/src/main/java/aquality/selenium/browser/devtools/NetworkHandling.java +++ b/src/main/java/aquality/selenium/browser/devtools/NetworkHandling.java @@ -8,7 +8,7 @@ import org.openqa.selenium.UsernameAndPassword; import org.openqa.selenium.devtools.NetworkInterceptor; import org.openqa.selenium.devtools.idealized.Network; -import org.openqa.selenium.devtools.v85.network.model.*; +import org.openqa.selenium.devtools.v137.network.model.*; import org.openqa.selenium.remote.http.*; import java.net.URI; @@ -22,11 +22,11 @@ import static aquality.selenium.browser.AqualityServices.getBrowser; import static aquality.selenium.logging.LocalizedLoggerUtility.logByLevel; -import static org.openqa.selenium.devtools.v85.network.Network.*; +import static org.openqa.selenium.devtools.v137.network.Network.*; /** * DevTools commands for version-independent network interception. - * For more information, see {@link org.openqa.selenium.devtools.v85.network.Network} and {@link Network}. + * For more information, see {@link org.openqa.selenium.devtools.v137.network.Network} and {@link Network}. */ public class NetworkHandling { public static final String LOC_NETWORK_INTERCEPTOR_START = "loc.browser.network.interceptor.start"; @@ -199,7 +199,7 @@ private Consumer getResponseLogger(HttpExchangeLoggingOptions formatHeaders(response.getHeaders())); } if (loggingOptions.getResponseBody().isEnabled()) { - String responseBody = tools.sendCommand(org.openqa.selenium.devtools.v85.network.Network.getResponseBody(requestId)).getBody(); + String responseBody = tools.sendCommand(org.openqa.selenium.devtools.v137.network.Network.getResponseBody(requestId)).getBody(); if (StringUtils.isNotEmpty(responseBody)) { logByLevel(loggingOptions.getResponseBody().getLogLevel(), "loc.browser.network.event.responsereceived.log.body", @@ -323,7 +323,8 @@ public void clearNetworkInterceptor() { */ public void emulateConditions(Boolean offline, Number latency, Number downloadThroughput, Number uploadThroughput) { tools.sendCommand(enable(Optional.empty(), Optional.empty(), Optional.empty())); - tools.sendCommand(emulateNetworkConditions(offline, latency, downloadThroughput, uploadThroughput, Optional.empty())); + tools.sendCommand(emulateNetworkConditions(offline, latency, downloadThroughput, uploadThroughput, Optional.empty(), + Optional.empty(), Optional.empty(), Optional.empty())); } /** @@ -339,6 +340,6 @@ public void emulateConditions(Boolean offline, Number latency, Number downloadTh public void emulateConditions(Boolean offline, Number latency, Number downloadThroughput, Number uploadThroughput, String connectionType) { tools.sendCommand(enable(Optional.empty(), Optional.empty(), Optional.empty())); tools.sendCommand(emulateNetworkConditions(offline, latency, downloadThroughput, uploadThroughput, - Optional.of(ConnectionType.fromString(connectionType)))); + Optional.of(ConnectionType.fromString(connectionType)), Optional.empty(), Optional.empty(), Optional.empty())); } } diff --git a/src/test/java/automationpractice/forms/ChallengingDomForm.java b/src/test/java/automationpractice/forms/ChallengingDomForm.java index 13c62ff..2cfa7b2 100644 --- a/src/test/java/automationpractice/forms/ChallengingDomForm.java +++ b/src/test/java/automationpractice/forms/ChallengingDomForm.java @@ -7,89 +7,17 @@ public class ChallengingDomForm extends Form { public static final String LOCATOR_CHALLENGING_DOM_FORM = "//h3[contains(text(),'Challenging DOM')]"; - public static final String ELEMENT_NAME_ROW3_COLUMN5 = "Cell in row 3 column 5"; - public static final String ELEMENT_NAME_ROW5_COLUMN5 = "Cell in row 5 column 5"; - public static final String ELEMENT_NAME_ROW7_COLUMN5 = "Cell in row 7 column 5"; - public static final String ELEMENT_NAME_ROW5_COLUMN7 = "Cell in row 5 column 7"; - public static final String ELEMENT_NAME_ROW5_COLUMN3 = "Cell in row 5 column 3"; - public static final String ELEMENT_NAME_ROW1_COLUMN1 = "Cell in row 1 column 1"; - public static final String ELEMENT_NAME_ROW2_COLUMN1 = "Cell in row 2 column 1"; - public static final String ELEMENT_NAME_HEADER_CHALLENGING_DOM = "Header of Challenging Dom"; - - private final String locatorCellRow5Column5 = "//tr[5]/td[5]"; - private final String locatorCellRow3Column5 = "//tr[3]/td[5]"; - private final String locatorCellRow7Column5 = "//tr[7]/td[5]"; - private final String locatorCellRow5Column3 = "//tr[5]/td[3]"; - private final String locatorCellRow5Column7 = "//tr[5]/td[7]"; - private final String locatorCellRow1Column1 = "//tr[1]/td[1]"; - private final String locatorCellRow2Column1 = "//tr[2]/td[1]"; - - private ILabel headerName = getElementFactory().getLabel(By.xpath(LOCATOR_CHALLENGING_DOM_FORM), ELEMENT_NAME_HEADER_CHALLENGING_DOM); - private ILabel cellInRow3Column5 = getElementFactory().getLabel(By.xpath(locatorCellRow3Column5), ELEMENT_NAME_ROW3_COLUMN5); - private ILabel cellInRow5Column5 = getElementFactory().getLabel(By.xpath(locatorCellRow5Column5), ELEMENT_NAME_ROW5_COLUMN5); - private ILabel cellInRow7Column5 = getElementFactory().getLabel(By.xpath(locatorCellRow7Column5), ELEMENT_NAME_ROW7_COLUMN5); - private ILabel cellInRow5Column7 = getElementFactory().getLabel(By.xpath(locatorCellRow5Column7), ELEMENT_NAME_ROW5_COLUMN7); - private ILabel cellInRow5Column3 = getElementFactory().getLabel(By.xpath(locatorCellRow5Column3), ELEMENT_NAME_ROW5_COLUMN3); - private ILabel cellInRow1Column1 = getElementFactory().getLabel(By.xpath(locatorCellRow1Column1), ELEMENT_NAME_ROW1_COLUMN1); - private ILabel cellInRow2Column1 = getElementFactory().getLabel(By.xpath(locatorCellRow2Column1), ELEMENT_NAME_ROW2_COLUMN1); public ChallengingDomForm() { - super(By.xpath(LOCATOR_CHALLENGING_DOM_FORM), "Challenging DOM"); - } - - public ILabel getCellInRow3Column5() { - return cellInRow3Column5; + super(By.xpath(LOCATOR_CHALLENGING_DOM_FORM), "Challenging Dom"); } - public ILabel getCellInRow5Column5() { - return cellInRow5Column5; + public String getHeaderText() { + return getFormLabel().getText(); } - public ILabel getCellInRow7Column5() { - return cellInRow7Column5; + public ILabel getCell(int row, int column) { + return getElementFactory().getLabel(By.xpath(String.format("//tr[%d]/td[%d]", row, column)), String.format("Cell at row %d and column %d", row, column)); } - public ILabel getCellInRow5Column7() { - return cellInRow5Column7; - } - - public ILabel getCellInRow5Column3() { - return cellInRow5Column3; - } - - public ILabel getCellInRow1Column1() { - return cellInRow1Column1; - } - - public ILabel getCellInRow2Column1() { - return cellInRow2Column1; - } - - public ILabel getHeaderName() { - return headerName; - } - - public String getLocatorCellRow1Column1() { - return locatorCellRow1Column1; - } - - public String getLocatorCellRow5Column5() { - return locatorCellRow5Column5; - } - - public String getLocatorCellRow3Column5() { - return locatorCellRow3Column5; - } - - public String getLocatorCellRow7Column5() { - return locatorCellRow7Column5; - } - - public String getLocatorCellRow5Column3() { - return locatorCellRow5Column3; - } - - public String getLocatorCellRow5Column7() { - return locatorCellRow5Column7; - } } diff --git a/src/test/java/manytools/ManyToolsForm.java b/src/test/java/manytools/ManyToolsForm.java index 2849ccf..7b055a6 100644 --- a/src/test/java/manytools/ManyToolsForm.java +++ b/src/test/java/manytools/ManyToolsForm.java @@ -2,6 +2,7 @@ import aquality.selenium.browser.AqualityServices; import aquality.selenium.core.utilities.IActionRetrier; +import aquality.selenium.elements.interfaces.IButton; import aquality.selenium.elements.interfaces.ILabel; import aquality.selenium.forms.Form; import org.openqa.selenium.By; @@ -12,6 +13,7 @@ public abstract class ManyToolsForm> extends Form { private static final String BASE_URL = "https://manytools.org/"; private final ILabel lblValue = getFormLabel().findChildElement(By.xpath(".//code"), getName(), ILabel.class); + private final IButton btnAgree = getElementFactory().getButton(By.xpath("//button[@mode='primary']"), "Agree"); protected ManyToolsForm(String name) { super(By.id("maincontent"), name); @@ -24,6 +26,11 @@ public T open() { AqualityServices.get(IActionRetrier.class).doWithRetry(() -> { AqualityServices.getBrowser().goTo(BASE_URL + getUrlPart()); AqualityServices.getBrowser().waitForPageToLoad(); + if (btnAgree.state().isDisplayed()) + { + btnAgree.click(); + btnAgree.state().waitForNotDisplayed(); + } }, Collections.singletonList(TimeoutException.class)); return (T) this; } diff --git a/src/test/java/tests/integration/LocatorTests.java b/src/test/java/tests/integration/LocatorTests.java index 43e92e6..4c07e72 100644 --- a/src/test/java/tests/integration/LocatorTests.java +++ b/src/test/java/tests/integration/LocatorTests.java @@ -17,16 +17,13 @@ import theinternet.forms.BrokenImagesForm; import java.util.List; +import java.util.concurrent.atomic.AtomicReference; import static aquality.selenium.locators.RelativeBySupplier.with; public class LocatorTests extends BaseTest { private final ChallengingDomForm challengingDomForm = new ChallengingDomForm(); - private final String labelLocatorCell = "//td"; - private final String friendlyMessageEquallingText = "Actual cell text is not equal expected"; - private final String friendlyMessageElementFound = "Element with not reachable distance is exist"; - private final int distanceToFindElementWithPositiveResult = 300; - private final int distanceToFindElementWithNegativeResult = 100; + private final By labelLocatorCell = By.xpath("//td"); @BeforeMethod public void beforeMethod() { @@ -46,173 +43,184 @@ public void testByImageLocator() { Assert.assertTrue(docLabels.size() > 1, "List of elements should be possible to find by image"); Assert.assertEquals(docLabels.size(), childLabels.size(), "Should be possible to find child elements by image with the same count"); - ILabel documentByTag = AqualityServices.getElementFactory().getLabel(By.tagName("body"), "document by tag"); + ILabel imgByTag = AqualityServices.getElementFactory().getLabel(By.tagName("img"), "img by tag"); float fullThreshold = 1; - ILabel documentByImage = AqualityServices.getElementFactory().getLabel(new ByImage(documentByTag.getElement().getScreenshotAs(OutputType.BYTES)).setThreshold(fullThreshold), - "body screen"); - Assert.assertTrue(documentByImage.state().isDisplayed(), "Should be possible to find element by document screenshot"); - Assert.assertEquals(((ByImage)documentByImage.getLocator()).getThreshold(), fullThreshold, "Should be possible to get ByImage threshold"); - Assert.assertEquals(documentByImage.getElement().getTagName(), "body", "Correct element must be found"); + AtomicReference documentByImageContainer = new AtomicReference<>(); + boolean isFound = AqualityServices.getConditionalWait().waitFor(browser -> { + ILabel image = AqualityServices.getElementFactory().getLabel(new ByImage(imgByTag.getElement().getScreenshotAs(OutputType.BYTES)).setThreshold(fullThreshold), + "img screen"); + documentByImageContainer.set(image); + boolean isDisplayed = image.state().isDisplayed(); + if (!isDisplayed) { + browser.navigate().refresh(); + } + return isDisplayed; + }); + ILabel elementByImage = documentByImageContainer.get(); + + Assert.assertTrue(isFound, "Should be possible to find element by element screenshot"); + Assert.assertEquals(((ByImage) elementByImage.getLocator()).getThreshold(), fullThreshold, "Should be possible to get ByImage threshold"); + Assert.assertEquals(elementByImage.getElement().getTagName(), "img", "Correct element must be found"); } @Test public void testAboveLocatorWithDifferentAboveParametersType() { - ILabel cellInRow5Column5 = challengingDomForm.getCellInRow5Column5(); + ILabel cellInRow5Column5 = challengingDomForm.getCell(5, 5); + ILabel cellInRow4Column5 = challengingDomForm.getCell(4, 5); - ILabel actualCellRaw3Column5GotWithByXpath = - elementFactory.getLabel(with(By.xpath(labelLocatorCell)).above(By.xpath(challengingDomForm.getLocatorCellRow5Column5())), - ChallengingDomForm.ELEMENT_NAME_ROW3_COLUMN5); + ILabel actualCellRaw4Column5GotWithByXpath = + elementFactory.getLabel(with(labelLocatorCell).above(cellInRow5Column5.getLocator()), + cellInRow5Column5.getName()); - ILabel actualCellRaw3Column5GotWithWebElement = - elementFactory.getLabel(with(By.xpath(labelLocatorCell)).above(cellInRow5Column5.getElement()), - ChallengingDomForm.ELEMENT_NAME_ROW3_COLUMN5); + ILabel actualCellRaw4Column5GotWithWebElement = + elementFactory.getLabel(with(labelLocatorCell).above(cellInRow5Column5.getElement()), + cellInRow4Column5.getName()); - ILabel actualCellRaw3Column5GotWithAqualityElement = - elementFactory.getLabel(with(By.xpath(labelLocatorCell)).above(cellInRow5Column5), - ChallengingDomForm.ELEMENT_NAME_ROW3_COLUMN5); + ILabel actualCellRaw4Column5GotWithAqualityElement = + elementFactory.getLabel(with(labelLocatorCell).above(cellInRow5Column5), + cellInRow4Column5.getName()); WebElement actualWebElementCellRaw3Column5GotBySeleniumRelative = getBrowser().getDriver().findElement(RelativeLocator - .with(By.xpath(labelLocatorCell)) - .above(By.xpath(challengingDomForm.getLocatorCellRow5Column5()))); + .with(labelLocatorCell) + .above(cellInRow5Column5.getLocator())); checkDifferentTypesWithSoftAssert( - actualCellRaw3Column5GotWithAqualityElement.getText(), - actualCellRaw3Column5GotWithWebElement.getText(), - actualCellRaw3Column5GotWithByXpath.getText(), + actualCellRaw4Column5GotWithAqualityElement.getText(), + actualCellRaw4Column5GotWithWebElement.getText(), + actualCellRaw4Column5GotWithByXpath.getText(), actualWebElementCellRaw3Column5GotBySeleniumRelative.getText(), - challengingDomForm.getCellInRow3Column5().getText()); + cellInRow4Column5.getText()); } @Test public void testBelowLocatorWithDifferentBelowParametersType() { - ILabel cellInRow5Column5 = challengingDomForm.getCellInRow5Column5(); + ILabel cellInRow5Column5 = challengingDomForm.getCell(5, 5); + ILabel cellInRow6Column5 = challengingDomForm.getCell(6, 5); ILabel actualCellRaw7Column5GotWithByXpath = - elementFactory.getLabel(with(By.xpath(labelLocatorCell)).below(By.xpath(challengingDomForm.getLocatorCellRow5Column5())), - ChallengingDomForm.ELEMENT_NAME_ROW7_COLUMN5); + elementFactory.getLabel(with(labelLocatorCell).below(cellInRow5Column5.getLocator()), + cellInRow6Column5.getName()); ILabel actualCellRaw7Column5GotWithWebElement = - elementFactory.getLabel(with(By.xpath(labelLocatorCell)).below(cellInRow5Column5.getElement()), - ChallengingDomForm.ELEMENT_NAME_ROW7_COLUMN5); + elementFactory.getLabel(with(labelLocatorCell).below(cellInRow5Column5.getElement()), + cellInRow6Column5.getName()); ILabel actualCellRaw7Column5GotWithAqualityElement = - elementFactory.getLabel(with(By.xpath(labelLocatorCell)).below(cellInRow5Column5), - ChallengingDomForm.ELEMENT_NAME_ROW7_COLUMN5); + elementFactory.getLabel(with(labelLocatorCell).below(cellInRow5Column5), + cellInRow6Column5.getName()); WebElement actualWebElementCellRaw7Column5GotBySeleniumRelative = getBrowser().getDriver().findElement(RelativeLocator - .with(By.xpath(labelLocatorCell)) - .below(By.xpath(challengingDomForm.getLocatorCellRow5Column5()))); + .with(labelLocatorCell) + .below(cellInRow5Column5.getLocator())); checkDifferentTypesWithSoftAssert( actualCellRaw7Column5GotWithAqualityElement.getText(), actualCellRaw7Column5GotWithWebElement.getText(), actualCellRaw7Column5GotWithByXpath.getText(), actualWebElementCellRaw7Column5GotBySeleniumRelative.getText(), - challengingDomForm.getCellInRow7Column5().getText()); + cellInRow6Column5.getText()); } @Test public void testToLeftOfLocatorWithDifferentToLeftOfParametersType() { - ILabel cellInRow5Column5 = challengingDomForm.getCellInRow5Column5(); + ILabel cellInRow5Column5 = challengingDomForm.getCell(5, 5); + ILabel cellInRow5Column4 = challengingDomForm.getCell(5, 4); ILabel actualCellRaw5Column3GotWithByXpath = - elementFactory.getLabel(with(By.xpath(labelLocatorCell)).toLeftOf(By.xpath(challengingDomForm.getLocatorCellRow5Column5())), - ChallengingDomForm.ELEMENT_NAME_ROW5_COLUMN3); + elementFactory.getLabel(with(labelLocatorCell).toLeftOf(cellInRow5Column5.getLocator()), + cellInRow5Column4.getName()); ILabel actualCellRaw5Column3GotWithWebElement = - elementFactory.getLabel(with(By.xpath(labelLocatorCell)).toLeftOf(cellInRow5Column5.getElement()), - ChallengingDomForm.ELEMENT_NAME_ROW5_COLUMN3); + elementFactory.getLabel(with(labelLocatorCell).toLeftOf(cellInRow5Column5.getElement()), + cellInRow5Column4.getName()); ILabel actualCellRaw5Column3GotWithAqualityElement = - elementFactory.getLabel(with(By.xpath(labelLocatorCell)).toLeftOf(cellInRow5Column5), - ChallengingDomForm.ELEMENT_NAME_ROW5_COLUMN3); + elementFactory.getLabel(with(labelLocatorCell).toLeftOf(cellInRow5Column5), + cellInRow5Column4.getName()); WebElement actualWebElementCellRaw5Column3GotBySeleniumRelative = getBrowser().getDriver().findElement(RelativeLocator - .with(By.xpath(labelLocatorCell)) - .toLeftOf(By.xpath(challengingDomForm.getLocatorCellRow5Column5()))); + .with(labelLocatorCell) + .toLeftOf(cellInRow5Column5.getLocator())); checkDifferentTypesWithSoftAssert( actualCellRaw5Column3GotWithAqualityElement.getText(), actualCellRaw5Column3GotWithWebElement.getText(), actualCellRaw5Column3GotWithByXpath.getText(), actualWebElementCellRaw5Column3GotBySeleniumRelative.getText(), - challengingDomForm.getCellInRow5Column3().getText()); + cellInRow5Column4.getText()); } @Test public void testToRightOfLocatorWithDifferentToRightOfParametersType() { - ILabel cellInRow5Column5 = challengingDomForm.getCellInRow5Column5(); + ILabel cellInRow5Column5 = challengingDomForm.getCell(5, 5); + ILabel cellInRow5Column6 = challengingDomForm.getCell(5, 6); ILabel actualCellRaw5Column7GotWithByXpath = - elementFactory.getLabel(with(By.xpath(labelLocatorCell)).toRightOf(By.xpath(challengingDomForm.getLocatorCellRow5Column5())), - ChallengingDomForm.ELEMENT_NAME_ROW5_COLUMN7); + elementFactory.getLabel(with(labelLocatorCell).toRightOf(cellInRow5Column5.getLocator()), + cellInRow5Column6.getName()); ILabel actualCellRaw5Column7GotWithWebElement = - elementFactory.getLabel(with(By.xpath(labelLocatorCell)).toRightOf(cellInRow5Column5.getElement()), - ChallengingDomForm.ELEMENT_NAME_ROW5_COLUMN7); + elementFactory.getLabel(with(labelLocatorCell).toRightOf(cellInRow5Column5.getElement()), + cellInRow5Column6.getName()); ILabel actualCellRaw5Column7GotWithAqualityElement = - elementFactory.getLabel(with(By.xpath(labelLocatorCell)).toRightOf(cellInRow5Column5), - ChallengingDomForm.ELEMENT_NAME_ROW5_COLUMN7); + elementFactory.getLabel(with(labelLocatorCell).toRightOf(cellInRow5Column5), + cellInRow5Column6.getName()); WebElement actualWebElementCellRaw5Column7GotBySeleniumRelative = getBrowser().getDriver().findElement(RelativeLocator - .with(By.xpath(labelLocatorCell)) - .toRightOf(By.xpath(challengingDomForm.getLocatorCellRow5Column5()))); + .with(labelLocatorCell) + .toRightOf(cellInRow5Column5.getLocator())); checkDifferentTypesWithSoftAssert( actualCellRaw5Column7GotWithAqualityElement.getText(), actualCellRaw5Column7GotWithWebElement.getText(), actualCellRaw5Column7GotWithByXpath.getText(), actualWebElementCellRaw5Column7GotBySeleniumRelative.getText(), - challengingDomForm.getCellInRow5Column7().getText()); + cellInRow5Column6.getText()); } @Test public void testAboveBelowLeftRightWithDifferentParametersType() { - ILabel cellInRow3Column5 = challengingDomForm.getCellInRow3Column5(); - ILabel cellInRow5Column7 = challengingDomForm.getCellInRow5Column7(); - ILabel cellInRow5Column5 = challengingDomForm.getCellInRow5Column5(); - ILabel cellInRow5Column3 = challengingDomForm.getCellInRow5Column3(); - ILabel cellInRow7Column5 = challengingDomForm.getCellInRow7Column5(); + ILabel cellInRow3Column5 = challengingDomForm.getCell(3, 5); + ILabel cellInRow5Column7 = challengingDomForm.getCell(5, 7); + ILabel cellInRow5Column5 = challengingDomForm.getCell(5, 5); + ILabel cellInRow5Column3 = challengingDomForm.getCell(5, 3); + ILabel cellInRow6Column5 = challengingDomForm.getCell(6, 5); ILabel actualCellRaw5Column5GotWithAqualityElement = - elementFactory.getLabel(with(By.xpath(labelLocatorCell)) - .above(cellInRow7Column5) + elementFactory.getLabel(with(labelLocatorCell) .below(cellInRow3Column5) .toRightOf(cellInRow5Column3) .toLeftOf(cellInRow5Column7) - .above(cellInRow7Column5) - , ChallengingDomForm.ELEMENT_NAME_ROW5_COLUMN5); + .above(cellInRow6Column5) + , cellInRow5Column5.getName()); ILabel actualCellRaw5Column5GotWithWebElement = - elementFactory.getLabel(with(By.xpath(labelLocatorCell)) - .above(cellInRow7Column5.getElement()) + elementFactory.getLabel(with(labelLocatorCell) .below(cellInRow3Column5.getElement()) .toRightOf(cellInRow5Column3.getElement()) .toLeftOf(cellInRow5Column7.getElement()) - .above(cellInRow7Column5.getElement()) - , ChallengingDomForm.ELEMENT_NAME_ROW5_COLUMN5); + .above(cellInRow6Column5.getElement()) + , cellInRow5Column5.getName()); ILabel actualCellRaw5Column5GotWithXpath = - elementFactory.getLabel(with(By.xpath(labelLocatorCell)) - .above(By.xpath(challengingDomForm.getLocatorCellRow7Column5())) - .below(By.xpath(challengingDomForm.getLocatorCellRow3Column5())) - .toRightOf(By.xpath(challengingDomForm.getLocatorCellRow5Column3())) - .toLeftOf(By.xpath(challengingDomForm.getLocatorCellRow5Column7())) - .above(By.xpath(challengingDomForm.getLocatorCellRow7Column5())) - , ChallengingDomForm.ELEMENT_NAME_ROW5_COLUMN5); + elementFactory.getLabel(with(labelLocatorCell) + .below(cellInRow3Column5.getLocator()) + .toRightOf(cellInRow5Column3.getLocator()) + .toLeftOf(cellInRow5Column7.getLocator()) + .above(cellInRow6Column5.getLocator()) + , cellInRow5Column5.getName()); WebElement actualWebElementCellRaw5Column5GotBySeleniumRelative = - getBrowser().getDriver().findElement(RelativeLocator.with(By.xpath(labelLocatorCell)) - .above(By.xpath(challengingDomForm.getLocatorCellRow7Column5())) - .below(By.xpath(challengingDomForm.getLocatorCellRow3Column5())) - .toRightOf(By.xpath(challengingDomForm.getLocatorCellRow5Column3())) - .toLeftOf(By.xpath(challengingDomForm.getLocatorCellRow5Column7())) - .above(By.xpath(challengingDomForm.getLocatorCellRow7Column5()))); + getBrowser().getDriver().findElement(RelativeLocator.with(labelLocatorCell) + .below(cellInRow3Column5.getLocator()) + .toRightOf(cellInRow5Column3.getLocator()) + .toLeftOf(cellInRow5Column7.getLocator()) + .above(cellInRow6Column5.getLocator())); checkDifferentTypesWithSoftAssert( actualCellRaw5Column5GotWithAqualityElement.getText(), @@ -224,84 +232,91 @@ public void testAboveBelowLeftRightWithDifferentParametersType() { @Test public void testNearWithDifferentNearParameterType() { + ILabel cellInRow1Column1 = challengingDomForm.getCell(1, 1); + ILabel cellInRow2Column1 = challengingDomForm.getCell(2, 1); ILabel actualCellRaw2Column1GotWithAqualityElement = - elementFactory.getLabel(with(By.xpath(labelLocatorCell)).near(challengingDomForm.getCellInRow1Column1()), - ChallengingDomForm.ELEMENT_NAME_ROW2_COLUMN1); + elementFactory.getLabel(with(labelLocatorCell).near(cellInRow1Column1), + cellInRow2Column1.getName()); ILabel actualCellRaw2Column1GotWithWebElement = - elementFactory.getLabel(with(By.xpath(labelLocatorCell)).near(challengingDomForm.getCellInRow1Column1().getElement()), - ChallengingDomForm.ELEMENT_NAME_ROW2_COLUMN1); + elementFactory.getLabel(with(labelLocatorCell).near(cellInRow1Column1.getElement()), + cellInRow2Column1.getName()); ILabel actualCellRaw2Column1GotWithXpath = - elementFactory.getLabel(with(By.xpath(labelLocatorCell)).near(By.xpath(challengingDomForm.getLocatorCellRow1Column1())), - ChallengingDomForm.ELEMENT_NAME_ROW2_COLUMN1); + elementFactory.getLabel(with(labelLocatorCell).near(cellInRow1Column1.getLocator()), + cellInRow2Column1.getName()); WebElement actualWebElementCellRaw2Column1GotBySeleniumRelative = - getBrowser().getDriver().findElement(RelativeLocator.with(By.xpath(labelLocatorCell)) - .near(By.xpath(challengingDomForm.getLocatorCellRow1Column1()))); + getBrowser().getDriver().findElement(RelativeLocator.with(labelLocatorCell) + .near(cellInRow1Column1.getLocator())); checkDifferentTypesWithSoftAssert( actualCellRaw2Column1GotWithAqualityElement.getText(), actualCellRaw2Column1GotWithWebElement.getText(), actualCellRaw2Column1GotWithXpath.getText(), actualWebElementCellRaw2Column1GotBySeleniumRelative.getText(), - challengingDomForm.getCellInRow2Column1().getText()); + cellInRow2Column1.getText()); } @Test public void testNearWithDistanceWithDifferentParametersType() { + ILabel cellInRow1Column1 = challengingDomForm.getCell(1, 1); + int distanceToFindElementWithPositiveResult = 300; ILabel actualHeaderNameGotWithAqualityElement = - elementFactory.getLabel(with(By.xpath(ChallengingDomForm.LOCATOR_CHALLENGING_DOM_FORM)) - .near(challengingDomForm.getCellInRow1Column1(), distanceToFindElementWithPositiveResult), - ChallengingDomForm.ELEMENT_NAME_HEADER_CHALLENGING_DOM); + elementFactory.getLabel(with(challengingDomForm.getLocator()) + .near(cellInRow1Column1, distanceToFindElementWithPositiveResult), + challengingDomForm.getName()); ILabel actualHeaderNameGotWithWebElement = - elementFactory.getLabel(with(By.xpath(ChallengingDomForm.LOCATOR_CHALLENGING_DOM_FORM)) - .near(challengingDomForm.getCellInRow1Column1().getElement(), distanceToFindElementWithPositiveResult), - ChallengingDomForm.ELEMENT_NAME_HEADER_CHALLENGING_DOM); + elementFactory.getLabel(with(challengingDomForm.getLocator()) + .near(cellInRow1Column1.getElement(), distanceToFindElementWithPositiveResult), + challengingDomForm.getName()); ILabel actualHeaderNameGotWithXpath = - elementFactory.getLabel(with(By.xpath(ChallengingDomForm.LOCATOR_CHALLENGING_DOM_FORM)) - .near(By.xpath(challengingDomForm.getLocatorCellRow1Column1()), distanceToFindElementWithPositiveResult), - ChallengingDomForm.ELEMENT_NAME_HEADER_CHALLENGING_DOM); + elementFactory.getLabel(with(challengingDomForm.getLocator()) + .near(cellInRow1Column1.getLocator(), distanceToFindElementWithPositiveResult), + challengingDomForm.getName()); WebElement actualWebElementHeaderNameGotBySeleniumRelative = - getBrowser().getDriver().findElement(RelativeLocator.with(By.xpath(ChallengingDomForm.LOCATOR_CHALLENGING_DOM_FORM)) - .near(getBrowser().getDriver().findElement(By.xpath(challengingDomForm.getLocatorCellRow1Column1())), distanceToFindElementWithPositiveResult)); + getBrowser().getDriver().findElement(RelativeLocator.with(challengingDomForm.getLocator()) + .near(getBrowser().getDriver().findElement(cellInRow1Column1.getLocator()), distanceToFindElementWithPositiveResult)); checkDifferentTypesWithSoftAssert( actualHeaderNameGotWithAqualityElement.getText(), actualHeaderNameGotWithWebElement.getText(), actualHeaderNameGotWithXpath.getText(), actualWebElementHeaderNameGotBySeleniumRelative.getText(), - challengingDomForm.getHeaderName().getText()); + challengingDomForm.getHeaderText()); } @Test public void testNearWithDistanceNegativeWithDifferentParametersType() { + ILabel cellInRow1Column1 = challengingDomForm.getCell(1, 1); + int distanceToFindElementWithNegativeResult = 100; ILabel actualHeaderNameGotWithAqualityElement = - elementFactory.getLabel(with(By.xpath(ChallengingDomForm.LOCATOR_CHALLENGING_DOM_FORM)) - .near(challengingDomForm.getCellInRow1Column1(), distanceToFindElementWithNegativeResult), - ChallengingDomForm.ELEMENT_NAME_HEADER_CHALLENGING_DOM); + elementFactory.getLabel(with(challengingDomForm.getLocator()) + .near(cellInRow1Column1, distanceToFindElementWithNegativeResult), + challengingDomForm.getName()); ILabel actualHeaderNameGotWithWebElement = - elementFactory.getLabel(with(By.xpath(ChallengingDomForm.LOCATOR_CHALLENGING_DOM_FORM)) - .near(challengingDomForm.getCellInRow1Column1().getElement(), distanceToFindElementWithNegativeResult), - ChallengingDomForm.ELEMENT_NAME_HEADER_CHALLENGING_DOM); + elementFactory.getLabel(with(challengingDomForm.getLocator()) + .near(cellInRow1Column1.getElement(), distanceToFindElementWithNegativeResult), + challengingDomForm.getName()); ILabel actualHeaderNameGotWithXpath = - elementFactory.getLabel(with(By.xpath(ChallengingDomForm.LOCATOR_CHALLENGING_DOM_FORM)) - .near(By.xpath(challengingDomForm.getLocatorCellRow1Column1()), distanceToFindElementWithNegativeResult), - ChallengingDomForm.ELEMENT_NAME_HEADER_CHALLENGING_DOM); + elementFactory.getLabel(with(challengingDomForm.getLocator()) + .near(cellInRow1Column1.getLocator(), distanceToFindElementWithNegativeResult), + challengingDomForm.getName()); List actualWebElementsHeaderNameGotBySeleniumRelative = - getBrowser().getDriver().findElements(RelativeLocator.with(By.xpath(ChallengingDomForm.LOCATOR_CHALLENGING_DOM_FORM)) - .near(getBrowser().getDriver().findElement(By.xpath(challengingDomForm.getLocatorCellRow1Column1())), distanceToFindElementWithNegativeResult)); + getBrowser().getDriver().findElements(RelativeLocator.with(challengingDomForm.getLocator()) + .near(getBrowser().getDriver().findElement(cellInRow1Column1.getLocator()), distanceToFindElementWithNegativeResult)); SoftAssert softAssert = new SoftAssert(); + String friendlyMessageElementFound = "Element with not reachable distance is exist"; softAssert.assertFalse(actualHeaderNameGotWithAqualityElement.state().isExist(), friendlyMessageElementFound); softAssert.assertFalse(actualHeaderNameGotWithWebElement.state().isExist(), friendlyMessageElementFound); softAssert.assertFalse(actualHeaderNameGotWithXpath.state().isExist(), friendlyMessageElementFound); @@ -311,6 +326,7 @@ public void testNearWithDistanceNegativeWithDifferentParametersType() { private void checkDifferentTypesWithSoftAssert(String textAquality, String textWebElement, String textByXpath, String textSelenium, String expectedText) { SoftAssert softAssert = new SoftAssert(); + String friendlyMessageEquallingText = "Actual cell text is not equal expected"; softAssert.assertEquals(textAquality, expectedText, friendlyMessageEquallingText); softAssert.assertEquals(textByXpath, expectedText, friendlyMessageEquallingText); softAssert.assertEquals(textWebElement, expectedText, friendlyMessageEquallingText); diff --git a/src/test/java/tests/usecases/devtools/DeviceEmulationTest.java b/src/test/java/tests/usecases/devtools/DeviceEmulationTest.java index afe32c3..e8dda34 100644 --- a/src/test/java/tests/usecases/devtools/DeviceEmulationTest.java +++ b/src/test/java/tests/usecases/devtools/DeviceEmulationTest.java @@ -3,8 +3,8 @@ import aquality.selenium.browser.AqualityServices; import aquality.selenium.browser.devtools.EmulationHandling; import com.google.common.collect.ImmutableMap; -import org.openqa.selenium.devtools.v132.emulation.Emulation; -import org.openqa.selenium.devtools.v132.emulation.model.DisplayFeature; +import org.openqa.selenium.devtools.v137.emulation.Emulation; +import org.openqa.selenium.devtools.v137.emulation.model.DisplayFeature; import org.testng.Assert; import org.testng.annotations.BeforeMethod; import org.testng.annotations.Test; diff --git a/src/test/java/tests/usecases/devtools/NetworkSpeedEmulationTest.java b/src/test/java/tests/usecases/devtools/NetworkSpeedEmulationTest.java index 9a04f9e..2238d60 100644 --- a/src/test/java/tests/usecases/devtools/NetworkSpeedEmulationTest.java +++ b/src/test/java/tests/usecases/devtools/NetworkSpeedEmulationTest.java @@ -2,7 +2,7 @@ import aquality.selenium.browser.AqualityServices; import org.openqa.selenium.TimeoutException; -import org.openqa.selenium.devtools.v132.network.model.ConnectionType; +import org.openqa.selenium.devtools.v137.network.model.ConnectionType; import org.testng.Assert; import org.testng.annotations.Test; import tests.BaseTest; diff --git a/src/test/java/tests/usecases/devtools/OverrideUserAgentTest.java b/src/test/java/tests/usecases/devtools/OverrideUserAgentTest.java index 5b7a7f0..1732528 100644 --- a/src/test/java/tests/usecases/devtools/OverrideUserAgentTest.java +++ b/src/test/java/tests/usecases/devtools/OverrideUserAgentTest.java @@ -8,7 +8,7 @@ import manytools.BrowserLanguageForm; import manytools.UserAgentForm; import org.openqa.selenium.devtools.idealized.Network; -import org.openqa.selenium.devtools.v132.emulation.Emulation; +import org.openqa.selenium.devtools.v137.emulation.Emulation; import org.testng.Assert; import org.testng.annotations.BeforeMethod; import org.testng.annotations.Test;