Skip to content
Draft
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
19 changes: 0 additions & 19 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -145,25 +145,6 @@ and
<artifactId>org.monte.media.screenrecorder</artifactId>
<version>17.2.1</version>
</dependency>
<dependency>
<groupId>com.browserup</groupId>
<artifactId>browserup-proxy-core</artifactId>
<version>2.1.2</version>
<exclusions>
<exclusion>
<groupId>javax.xml.bind</groupId>
<artifactId>jaxb-api</artifactId>
</exclusion>
<exclusion>
<groupId>org.bouncycastle</groupId>
<artifactId>bcpkix-jdk15on</artifactId>
</exclusion>
<exclusion>
<groupId>org.bouncycastle</groupId>
<artifactId>bcprov-jdk15on</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>com.cloudbees</groupId>
<artifactId>extensibility</artifactId>
Expand Down
35 changes: 0 additions & 35 deletions src/main/java/org/jenkinsci/test/acceptance/FallbackConfig.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package org.jenkinsci.test.acceptance;

import com.browserup.bup.BrowserUpProxy;
import com.browserup.bup.client.ClientUtil;
import com.cloudbees.sdk.extensibility.ExtensionList;
import com.google.inject.AbstractModule;
import com.google.inject.Injector;
Expand All @@ -11,10 +9,8 @@
import java.io.Closeable;
import java.io.File;
import java.io.IOException;
import java.net.InetAddress;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.UnknownHostException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.time.Duration;
Expand All @@ -35,7 +31,6 @@
import org.jenkinsci.test.acceptance.guice.TestName;
import org.jenkinsci.test.acceptance.guice.TestScope;
import org.jenkinsci.test.acceptance.po.Jenkins;
import org.jenkinsci.test.acceptance.recorder.HarRecorder;
import org.jenkinsci.test.acceptance.selenium.Scroller;
import org.jenkinsci.test.acceptance.server.JenkinsControllerPoolProcess;
import org.jenkinsci.test.acceptance.server.PooledJenkinsController;
Expand All @@ -54,7 +49,6 @@
import org.openqa.selenium.Capabilities;
import org.openqa.selenium.Dimension;
import org.openqa.selenium.MutableCapabilities;
import org.openqa.selenium.Proxy;
import org.openqa.selenium.UnsupportedCommandException;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
Expand All @@ -64,7 +58,6 @@
import org.openqa.selenium.firefox.FirefoxOptions;
import org.openqa.selenium.firefox.GeckoDriverService;
import org.openqa.selenium.remote.Augmenter;
import org.openqa.selenium.remote.CapabilityType;
import org.openqa.selenium.remote.LocalFileDetector;
import org.openqa.selenium.remote.RemoteWebDriver;
import org.openqa.selenium.safari.SafariDriver;
Expand Down Expand Up @@ -119,10 +112,6 @@ private WebDriver createWebDriver(TestCleaner cleaner, TestName testName) throws
prefs.put(LANGUAGE_SELECTOR, "en");
ChromeOptions options = new ChromeOptions();
options.setExperimentalOption("prefs", prefs);
if (HarRecorder.isCaptureHarEnabled()) {
options.setAcceptInsecureCerts(true);
options.setProxy(createSeleniumProxy(testName.get()));
}

setDriverPropertyIfMissing("chromedriver", ChromeDriverService.CHROME_DRIVER_EXE_PROPERTY);
return new ChromeDriver(options);
Expand All @@ -134,9 +123,6 @@ private WebDriver createWebDriver(TestCleaner cleaner, TestName testName) throws
caps.setCapability("version", "29");
caps.setCapability("platform", "Windows 7");
caps.setCapability("name", testName.get());
if (HarRecorder.isCaptureHarEnabled()) {
caps.setCapability(CapabilityType.PROXY, createSeleniumProxy(testName.get()));
}

// if running inside Jenkins, expose build ID
String tag = System.getenv("BUILD_TAG");
Expand Down Expand Up @@ -185,9 +171,6 @@ private FirefoxOptions buildFirefoxOptions(TestName testName) throws IOException
DOM_MAX_CHROME_SCRIPT_RUN_TIME, (int) getElasticTime().seconds(600));
firefoxOptions.addPreference(DEVTOOLS_JSONVIEW_ENABLED, false); // For MetricsTest
firefoxOptions.enableBiDi();
if (HarRecorder.isCaptureHarEnabled()) {
firefoxOptions.setProxy(createSeleniumProxy(testName.get()));
}
if (System.getenv("FIREFOX_BIN") != null) {
firefoxOptions.setBinary(System.getenv("FIREFOX_BIN"));
}
Expand All @@ -196,9 +179,6 @@ private FirefoxOptions buildFirefoxOptions(TestName testName) throws IOException

private ChromeOptions buildChromeOptions(TestName testName) throws IOException {
ChromeOptions chromeOptions = new ChromeOptions();
if (HarRecorder.isCaptureHarEnabled()) {
chromeOptions.setProxy(createSeleniumProxy(testName.get()));
}
return chromeOptions;
}

Expand Down Expand Up @@ -276,21 +256,6 @@ public String toString() {
}
}

