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
7 changes: 6 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,12 @@
<dependency>
<groupId>com.github.aquality-automation</groupId>
<artifactId>aquality-selenium-core</artifactId>
<version>5.0.2</version>
<version>5.1.0</version>
</dependency>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>4.51.0</version>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
Expand Down
32 changes: 4 additions & 28 deletions src/main/java/aquality/selenium/browser/RemoteBrowserFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import aquality.selenium.configuration.ITimeoutConfiguration;
import aquality.selenium.core.localization.ILocalizedLogger;
import aquality.selenium.core.utilities.IActionRetrier;
import com.google.common.collect.ImmutableMap;
import org.openqa.selenium.Capabilities;
import org.openqa.selenium.WebDriverException;
import org.openqa.selenium.remote.CommandExecutor;
Expand All @@ -13,10 +12,8 @@
import org.openqa.selenium.remote.RemoteWebDriver;
import org.openqa.selenium.remote.http.ClientConfig;
import org.openqa.selenium.remote.http.HttpClient;
import org.openqa.selenium.remote.http.HttpClient.Factory;

import java.net.URL;
import java.time.Duration;


public class RemoteBrowserFactory extends BrowserFactory {
Expand All @@ -36,13 +33,12 @@ public RemoteBrowserFactory(IActionRetrier actionRetrier, IBrowserProfile browse
@Override
protected RemoteWebDriver getDriver() {
Capabilities capabilities = browserProfile.getDriverSettings().getDriverOptions();
URL url = browserProfile.getRemoteConnectionUrl();
localizedLogger.info("loc.browser.grid");
ClientConfig config = ClientConfig.defaultConfig().baseUrl(url).readTimeout(timeoutConfiguration.getCommand());

ClientFactory clientFactory = new ClientFactory();
CommandExecutor commandExecutor = new HttpCommandExecutor(
ImmutableMap.of(),
browserProfile.getRemoteConnectionUrl(),
clientFactory);
HttpClient.Factory clientFactory = HttpClient.Factory.createDefault();
CommandExecutor commandExecutor = new HttpCommandExecutor(clientFactory.createClient(config), url);

try {
RemoteWebDriver driver = new RemoteWebDriver(commandExecutor, capabilities);
Expand All @@ -55,24 +51,4 @@ protected RemoteWebDriver getDriver() {
}

}

class ClientFactory implements Factory {
private final Factory defaultClientFactory = Factory.createDefault();
private final Duration timeoutCommand = timeoutConfiguration.getCommand();

public HttpClient createClient(URL url) {
return defaultClientFactory.createClient(ClientConfig.defaultConfig().baseUrl(url).readTimeout(timeoutCommand));
}

@Override
public HttpClient createClient(ClientConfig clientConfig) {
clientConfig.readTimeout(timeoutCommand);
return defaultClientFactory.createClient(clientConfig);
}

@Override
public void cleanupIdleClients() {
defaultClientFactory.cleanupIdleClients();
}
}
}
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.v154.performance.Performance;
import org.openqa.selenium.devtools.v154.performance.model.Metric;
import org.openqa.selenium.devtools.latest.performance.Performance;
import org.openqa.selenium.devtools.latest.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.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 org.openqa.selenium.devtools.latest.dom.model.RGBA;
import org.openqa.selenium.devtools.latest.emulation.Emulation;
import org.openqa.selenium.devtools.latest.emulation.model.DevicePosture;
import org.openqa.selenium.devtools.latest.emulation.model.DisplayFeature;
import org.openqa.selenium.devtools.latest.emulation.model.MediaFeature;
import org.openqa.selenium.devtools.latest.emulation.model.ScreenOrientation;
import org.openqa.selenium.devtools.latest.page.model.Viewport;

import java.util.Collections;
import java.util.List;
Expand Down Expand Up @@ -136,7 +136,7 @@
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(), Optional.empty());
Optional.empty(), Optional.empty(), Optional.empty(), Optional.empty());
}

