selenium-help

Library that helps you use Selenium WebDriver in Java

License

License

GroupId

GroupId

com.github.mike10004
ArtifactId

ArtifactId

selenium-help
Last Version

Last Version

0.51
Release Date

Release Date

Type

Type

jar
Description

Description

selenium-help
Library that helps you use Selenium WebDriver in Java
Project URL

Project URL

https://github.com/mike10004/selenium-help
Source Code Management

Source Code Management

https://github.com/mike10004/selenium-help

Download selenium-help

How to add to project

<!-- https://jarcasting.com/artifacts/com.github.mike10004/selenium-help/ -->
<dependency>
    <groupId>com.github.mike10004</groupId>
    <artifactId>selenium-help</artifactId>
    <version>0.51</version>
</dependency>
// https://jarcasting.com/artifacts/com.github.mike10004/selenium-help/
implementation 'com.github.mike10004:selenium-help:0.51'
// https://jarcasting.com/artifacts/com.github.mike10004/selenium-help/
implementation ("com.github.mike10004:selenium-help:0.51")
'com.github.mike10004:selenium-help:jar:0.51'
<dependency org="com.github.mike10004" name="selenium-help" rev="0.51">
  <artifact name="selenium-help" type="jar" />
</dependency>
@Grapes(
@Grab(group='com.github.mike10004', module='selenium-help', version='0.51')
)
libraryDependencies += "com.github.mike10004" % "selenium-help" % "0.51"
[com.github.mike10004/selenium-help "0.51"]

Dependencies

compile (19)

Group / Artifact Type Version
com.google.code.gson : gson jar 2.8.5
org.apache.httpcomponents : httpclient jar 4.5.6
com.google.guava : guava jar 24.1-jre
org.apache.commons : commons-lang3 jar 3.6
org.apache.commons : commons-text jar 1.4
net.lightbody.bmp : browsermob-core jar 2.1.5
com.github.mike10004 : littleproxy jar 1.1.3socksmod1
org.seleniumhq.selenium : selenium-java jar 3.141.59
com.github.mike10004 : native-helper jar 10.0.0
com.google.code.findbugs : jsr305 jar 3.0.1
com.opencsv : opencsv jar 4.3.2
com.github.mike10004 : chrome-cookie-implant jar 1.5.15
org.brotli : dec jar 0.1.1
com.helger : ph-css jar 5.0.3
commons-io : commons-io jar 2.6
com.github.mike10004 : subprocess jar 0.1
org.mozilla : rhino jar 1.7.11
javax.xml.bind : jaxb-api jar 1.0.6
com.github.mike10004 : extensible-firefox-webdriver jar 3.141.59x0.16

test (8)

Group / Artifact Type Version
org.slf4j : slf4j-simple jar 1.7.25
junit : junit jar 4.12
io.github.bonigarcia : webdrivermanager jar 3.7.1
com.github.mike10004 : xvfb-testing jar 0.19
com.github.mike10004 : nanohttpd-server jar 0.14
commons-codec : commons-codec jar 1.10
commons-validator : commons-validator jar 1.6
com.github.mike10004 : nitsick-junit jar 0.2

Project Modules

There are no modules declared in this project.

Travis build Status AppVeyor build status Maven Central

selenium-capture

This is a library that facilitates capturing HTTP traffic from a Selenium web-browsing session. An intercepting proxy is used to capture the traffic.

Example

// be sure to define system property with geckodriver location if not contained in $PATH
// System.setProperty("webdriver.gecko.driver", "/path/to/geckodriver");
FirefoxWebDriverFactory factory = FirefoxWebDriverFactory.builder()
        .configure(firefoxOptions -> {
            firefoxOptions.setAcceptInsecureCerts(true);
        })
        .build();
Path scratchDir = java.nio.file.Files.createTempDirectory("selenium-capture-example");
try {
    TrafficCollector collector = TrafficCollector.builder(factory)
            .collectHttps(new AutoCertificateAndKeySource(scratchDir))
            .build();
    HarPlus<String> harPlus = collector.collect(new TrafficGenerator<String>() {
        @Override
        public String generate(WebDriver driver) {
            driver.get("https://www.example.com/");
            return driver.getTitle();
        }
    });
    System.out.println("collected page with title " + harPlus.result);
    File harFile = File.createTempFile("selenium-capture-example", ".har");
    BrowserUpHars.writeHar(harPlus.har, harFile, StandardCharsets.UTF_8);
    System.out.format("%s contains captured traffic%n", harFile);
} finally {
    FileUtils.forceDelete(scratchDir.toFile());
}

Capturing HTTPS traffic

To capture HTTPS traffic, the proxy must MITM the TLS traffic and the browser must be configured to trust the proxy's certificate or to accept insecure certificates.

The library will generate a self-signed certificate on demand to capture HTTPS traffic, or you can pre-generate one (take a look at the [GenerateNewCertificate][generate-new] class in the test sources).

Generating a new certificate takes up to 1000ms, so if you're frequently generating new certificates with the auto-generator, then you might save time by pre-generating a certificate and reusing it. For some examples of reusing a pre-generated certificate, take a look at the unit tests where HTTPS traffic is captured.

Providing cookies to your browser

The WebDriver APIs for cookie management are a tad simplistic. They have annoying snafus like

  • you can't add cookies associated with a site whose page is not open in the browser window,
  • you can't add cookies with all of the attributes the browser is capable of storing
  • you can't export cookies with all of the original attributes like expiration date

This library helps resolve the first two of these snafus for Firefox and Chrome webdrivers with custom solutions for each browser.

  • For Firefox, the library provides a mechanism to generate the SQLite database where the browser stores cookies in the user profile directory
  • For Chrome, the browser is started with an extension that enables cookies to be imported programatically

To resolve the issue of cookie export, you can use the traffic capture to gain access to all cookies that were sent during a browsing session.

Required Driver Versions

Make sure to keep your Chromedriver and Geckodriver installations up to date. When Selenium gets updated, the minimum required versions of the driver executables are often raised.

Versions

Version
0.51
0.50
0.49
0.48
0.47
0.46
0.44
0.42
0.41
0.40
0.39
0.38
0.37
0.36
0.34
0.33
0.32
0.31
0.30
0.29
0.28
0.27
0.26
0.25
0.21
0.20
0.19
0.18
0.17
0.16
0.15
0.14
0.13
0.11
0.10
0.9
0.8
0.7
0.6
0.5
0.2