Skip to content

Commit

Permalink
Bumping Selenium version
Browse files Browse the repository at this point in the history
Also adding performanceMetricsWithCPUThrottling test
  • Loading branch information
diemol committed Feb 26, 2024
1 parent 01c4424 commit 7ba4c0d
Show file tree
Hide file tree
Showing 4 changed files with 86 additions and 33 deletions.
10 changes: 5 additions & 5 deletions selenium-examples/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
<licenses>
<license>
<name>MIT License</name>
<url>http://www.opensource.org/licenses/mit-license.php</url>
<url>https://www.opensource.org/licenses/mit-license.php</url>
<distribution>repo</distribution>
</license>
</licenses>
Expand All @@ -30,19 +30,19 @@
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>4.14.1</version>
<version>4.18.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<version>5.10.0</version>
<version>5.10.2</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.deque.html.axe-core</groupId>
<artifactId>selenium</artifactId>
<version>4.7.0</version>
<version>4.8.2</version>
<scope>test</scope>
</dependency>
<dependency>
Expand Down Expand Up @@ -73,4 +73,4 @@
</plugin>
</plugins>
</build>
</project>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public void startSession(TestInfo testInfo, Capabilities options) {
protected void startSession(Capabilities options, Map<String, Object> sauceOptions) {
((MutableCapabilities) options).setCapability("sauce:options", sauceOptions);
if (options.getPlatformName() == null) {
((AbstractDriverOptions<AbstractDriverOptions>) options).setPlatformName("Windows 11");
((AbstractDriverOptions<?>) options).setPlatformName("Windows 11");
}

URL url;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,18 @@

import com.google.common.collect.ImmutableMap;
import com.saucedemo.selenium.TestBase;
import java.util.*;
import org.junit.jupiter.api.*;
import org.openqa.selenium.*;

import java.util.Base64;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.TestInfo;
import org.openqa.selenium.By;
import org.openqa.selenium.Cookie;
import org.openqa.selenium.chromium.HasCdp;
import org.openqa.selenium.remote.Augmenter;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,23 +8,39 @@
import com.saucedemo.selenium.TestBase;
import java.net.URI;
import java.time.Duration;
import java.util.*;
import java.util.Base64;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Optional;
import java.util.concurrent.CopyOnWriteArrayList;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.function.Predicate;
import java.util.function.Supplier;
import org.junit.jupiter.api.*;
import org.openqa.selenium.*;

import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.TestInfo;
import org.openqa.selenium.By;
import org.openqa.selenium.Cookie;
import org.openqa.selenium.Credentials;
import org.openqa.selenium.HasAuthentication;
import org.openqa.selenium.JavascriptException;
import org.openqa.selenium.UsernameAndPassword;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeOptions;
import org.openqa.selenium.devtools.DevTools;
import org.openqa.selenium.devtools.HasDevTools;
import org.openqa.selenium.devtools.NetworkInterceptor;
import org.openqa.selenium.devtools.v118.browser.Browser;
import org.openqa.selenium.devtools.v118.network.Network;
import org.openqa.selenium.devtools.v118.network.model.Headers;
import org.openqa.selenium.devtools.v118.performance.Performance;
import org.openqa.selenium.devtools.v118.performance.model.Metric;
import org.openqa.selenium.devtools.v118.runtime.Runtime;
import org.openqa.selenium.devtools.v122.browser.Browser;
import org.openqa.selenium.devtools.v122.emulation.Emulation;
import org.openqa.selenium.devtools.v122.network.Network;
import org.openqa.selenium.devtools.v122.network.model.Headers;
import org.openqa.selenium.devtools.v122.performance.Performance;
import org.openqa.selenium.devtools.v122.performance.model.Metric;
import org.openqa.selenium.devtools.v122.runtime.Runtime;
import org.openqa.selenium.logging.HasLogEvents;
import org.openqa.selenium.remote.Augmenter;
import org.openqa.selenium.remote.http.Contents;
Expand Down Expand Up @@ -93,6 +109,35 @@ public void performanceMetrics() {
}

@Test
public void performanceMetricsWithCPUThrottling() {
driver.get("https://googlechrome.github.io/devtools-samples/jank/");

DevTools devTools = ((HasDevTools) driver).getDevTools();
devTools.createSession();
devTools.send(Performance.enable(Optional.empty()));

List<Metric> metricList = devTools.send(Performance.getMetrics());
Metric heapCheckOne =
metricList.stream()
.filter(metric -> "JSHeapUsedSize".equals(metric.getName()))
.findFirst()
.orElse(new Metric("JSHeapUsedSize", 0));

devTools.send(Emulation.setCPUThrottlingRate(4));
for (int i = 0; i < 15; i++) {
driver.findElement(By.className("add")).click();
}

metricList = devTools.send(Performance.getMetrics());
Metric heapCheckTwo = metricList.stream()
.filter(metric -> "JSHeapUsedSize".equals(metric.getName()))
.findFirst()
.orElse(new Metric("JSHeapUsedSize", 0));

Assertions.assertTrue(heapCheckOne.getValue().intValue() < heapCheckTwo.getValue().intValue());
}

@Test
public void basicAuthenticationCdpApi() {
DevTools devTools = ((HasDevTools) driver).getDevTools();
devTools.createSession();
Expand All @@ -110,6 +155,20 @@ public void basicAuthenticationCdpApi() {
driver.findElement(By.tagName("p")).getText());
}

@Test
public void basicAuthenticationBidiApi() {
Predicate<URI> uriPredicate = uri -> uri.toString().contains("herokuapp.com");
Supplier<Credentials> authentication = UsernameAndPassword.of("admin", "admin");

((HasAuthentication) driver).register(uriPredicate, authentication);

driver.get("https://the-internet.herokuapp.com/basic_auth");

String successMessage = "Congratulations! You must have the proper credentials.";
WebElement elementMessage = driver.findElement(By.tagName("p"));
Assertions.assertEquals(successMessage, elementMessage.getText());
}

@Test
public void consoleLogs() {
driver.get("https://www.selenium.dev/selenium/web/bidi/logEntryAdded.html");
Expand Down Expand Up @@ -169,21 +228,6 @@ public void waitForDownload() {
Assertions.assertDoesNotThrow(() -> wait.until(_d -> completed));
}

@Test
@Disabled("For some reason, this one does not work")
public void basicAuthenticationBidiApi() {
Predicate<URI> uriPredicate = uri -> uri.toString().contains("herokuapp.com");
Supplier<Credentials> authentication = UsernameAndPassword.of("admin", "admin");

((HasAuthentication) driver).register(uriPredicate, authentication);

driver.get("https://the-internet.herokuapp.com/basic_auth");

String successMessage = "Congratulations! You must have the proper credentials.";
WebElement elementMessage = driver.findElement(By.tagName("p"));
Assertions.assertEquals(successMessage, elementMessage.getText());
}

@Test
public void mutatedElements() {
driver.get("https://www.selenium.dev/selenium/web/dynamic.html");
Expand Down

0 comments on commit 7ba4c0d

Please sign in to comment.