/**
Expand All @@ -159,10 +159,17 @@
* @param scrollbarType The type of the scrollbars to render (e.g., mobile vs desktop). Ignored if |dontSetVisibleSize| is set.
* @param screenOrientationLockEmulation Enables screen orientation lock emulation that intercepts calls to screen.orientation.lock().
*/
public void setDeviceMetricsOverride(Integer width, Integer height, Number deviceScaleFactor, Boolean mobile, Optional<Number> scale, Optional<Integer> screenWidth, Optional<Integer> screenHeight, Optional<Integer> positionX, Optional<Integer> positionY, Optional<Boolean> dontSetVisibleSize, Optional<ScreenOrientation> screenOrientation, Optional<Viewport> viewport, Optional<DisplayFeature> displayFeature, Optional<DevicePosture> devicePosture, Optional<Emulation.SetDeviceMetricsOverrideScrollbarType> scrollbarType, Optional<Boolean> screenOrientationLockEmulation) {
public void setDeviceMetricsOverride(Integer width, Integer height, Number deviceScaleFactor, Boolean mobile,

Check warning on line 162 in src/main/java/aquality/selenium/browser/devtools/EmulationHandling.java

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Method has 17 parameters, which is greater than 7 authorized.

See more on https://sonarcloud.io/project/issues?id=aquality-automation_aquality-selenium-java&issues=AaGmFdZPXwwpdTbOOTqT&open=AaGmFdZPXwwpdTbOOTqT&pullRequest=169
Optional<Number> scale, Optional<Integer> screenWidth, Optional<Integer> screenHeight,
Optional<Integer> positionX, Optional<Integer> positionY, Optional<Boolean> dontSetVisibleSize,
Optional<ScreenOrientation> screenOrientation, Optional<Viewport> viewport,
Optional<DisplayFeature> displayFeature, Optional<DevicePosture> devicePosture,
Optional<Emulation.SetDeviceMetricsOverrideScrollbarType> scrollbarType,
Optional<Boolean> screenOrientationLockEmulation,
Optional<Emulation.SetDeviceMetricsOverrideViewportMeta> setDeviceMetricsOverrideViewportMeta) {
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Resolved
tools.sendCommand(Emulation.setDeviceMetricsOverride(width, height, deviceScaleFactor, mobile, scale, screenWidth,
screenHeight, positionX, positionY, dontSetVisibleSize, screenOrientation, viewport, displayFeature,
devicePosture, scrollbarType, screenOrientationLockEmulation));
devicePosture, scrollbarType, screenOrientationLockEmulation, setDeviceMetricsOverrideViewportMeta));
}

/**
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.v154.page.Page;
import org.openqa.selenium.devtools.v154.page.model.ScriptIdentifier;
import org.openqa.selenium.devtools.v154.runtime.Runtime;
import org.openqa.selenium.devtools.latest.page.Page;
import org.openqa.selenium.devtools.latest.page.model.ScriptIdentifier;
import org.openqa.selenium.devtools.latest.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.v154.network.model.*;
import org.openqa.selenium.devtools.latest.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.v154.network.Network.*;
import static org.openqa.selenium.devtools.latest.network.Network.*;

/**
* DevTools commands for version-independent network interception.
* For more information, see {@link org.openqa.selenium.devtools.v154.network.Network} and {@link Network}.
* For more information, see {@link org.openqa.selenium.devtools.latest.network.Network} and {@link Network}.
*/
public class NetworkHandling {
public static final String LOC_NETWORK_INTERCEPTOR_START = "loc.browser.network.interceptor.start";
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.v153.emulation.Emulation;
import org.openqa.selenium.devtools.v153.emulation.model.DisplayFeature;
import org.openqa.selenium.devtools.v155.emulation.Emulation;
import org.openqa.selenium.devtools.v155.emulation.model.DisplayFeature;
import org.testng.Assert;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
Expand Down Expand Up @@ -44,7 +44,7 @@ public void setAndClearDeviceMetricsOverrideWithVersionSpecificParametersTest()
AqualityServices.getBrowser().devTools().sendCommand(Emulation.setDeviceMetricsOverride(
WIDTH, HEIGHT, SCALE_FACTOR, IS_MOBILE, Optional.empty(), Optional.empty(), Optional.empty(),
Optional.empty(), Optional.empty(), Optional.empty(), Optional.empty(), Optional.empty(),
Optional.of(DISPLAY_FEATURE), Optional.empty(), Optional.empty(), Optional.empty()
Optional.of(DISPLAY_FEATURE), Optional.empty(), Optional.empty(), Optional.empty(), Optional.empty()
));
AqualityServices.getLogger().info("success");
});
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.v154.network.model.ConnectionType;
import org.openqa.selenium.devtools.v154.network.model.NetworkConditions;
import org.openqa.selenium.devtools.latest.network.model.ConnectionType;
import org.openqa.selenium.devtools.latest.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.v153.emulation.Emulation;
import org.openqa.selenium.devtools.v155.emulation.Emulation;
import org.testng.Assert;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
Expand Down
Loading