private Proxy createSeleniumProxy(String testName) throws UnknownHostException {
// if we are running maven locally but the browser elsewhere (e.g. docker) using the "127.0.0.1"
// address will not work for the browser
String name = System.getenv("SELENIUM_PROXY_HOSTNAME");
InetAddress proxyAddr;
if (name != null) {
proxyAddr = InetAddress.getByName(name);
} else {
// bind to the loopback to prevent exposing the proxy to the world.
proxyAddr = InetAddress.getLoopbackAddress();
}
BrowserUpProxy proxy = HarRecorder.getProxy(proxyAddr, testName);
return ClientUtil.createSeleniumProxy(proxy, proxyAddr);
}

private void setDriverPropertyIfMissing(final String driverCommand, final String property) {
if (System.getProperty(property) != null) {
return;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,20 +1,19 @@
package org.jenkinsci.test.acceptance.recorder;

import com.browserup.bup.BrowserUpProxy;
import com.browserup.bup.BrowserUpProxyServer;
import com.browserup.bup.proxy.CaptureType;
import com.browserup.harreader.model.Har;
import jakarta.inject.Inject;
import java.io.File;
import java.io.IOException;
import java.net.InetAddress;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.jenkinsci.test.acceptance.junit.FailureDiagnostics;
import org.jenkinsci.test.acceptance.junit.GlobalRule;
import org.jenkinsci.test.acceptance.recorder.har.BiDiHARRecorder;
import org.jenkinsci.test.acceptance.utils.SystemEnvironmentVariables;
import org.junit.rules.TestWatcher;
import org.junit.runner.Description;
import org.openqa.selenium.Capabilities;
import org.openqa.selenium.HasCapabilities;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.bidi.HasBiDi;
import org.openqa.selenium.bidi.module.Network;
import org.openqa.selenium.devtools.HasDevTools;

/**
* The system property RECORD_BROWSER_TRAFFIC can be set to either off, failuresOnly or always to control when browser
Expand Down Expand Up @@ -71,37 +70,12 @@ public static State value(String value) {
static State CAPTURE_HAR = State.value(SystemEnvironmentVariables.getPropertyVariableOrEnvironment(
"RECORD_BROWSER_TRAFFIC", State.OFF.getValue()));

private static BrowserUpProxy proxy;

/**
* Create a proxy to record the HAR listening on the specified address
* @param networkAddress the specific address to bind to, or {@code null} to bind on all addresses
*/
public static BrowserUpProxy getProxy(InetAddress networkAddress, String testName) {
LOGGER.log(Level.INFO, "Obtaining proxy for {0}...", testName);
if (proxy == null) {
LOGGER.log(Level.INFO, "Creating new Proxy for {0}...", testName);
// start the proxy
proxy = new BrowserUpProxyServer();
// enable more detailed HAR capture, if desired (see CaptureType for the complete list)
proxy.enableHarCaptureTypes(
CaptureType.REQUEST_HEADERS,
CaptureType.REQUEST_CONTENT,
CaptureType.RESPONSE_HEADERS,
CaptureType.RESPONSE_CONTENT);
proxy.setTrustAllServers(true);
proxy.setMitmDisabled(true);
proxy.start(0, networkAddress);
LOGGER.log(Level.INFO, "Proxy Created and listening on port {0}", proxy.getPort());
} else {
LOGGER.log(Level.INFO, "Existing Proxy for {0} returned using port {1}", new Object[] {
testName, proxy.getPort()
});
}
return proxy;
}
@Inject
protected WebDriver driver;

private FailureDiagnostics diagnostics;
private Network network;
private BiDiHARRecorder harRecorder;

@Inject
public HarRecorder(FailureDiagnostics diagnostics) {
Expand All @@ -128,25 +102,43 @@ protected void failed(Throwable e, Description description) {

@Override
protected void starting(Description description) {
if (!CAPTURE_HAR.isRecordingEnabled()) {
return;
}
initializeHarForTest(description.getDisplayName());
}

private void initializeHarForTest(String name) {
if (proxy != null) {
proxy.newHar(name);
if (!(driver instanceof HasBiDi)) {
LOGGER.warning("configured driver does not support BiDi, HAR recording will not be available");
return;
}
if (driver instanceof HasDevTools) {
// selenium removed support for DevTools for firefox
LOGGER.fine("configured driver supports DevTools!");
}


if (driver instanceof HasCapabilities) {
Capabilities caps = ((HasCapabilities) driver).getCapabilities();
harRecorder = new BiDiHARRecorder(name, caps.getBrowserName(), caps.getBrowserVersion());
} else {
harRecorder = new BiDiHARRecorder(name);
}

network = new Network(driver);
network.onBeforeRequestSent(harRecorder::onBeforeRequestSent);
network.onResponseCompleted(harRecorder::onResponseCompleted);
}

private void recordHar() {
if (proxy != null) {
Har har = proxy.getHar(true);
File file = diagnostics.touch("jenkins.har");
try {
har.writeTo(file);
} catch (IOException e) {
System.err.println("Unable to write HAR file to " + file);
e.printStackTrace(System.err);
}
try {

} finally {
// TODO do we need to close this or is it closed when the driver is closed?
// we also do not close if we do not write the HAR file, so if we need to close it we would leak
network.close();
}
}

}
Loading