Skip to content
Merged
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
55 changes: 33 additions & 22 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -70,17 +70,17 @@
<dependency>
<groupId>com.github.aquality-automation</groupId>
<artifactId>aquality-selenium-core</artifactId>
<version>4.19.0</version>
<version>5.0.2</version>
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Resolved
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>3.20.0</version>
<version>3.21.0</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.22.2</version>
<version>2.22.3</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
Expand Down Expand Up @@ -153,24 +153,6 @@
</suiteXmlFiles>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<version>3.8.0</version>
<executions>
<execution>
<goals>
<goal>single</goal>
</goals>
<phase>package</phase>
<configuration>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
Expand Down Expand Up @@ -223,7 +205,7 @@
<plugin>
<groupId>org.sonatype.central</groupId>
<artifactId>central-publishing-maven-plugin</artifactId>
<version>0.11.0</version>
<version>0.12.0</version>
<extensions>true</extensions>
<configuration>
<publishingServerId>central</publishingServerId>
Expand All @@ -238,4 +220,33 @@
</plugin>
</plugins>
</build>

<profiles>
<profile>
<id>fatjar</id>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<version>3.8.0</version>
<executions>
<execution>
<id>fat-jar</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
<configuration>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
</profiles>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -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.v153.performance.Performance;
import org.openqa.selenium.devtools.v153.performance.model.Metric;
import org.openqa.selenium.devtools.v154.performance.Performance;
import org.openqa.selenium.devtools.v154.performance.model.Metric;

import java.util.List;
import java.util.Map;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@

import org.apache.commons.lang3.StringUtils;
import org.openqa.selenium.devtools.Command;
import org.openqa.selenium.devtools.v153.dom.model.RGBA;
import org.openqa.selenium.devtools.v153.emulation.Emulation;
import org.openqa.selenium.devtools.v153.emulation.model.DevicePosture;
import org.openqa.selenium.devtools.v153.emulation.model.DisplayFeature;
import org.openqa.selenium.devtools.v153.emulation.model.MediaFeature;
import org.openqa.selenium.devtools.v153.emulation.model.ScreenOrientation;
import org.openqa.selenium.devtools.v153.page.model.Viewport;
import org.openqa.selenium.devtools.v154.dom.model.RGBA;
import org.openqa.selenium.devtools.v154.emulation.Emulation;
import org.openqa.selenium.devtools.v154.emulation.model.DevicePosture;
import org.openqa.selenium.devtools.v154.emulation.model.DisplayFeature;
import org.openqa.selenium.devtools.v154.emulation.model.MediaFeature;
import org.openqa.selenium.devtools.v154.emulation.model.ScreenOrientation;
import org.openqa.selenium.devtools.v154.page.model.Viewport;

import java.util.Collections;
import java.util.List;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.v153.page.Page;
import org.openqa.selenium.devtools.v153.page.model.ScriptIdentifier;
import org.openqa.selenium.devtools.v153.runtime.Runtime;
import org.openqa.selenium.devtools.v154.page.Page;
import org.openqa.selenium.devtools.v154.page.model.ScriptIdentifier;
import org.openqa.selenium.devtools.v154.runtime.Runtime;
import org.openqa.selenium.logging.EventType;
import org.openqa.selenium.logging.HasLogEvents;
import org.openqa.selenium.remote.Augmenter;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.v153.network.model.*;
import org.openqa.selenium.devtools.v154.network.model.*;
import org.openqa.selenium.remote.http.*;

import java.net.URI;
Expand All @@ -22,11 +22,11 @@

import static aquality.selenium.browser.AqualityServices.getBrowser;
import static aquality.selenium.logging.LocalizedLoggerUtility.logByLevel;
import static org.openqa.selenium.devtools.v153.network.Network.*;
import static org.openqa.selenium.devtools.v154.network.Network.*;

