Skip to content

Commit

Permalink
The new config path webdriver.user.agent closes #4
Browse files Browse the repository at this point in the history
  • Loading branch information
ldaume committed Aug 1, 2017
1 parent bea3c75 commit 9e30d64
Show file tree
Hide file tree
Showing 7 changed files with 104 additions and 41 deletions.
32 changes: 26 additions & 6 deletions README.md
@@ -1,11 +1,17 @@
| Build Status | Dependencies UpToDate | Latest Version | License |
|:------------:|:---------------------:|:--------------:|:-------:|
| [![Build Status](https://ci.reinvent-software.de/buildStatus/icon?job=Headless-Chrome-Build)](https://ci.reinvent-software.de/job/Headless-Chrome-Build) | [![Dependencies UpToDate](https://ci.reinvent-software.de/buildStatus/icon?job=Headless-Chrome-DependencyCheck)](https://ci.reinvent-software.de/job/Headless-Chrome-DependencyCheck) | [![Maven Central](https://maven-badges.herokuapp.com/maven-central/software.reinvent/headless-chrome/badge.svg)](https://maven-badges.herokuapp.com/maven-central/software.reinvent/headless-chrome) | [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT) |

Headless Chrome
==========

<!-- TOC depthFrom:1 depthTo:6 withLinks:1 updateOnSave:1 orderedList:0 -->

- [Abstract](#abstract)
- [Status](#status)
- [Usage](#usage)
- [Repo](#repo)
- [SBT](#sbt)
- [Maven](#maven)
- [Guice Binding](#guice-binding)
- [Config](#config)
- [Chrome](#chrome)
Expand All @@ -23,13 +29,26 @@ Headless Chrome

Google Chrome version 59+ contains a real headless mode with no need of any display like xvfb or vnc.

# Status
# Usage

| Build Status | Dependencies UpToDate | License |
|:------------:|:---------------------:|:-------:|
| [![Build Status](https://ci.reinvent-software.de/buildStatus/icon?job=Headless-Chrome-Build)](https://ci.reinvent-software.de/job/Headless-Chrome-Build) | [![Dependencies UpToDate](https://ci.reinvent-software.de/buildStatus/icon?job=Headless-Chrome-DependencyCheck)](https://ci.reinvent-software.de/job/Headless-Chrome-DependencyCheck) | [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT) |
## Repo
Just add the following [maven central](https://mvnrepository.com/artifact/software.reinvent/commons) dependency.

### SBT
Add dependency to `build.sbt`.
```bash
libraryDependencies += "software.reinvent" % "headless-chrome" % "0.3.0"
```

### Maven
```xml
<dependency>
<groupId>software.reinvent</groupId>
<artifactId>headless-chrome</artifactId>
<version>0.3.0</version>
</dependency
```

# Usage

## Guice Binding

Expand All @@ -44,6 +63,7 @@ The config uses the [typesafe config](https://github.com/typesafehub/config).
| webdriver.chrome.driver | The path to the chromedriver binary | bundled in resources | :x: |
| webdriver.chrome.binary | The path to the chrome binary | /usr/bin/google-chrome-unstable | :white_check_mark: |
| chrome.window.size | The window size as string: "width,height" | "1920,1200" | :x: |
| webdriver.user.agent | The user agent used in chrome | default HeadlessChrome agent | :x: |

### Chrome

Expand Down
96 changes: 63 additions & 33 deletions build.sbt
@@ -1,50 +1,25 @@
import sbt.Keys.version

// Project name (artifact name in Maven)
name := """headless-chrome"""

// orgnization name (e.g., the package name of the project)
organization := "software.reinvent"

version := "0.3.0-SNAPSHOT"
version in ThisBuild := "0.3.0-SNAPSHOT"
// version := "0.2.2"
// version in ThisBuild := "0.2.2"
version := "0.4.0-SNAPSHOT"
version in ThisBuild := "0.4.0-SNAPSHOT"
//version := "0.3.0"
//version in ThisBuild := "0.3.0"

scalaVersion := "2.12.3"

// project description
description := "Implementation of the new headless chrome with chromedriver and selenium."

// Enables publishing to maven repo
publishMavenStyle := true
publishArtifact in Test := false
pomIncludeRepository := { _ => false }

publishTo := {
val nexus = "https://maven.reinvent-software.de/nexus/"
if ((version in ThisBuild).value.endsWith("SNAPSHOT")) {
Some("snapshots" at nexus + "content/repositories/snapshots")
else
Some("releases" at nexus + "content/repositories/releases")
}

overridePublishBothSettings

credentials += Credentials(Path.userHome / ".ivy2" / ".credentials")

// Do not append Scala versions to the generated artifacts
crossPaths := false

// This forbids including Scala related libraries into the dependency
autoScalaLibrary := false

aetherOldVersionMethod := true

resolvers ++= Seq(
Resolver.mavenLocal,
"ReInvent Software OSS" at "https://maven.reinvent-software.de/nexus/content/groups/public"
Resolver.mavenLocal
)


libraryDependencies ++= Seq(

// Commons
Expand All @@ -65,4 +40,59 @@ scalacOptions in Test ++= Seq("-Yrangepos")

dependencyUpdatesFailBuild := true

//dependencyUpdatesExclusions := moduleFilter(organization = "software.reinvent")
// Enables publishing to maven repo
publishMavenStyle := true
publishArtifact in Test := false
pomIncludeRepository := { _ => false }

enablePlugins(SignedAetherPlugin)

disablePlugins(AetherPlugin)

publishTo := {
val nexus = "https://maven.reinvent-software.de/nexus/"
if (version.value.trim.endsWith("SNAPSHOT")) {
Some("snapshots" at nexus + "content/repositories/snapshots")
} else {
Some(Opts.resolver.sonatypeStaging)
}
}

overridePublishBothSettings

overridePublishSignedBothSettings

credentials += Credentials(Path.userHome / ".ivy2" / ".credentials")
//credentials += Credentials(Path.userHome / ".ivy2" / ".credentials.sonatype")

// Do not append Scala versions to the generated artifacts
crossPaths := false

// This forbids including Scala related libraries into the dependency
autoScalaLibrary := false

homepage := Some(new URL("https://github.com/ldaume/headless-chrome"))

startYear := Some(2017)

licenses := Seq(("MIT", new URL("https://github.com/ldaume/headless-chrome/blob/master/LICENSE")))

pomExtra <<= (pomExtra, name, description) { (pom, name, desc) =>
pom ++ xml.Group(
<scm>
<url>http://github.com/ldaume/headless-chrome/tree/master</url>
<connection>scm:git:git://github.com:ldaume/headless-chrome.git</connection>
<developerConnection>scm:git:git@github.com:ldaume/headless-chrome.git</developerConnection>
</scm>
<developers>
<developer>
<id>ldaume</id>
<name>Leonard Daume</name>
<url>https://reinvent.software</url>
</developer>
</developers>
)
}



2 changes: 2 additions & 0 deletions project/plugins.sbt
@@ -1,3 +1,5 @@
addSbtPlugin("no.arktekk.sbt" % "aether-deploy" % "0.19.0")

addSbtPlugin("com.timushev.sbt" % "sbt-updates" % "0.3.1")

addSbtPlugin("com.jsuereth" % "sbt-pgp" % "1.0.0")
Expand Up @@ -66,6 +66,9 @@ public HeadlessDriver(Config config) {
} else {
windowSize = "1920,1200";
}
if (configToUse.hasPath("webdriver.user.agent")) {
chromeOptions.addArguments("--user-agent=" + configToUse.getString("webdriver.user.agent"));
}
chromeOptions.addArguments("--headless", "--disable-gpu", "--no-sandbox", "--incognito", "window-size=" + windowSize);

final DesiredCapabilities capabilities = DesiredCapabilities.chrome();
Expand Down
Expand Up @@ -50,7 +50,7 @@ public void testChromeDriver() throws Exception {
public void testExpectedElement() throws Exception {
driver.get("https://reinvent-software.de");
final String text = driver.findElementByXPath(".//*[@id='team']//p[@class='text-muted']").getText();
assertThat(text).isEqualTo("Head of Development");
assertThat(text).isEqualTo("Software Craftsman | DevOp | Agile Evangelist | Responsible Leader");
}

@Test
Expand All @@ -63,5 +63,11 @@ public void testScreenshot() throws Exception {
}


@Test
public void testUserAgent() throws Exception {
driver.get("http://www.useragents.com/");
final String text = driver.findElementByXPath("./html/body/center/p").getText();
assertThat(text).contains("Mozilla/5.0 (X11; Linux i686; rv:17.0.1) Gecko/20100101 Arch Linux Firefox/17.0.1");
}
}

3 changes: 3 additions & 0 deletions src/test/resources/application.conf
@@ -0,0 +1,3 @@
webdriver.chrome.binary: "C:/Program Files (x86)/Google/Chrome/Application/chrome.exe"

webdriver.user.agent: "Mozilla/5.0 (X11; Linux i686; rv:17.0.1) Gecko/20100101 Arch Linux Firefox/17.0.1"
1 change: 0 additions & 1 deletion src/test/resources/leona.conf

This file was deleted.

0 comments on commit 9e30d64

Please sign in to comment.