/**
* DevTools commands for version-independent network interception.
* For more information, see {@link org.openqa.selenium.devtools.v153.network.Network} and {@link Network}.
* For more information, see {@link org.openqa.selenium.devtools.v154.network.Network} and {@link Network}.
*/
public class NetworkHandling {
public static final String LOC_NETWORK_INTERCEPTOR_START = "loc.browser.network.interceptor.start";
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/aquality/selenium/elements/Element.java
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ protected IConditionalWait getConditionalWait() {
@Override
public RemoteWebElement getElement(Duration timeout) {
try {
return super.getElement(timeout);
return (RemoteWebElement) super.getElement(timeout);
} catch (NoSuchElementException e) {
getLogger().error(e.getMessage());
long timeoutInSeconds = timeout == null
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -169,10 +169,11 @@ protected Mat getScreenshot(SearchContext context) {
: AqualityServices.getBrowser().getScreenshot();
boolean isBrowserScreenshot = context instanceof WebDriver || !(context instanceof TakesScreenshot);
Mat source = Imgcodecs.imdecode(new MatOfByte(screenshotBytes), Imgcodecs.IMREAD_UNCHANGED);
long devicePixelRatio = (long) AqualityServices.getBrowser().executeScript(JavaScript.GET_DEVICE_PIXEL_RATIO);
double devicePixelRatio =
((Number) AqualityServices.getBrowser().executeScript(JavaScript.GET_DEVICE_PIXEL_RATIO)).doubleValue();
if (devicePixelRatio != 1 && isBrowserScreenshot) {
int scaledWidth = (int) (source.width() / devicePixelRatio);
int scaledHeight = (int) (source.height() / devicePixelRatio);
double scaledWidth = source.width() / devicePixelRatio;
double scaledHeight = source.height() / devicePixelRatio;
Imgproc.resize(source, source, new Size(scaledWidth, scaledHeight), 0, 0, Imgproc.INTER_AREA);
}
return source;
Expand Down
21 changes: 21 additions & 0 deletions src/main/java/aquality/selenium/elements/interfaces/IElement.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,31 @@
import aquality.selenium.elements.actions.MouseActions;
import org.openqa.selenium.By;
import org.openqa.selenium.Keys;
import org.openqa.selenium.remote.RemoteWebElement;

import java.time.Duration;
import java.util.List;

public interface IElement extends aquality.selenium.core.elements.interfaces.IElement, IShadowRootExpander {
/**
* Gets current element by specified {@link #getLocator()}
* Default timeout is provided in {@link aquality.selenium.core.configurations.ITimeoutConfiguration}
* {@link org.openqa.selenium.NoSuchElementException} throws if element not found
*
* @return instance of {@link RemoteWebElement} if found.
*/
default RemoteWebElement getElement() {
return getElement(null);
}

/**
* Gets current element by specified {@link #getLocator()}
* {@link org.openqa.selenium.NoSuchElementException} throws if element not found
*
* @param timeout Timeout for waiting
* @return instance of {@link RemoteWebElement} if found.
*/
RemoteWebElement getElement(Duration timeout);

/**
* Send keys.
Expand Down
2 changes: 1 addition & 1 deletion src/test/java/tests/integration/ActionTests.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public void testScrollToTheCenter() {
final int accuracy = 1;
WelcomeForm welcomeForm = new WelcomeForm();
getBrowser().goTo(welcomeForm.getUrl());
ILink link = welcomeForm.getExampleLink(WelcomeForm.AvailableExample.HOVERS);
ILink link = welcomeForm.getExampleLink(WelcomeForm.AvailableExample.CHECKBOXES);
link.getJsActions().scrollToTheCenter();

Long windowHeight = getScriptResultOrDefault("getWindowSize.js", 10L);
Expand Down
5 changes: 4 additions & 1 deletion src/test/java/tests/integration/LocatorTests.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package tests.integration;

import aquality.selenium.browser.AqualityServices;
import aquality.selenium.core.elements.ElementState;
import aquality.selenium.core.elements.ElementsCount;
import aquality.selenium.elements.interfaces.ByImage;
import aquality.selenium.elements.interfaces.ILabel;
import automationpractice.forms.ChallengingDomForm;
Expand Down Expand Up @@ -43,7 +45,8 @@ 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 imgByTag = AqualityServices.getElementFactory().getLabel(By.tagName("img"), "img by tag");
ILabel imgByTag = AqualityServices.getElementFactory()
.findElements(By.tagName("img"), "img by tag", ILabel.class, ElementsCount.MORE_THAN_ZERO, ElementState.DISPLAYED).get(1);
float fullThreshold = 1;
AtomicReference<ILabel> documentByImageContainer = new AtomicReference<>();
boolean isFound = AqualityServices.getConditionalWait().waitFor(browser -> {
Expand Down
2 changes: 1 addition & 1 deletion src/test/java/tests/integration/elements/ElementTests.java
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ public void testShouldBePossibleToGetCssValue(){
ITextBox txbUsername = elementFactory.getTextBox(By.id("username"), "username");

String propertyName = "font-family";
String expectedCssValue = "Helvetica";
String expectedCssValue = "Arial";

Assert.assertTrue(txbUsername.getCssValue(propertyName).contains(expectedCssValue));
Assert.assertTrue(txbUsername.getCssValue(propertyName, HighlightState.HIGHLIGHT).contains(expectedCssValue));
Expand Down
2 changes: 1 addition & 1 deletion src/test/java/tests/usecases/FileDownloadingTests.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public void testDownloading() {
List<String> tabs = new ArrayList<>(AqualityServices.getBrowser().getDriver().getWindowHandles());

AqualityServices.getBrowser().getDriver().switchTo().window(tabs.get(1));
AqualityServices.getBrowser().goTo(TheInternetPage.DOWNLOAD.getAddress());
downloaderForm.open();
downloaderForm.getLnkDownload(fileName).getJsActions().clickAndWait();

AqualityServices.getBrowser().getDriver().switchTo().window(tabs.get(0));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.v152.emulation.Emulation;
import org.openqa.selenium.devtools.v152.emulation.model.DisplayFeature;
import org.openqa.selenium.devtools.v153.emulation.Emulation;
import org.openqa.selenium.devtools.v153.emulation.model.DisplayFeature;
import org.testng.Assert;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
import aquality.selenium.browser.AqualityServices;
import aquality.selenium.browser.devtools.NetworkHandling;
import org.openqa.selenium.TimeoutException;
import org.openqa.selenium.devtools.v153.network.model.ConnectionType;
import org.openqa.selenium.devtools.v153.network.model.NetworkConditions;
import org.openqa.selenium.devtools.v154.network.model.ConnectionType;
import org.openqa.selenium.devtools.v154.network.model.NetworkConditions;
import org.testng.Assert;
import org.testng.annotations.Test;
import tests.BaseTest;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import manytools.BrowserLanguageForm;
import manytools.UserAgentForm;
import org.openqa.selenium.devtools.idealized.Network;
import org.openqa.selenium.devtools.v152.emulation.Emulation;
import org.openqa.selenium.devtools.v153.emulation.Emulation;
import org.testng.Assert;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
Expand Down
35 changes: 35 additions & 0 deletions src/test/java/theinternet/forms/FileDownloaderForm.java
Original file line number Diff line number Diff line change
@@ -1,11 +1,19 @@
package theinternet.forms;

import aquality.selenium.browser.AlertActions;
import aquality.selenium.browser.AqualityServices;
import aquality.selenium.core.logging.Logger;
import aquality.selenium.elements.interfaces.ILink;
import aquality.selenium.forms.Form;
import org.openqa.selenium.By;
import org.openqa.selenium.NoAlertPresentException;
import org.openqa.selenium.NoSuchWindowException;
import org.openqa.selenium.UnhandledAlertException;
import theinternet.TheInternetPage;

public class FileDownloaderForm extends Form {
private static final String DEFAULT_FILE_NAME = "some-file.txt";
private static final int MAX_ALERTS_COUNT = 100;
private static final String LINK_TEMPLATE = "//a[contains(@href,'%s')]";

public FileDownloaderForm() {
Expand All @@ -20,4 +28,31 @@ public ILink getLnkDownload(String fileName) {
public String getFileName() {
return DEFAULT_FILE_NAME;
}

public void open() {
String url = TheInternetPage.DOWNLOAD.getAddress();
try {
AqualityServices.getBrowser().goTo(url);
AqualityServices.getBrowser().waitForPageToLoad();
} catch (UnhandledAlertException e) {
Logger.getInstance().debug("Unhandled alert detected", e);
for (int i = 0; i < MAX_ALERTS_COUNT; i++)
{
try
{
AqualityServices.getBrowser().handleAlert(AlertActions.ACCEPT);
}
catch (NoAlertPresentException noAlertPresentException)
{
Logger.getInstance().debug("No more alerts present", noAlertPresentException);
break;
}
}
if (!url.equals(AqualityServices.getBrowser().getCurrentUrl()))
{
throw new NoSuchWindowException(url + " was not opened", e);
}
AqualityServices.getBrowser().waitForPageToLoad();
}
}
}
7 changes: 0 additions & 7 deletions src/test/java/theinternet/forms/TheInternetForm.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package theinternet.forms;

import aquality.selenium.elements.interfaces.ILink;
import aquality.selenium.forms.Form;
import org.openqa.selenium.By;

Expand All @@ -11,15 +10,9 @@ public abstract class TheInternetForm extends Form {
}

private static final String THE_INTERNET_FORM_URL = "https://the-internet.herokuapp.com";
private final ILink elementalSeleniumLink = getElementFactory().getLink(By.xpath("//a[contains(@href,'elementalselenium')]"), "Elemental Selenium");

public String getUrl() {
return THE_INTERNET_FORM_URL + getUri();
}

public void clickElementalSelenium() {
elementalSeleniumLink.click();
}

protected abstract String getUri();
}
6 changes: 6 additions & 0 deletions src/test/java/theinternet/forms/WelcomeForm.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ public class WelcomeForm extends TheInternetForm {
private static final String EXAMPLE_LINK_XPATH_TEMPLATE = "//a[contains(@href,'%s')]";
private final ILabel lblSubtitle = getElementFactory().getLabel(By.xpath("//h2"), "Sub title");

private final ILink lnkElementalSelenium = getElementFactory().getLink(By.xpath("//a[contains(@href,'elementalselenium')]"), "Elemental Selenium");

public WelcomeForm() {
super(By.xpath("//h1[contains(.,'Welcome to the-internet')]"), "Welcome to the-internet");
}
Expand All @@ -32,6 +34,10 @@ public Point getFormPointInViewPort(){
return getElementFactory().getLabel(getLocator(), getName()).getJsActions().getViewPortCoordinates();
}

public void clickElementalSelenium() {
lnkElementalSelenium.click();
}

public enum AvailableExample {
CHECKBOXES,
DROPDOWN,
Expand Down
Loading