Skip to content

Commit

Permalink
update ghostdriver for phantomjs 2.5 (#511)
Browse files Browse the repository at this point in the history
* fix page load for phantomjs 2.5.0
* add unhandledPromptBehavior w3c capability
* add blacklist/whitelist filters
* fix sending keys to content editable elements
* fix file upload for phantomjs 2.5.0
* fix action chains with elements in iframes
* replace calls to execute_script with atoms
* add --remoteHost (@madhavajay)
* add w3c defaults for add cookie
* fix multiple file upload
* add w3c timeout defaults
* fix custom phantomjs headers
* fix memory leak in the har log
* add limited support for loggingPrefs capability
* fix browser and har logs default to OFF
* add jitpack configuration
* various bug fixes

Issue #486
  • Loading branch information
jesg authored and detro committed Mar 21, 2017
1 parent 873c9d6 commit 7cf96db
Show file tree
Hide file tree
Showing 72 changed files with 2,185 additions and 2,352 deletions.
86 changes: 39 additions & 47 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,27 +1,8 @@
# HELP NEEDED
I have been away from this project for 2+ years. Family and change or more intense and demanding work, made it impossible to maintain this properly.

Lots has changed: PhantomJS is now 2.x and lots of this code should be revised, tested and validated to work with latest PhantomJS **whilst** conforming to latest WebDriver specs.
All of this requires a big effort and commitment that I can't make.

I have been merging some obviously good PR, but not testing them: I have to assume that submitters did it!.

__GhostDriver__ needs a proper maintainer. Someone that can prove she/he can understand this codebase and bring it forward. There are many MANY things that need to be done to make this project survive.

**Are you out there?**

---

### Alternatives

If you need a better maintained WebDriver implementation, and write your code in Java, why not checkout [Machine Publishers' jBrowserDriver](https://github.com/MachinePublishers/jBrowserDriver/)? Tell [Dan Hollingsworth](https://github.com/hollingsworthd) I sent you.

---

# Ghost Driver

Ghost Driver is a pure JavaScript implementation of the
[WebDriver Wire Protocol](http://code.google.com/p/selenium/wiki/JsonWireProtocol)
[WebDriver Wire Protocol](https://github.com/SeleniumHQ/selenium/wiki/JsonWireProtocol)
for [PhantomJS](http://phantomjs.org/).
It's a Remote WebDriver that uses PhantomJS as back-end.

Expand All @@ -30,8 +11,8 @@ by this Repository.**

* Current _GhostDriver_ stable version:
see [releases](https://github.com/detro/ghostdriver/releases)
* Current _PhantomJS-integrated_ version is `"1.1.0"`:
contained in PhantomJS `"1.9.7"`
* PhantomJS-integrated version is `"1.2.0"` (detro@2af7099a9) :
contained in PhantomJS `"2.1.1"`
* Current _PhantomJSDriver Java bindings_ stable version: see
[Maven](https://oss.sonatype.org/index.html#nexus-search;quick~phantomjsdriver)

Expand All @@ -44,7 +25,7 @@ IRC channel: [#phantomjs-ghostdriver](http://webchat.freenode.net/?channels=%23p
## Setup

* Download latest stable PhantomJS from [here](http://phantomjs.org/download.html)
* Selenium version `">= 2.33.0`"
* Selenium version `">= 3.0.0`"

**THAT'S IT!!** Because of latest stable GhostDriver being embedded in PhantomJS,
you shouldn't need anything else to get started.
Expand All @@ -65,41 +46,45 @@ under the same name within the [Selenium project](http://docs.seleniumhq.org/doc

### Include Java Bindings in your Maven project

For versions >= 1.2.0, add the following to your `pom.xml`:
For versions >= 2.0.0, add the following to your `pom.xml`:

```xml
<dependency>
<groupId>com.github.detro</groupId>
<artifactId>phantomjsdriver</artifactId>
<version>1.2.0</version>
</dependency>
<repositories>
<repository>
<id>jitpack.io</id>
<url>https://jitpack.io</url>
</repository>
</repositories>
```

For versions < 1.2.0, add the following to your `pom.xml`:

```xml
<dependency>
<groupId>com.github.detro.ghostdriver</groupId>
<groupId>com.github.detro</groupId>
<artifactId>phantomjsdriver</artifactId>
<version>1.1.0</version>
<version>2.0.0</version>
</dependency>
```

### Include Java Bindings in your Gradle project

Just add the following to your `build.gradle`:

```gradle
allprojects {
repositories {
maven { url 'https://jitpack.io' }
}
}
```

```gradle
dependencies {
...
testCompile "com.github.detro.ghostdriver:phantomjsdriver:LATEST_VERSION_HERE"
testCompile "com.github.detro.ghostdriver:phantomjsdriver:2.0.0"
...
}
```

### Search Maven
For other options on how to include the PhantomJSDriver dependency into your project, click [here](http://search.maven.org/#search%7Cga%7C1%7Ccom.github.detro.ghostdriver).

### Alternative: how to use it via `RemoteWebDriver`

Launching PhantomJS in Remote WebDriver mode it's simple:
Expand All @@ -112,14 +97,21 @@ Once started, you can use any `RemoteWebDriver` implementation to send commands
## F.A.Q.

### What extra WebDriver `capabilities` GhostDriver offers?
* GhostDriver extra Capabilities
* **GhostDriver** extra Capabilities
* `phantomjs.page.settings.SETTING = VALUE` - Configure `page.settings`
on PhantomJS internal page objects (_windows_ in WebDriver context)
(see [reference](http://phantomjs.org/api/webpage/property/settings.html))
* `phantomjs.page.customHeaders.HEADER = VALUE` - Add extra HTTP Headers
when loading a URL
(see [reference](http://phantomjs.org/api/webpage/property/custom-headers.html))
* PhantomJSDriver (Java-binding) Capabilities
* `phantomjs.page.whitelist` - an array of regex expressions of urls to accept. eg. ['my-awesome-website.com']
* `phantomjs.page.blacklist` - array of regex expressions of urls to ignore. The blacklist overrides the whitelist. eg. ['google.com', 'github.com']
* `unhandledPromptBehavior` - set to `dismiss` to automatically dismiss
all user prompts or set to `accept` to automatically accept all user prompts
* `loggingPrefs` - ghostdriver has two logs `browser` and `har`. The logs
default to `"OFF"`. follow the [DesiredCapabilities](https://github.com/SeleniumHQ/selenium/wiki/DesiredCapabilities#loggingpreferences-json-object)
documentation to enable the logs.
* PhantomJSDriver **Java-binding** Capabilities
* `phantomjs.binary.path` - Specify path to PhantomJS executable to use
* `phantomjs.ghostdriver.path` - Specify path to GhostDriver `main/src.js`
script to use; allows to use a different version of GhostDriver then the one
Expand All @@ -142,7 +134,7 @@ If you are planning to contribute, that is the PhantomJS you should use.

Here I show how to clone this repo and kick start the (Java) tests. You need
[Java SDK](http://www.oracle.com/technetwork/java/javase/downloads/index.html)
to run them (I tested it with Java 7, but should work with Java 6 too).
to run them. ghostdriver requires Java 1.8.

1. `git clone https://github.com/detro/ghostdriver.git`
2. Configure `phantomjs_exec_path` inside `ghostdriver/test/config.ini` to point at the build of PhantomJS you just did
Expand Down Expand Up @@ -189,17 +181,17 @@ Here follows the output of the `tree -hd -L 3` command, trimmed of files and "bu
Being GhostDriver a WebDriver implementation, it embeds the standard/default WebDriver Atoms to operate inside open
webpages. In the specific, the Atoms cover scenarios where the "native" PhantomJS `require('webpage')` don't stretch.

Documentation about how those work can be found [here](http://code.google.com/p/selenium/wiki/AutomationAtoms)
Documentation about how those work can be found [here](https://github.com/SeleniumHQ/selenium/wiki/Automation-Atoms)
and [here](http://www.aosabook.org/en/selenium.html).

How are those Atoms making their way into GhostDriver? If you look inside the `/tools` directory you can find a bash
script: `/tools/import_atoms.sh`. That script accepts the path to a Selenium local repo, runs the
[CrazyFunBuild](http://code.google.com/p/selenium/wiki/CrazyFunBuild) to produce the compressed/minified Atoms,
[CrazyFunBuild](https://github.com/SeleniumHQ/selenium/wiki/Crazy-Fun-Build) to produce the compressed/minified Atoms,
grabs those and copies them over to the `/src/third_party/webdriver-atoms` directory.

The Atoms original source lives inside the Selenium repo in the subtree of `/javascript`. To understand how the build
works, you need to spend a bit of time reading about
[CrazyFunBuild](http://code.google.com/p/selenium/wiki/CrazyFunBuild): worth your time if you want to contribute to
[CrazyFunBuild](https://github.com/SeleniumHQ/selenium/wiki/Crazy-Fun-Build): worth your time if you want to contribute to
GhostDriver (or any WebDriver, as a matter of fact).

One thing it's important to mention, is that CrazyFunBuild relies on the content of `build.desc` file to understand
Expand All @@ -209,7 +201,7 @@ The definition of the Atoms that GhostDriver uses lives at `/tools/atoms_build_d

Let's take this small portion of our `build.desc`:
```
js_deps(name = "deps",
js_library(name = "deps",
srcs = "*.js",
deps = ["//javascript/atoms:deps",
"//javascript/webdriver/atoms:deps"])
Expand All @@ -219,21 +211,21 @@ js_fragment(name = "get_element_from_cache",
function = "bot.inject.cache.getElement",
deps = [ "//javascript/atoms:deps" ])
js_deps(name = "build_atoms",
js_library(name = "build_atoms",
deps = [
...
"//javascript/webdriver/atoms:execute_script",
...
]
```
The first part (`js_deps(name = "deps"...`) declares what are the dependency of this `build.desc`: with that CrazyFunBuild knows
The first part (`js_library(name = "deps"...`) declares what are the dependency of this `build.desc`: with that CrazyFunBuild knows
what to build before fulfilling our build.

The second part (`js_fragment(...`) defines an Atom: the `get_element_from_cache` is going to be the name of
an Atom to build; it can be found in the module `bot.inject.cache` and is realised by the function named
`bot.inject.cache.getElement`.

The third part (`js_deps(name = "build_atoms"...`) is a list of the Atoms (either defined by something like the second
The third part (`js_library(name = "build_atoms"...`) is a list of the Atoms (either defined by something like the second
part or in one of the files we declared as dependency) that we want to build.

If you reached this stage in understanding the Atoms, you are ready to go further by yourself.
Expand Down
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.2.0
2.0.0
136 changes: 61 additions & 75 deletions binding/java/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ apply plugin: "java"
apply plugin: "idea"
apply plugin: "eclipse"
apply plugin: "maven"
apply plugin: "signing"

group "com.github.detro"

task wrapper(type: Wrapper) {
gradleVersion = "2.5"
Expand All @@ -38,15 +39,18 @@ task wrapper(type: Wrapper) {

repositories {
mavenCentral()
jcenter()
maven { url "https://jitpack.io" }
}

compileJava {
options.compilerArgs.add("-Xlint:unchecked")
options.compilerArgs.add("-Xlint:deprecation")
}

ext.seleniumVersion = "3.0.0"
project.archivesBaseName = project.name
project.version = "1.3.0"
project.version = "2.0.0"

ext.projectGroupId = "com.github.detro"
ext.projectArtifactId = "phantomjsdriver"
Expand All @@ -55,18 +59,15 @@ ext.projectArtefactDir = "jars/"
ext.projectMainClass = "org.openqa.selenium.phantomjs.PhantomJSDriver"
ext.projectCreator = "Ivan De Marino (https://github.com/detro)"

ext.seleniumVersion = "2.44.0"

dependencies {
["selenium-java", "selenium-remote-driver"].each {
compile "org.seleniumhq.selenium:$it:$seleniumVersion"
}
compile "org.seleniumhq.selenium:selenium-remote-driver:$seleniumVersion"
}

// Forces Java 6 compile source/target
// Forces Java 8 compile source/target
compileJava {
sourceCompatibility = 1.6
targetCompatibility = 1.6
sourceCompatibility = 1.8
targetCompatibility = 1.8
}

tasks.withType(JavaExec) {
Expand Down Expand Up @@ -140,75 +141,60 @@ artifacts {
archives sourceJar
}

// Sign artifacts
signing {
sign configurations.archives
}

// Upload archives to OSS Sonatype
//
// NOTE: requires you to first setup
// 1) ~/.gnupg/* with a PGP key to sign the artifacts
// 2) ~/.gradle/gradle.properties defining
//
// signing.keyId=<YOUR PGP KEY ID>
// signing.password=<PASSWORD TO PGP SECRET RING>
// signing.secretKeyRingFile=<FULLPATH TO PGP SECRET RING>
// ossrhUsername=<OSS Sonatype Username>
// ossrhPassword=<OSS Sonatype Password>
//
uploadArchives {
repositories {
mavenDeployer {
beforeDeployment {
MavenDeployment deployment -> signing.signPom(deployment)
}
// To specify a license in the pom:
install {
repositories.mavenInstaller {
pom.project {
name "PhantomJSDriver"
description """
PhantomJSDriver is a Java binding for the PhantomJS WebDriver, GhostDriver.
The binding is developed within the GhostDriver project, and distributed through public Maven repository
and Selenium official .zip package.
"""
groupId projectGroupId
artifactId projectArtifactId
version project.version
packaging "jar"
url "https://github.com/detro/ghostdriver"
inceptionYear "2012"

scm {
url "https://github.com/detro/ghostdriver"
connection "scm:git:[email protected]:detro/ghostdriver.git"
developerConnection "scm:git:[email protected]:detro/ghostdriver.git"
}

repository(url: "https://oss.sonatype.org/service/local/staging/deploy/maven2/") {
authentication(userName: ossrhUsername, password: ossrhPassword)
licenses {
license {
name "The BSD 2-Clause License"
url "http://opensource.org/licenses/BSD-2-Clause"
distribution "repo"
}
}

developers {
developer {
id "detro"
name "Ivan De Marino"
email "[email protected]"
url "http://ivandemarino.me"
roles {
role "Owner"
role "Developer"
}

pom.project {
name "PhantomJSDriver"
description """
PhantomJSDriver is a Java binding for the PhantomJS WebDriver, GhostDriver.
The binding is developed within the GhostDriver project, and distributed through public Maven repository
and Selenium official .zip package.
"""
groupId projectGroupId
artifactId projectArtifactId
version project.version
packaging "jar"
url "https://github.com/detro/ghostdriver"
inceptionYear "2012"

scm {
url "https://github.com/detro/ghostdriver"
connection "scm:git:[email protected]:detro/ghostdriver.git"
developerConnection "scm:git:[email protected]:detro/ghostdriver.git"
}

licenses {
license {
name "The BSD 2-Clause License"
url "http://opensource.org/licenses/BSD-2-Clause"
distribution "repo"
}
}

developers {
developer {
id "detro"
name "Ivan De Marino"
email "[email protected]"
url "http://ivandemarino.me"
roles {
role "Developer"
}
timezone "GMT"
}
}
timezone "GMT"
}
developer {
id "jesg"
name "Jason Gowan"
email "[email protected]"
url "http://github.com/jesg"
roles {
role "Developer"
}
timezone "America/Los_Angeles"
}
}
}
}
}
Loading

0 comments on commit 7cf96db

Please sign in to comment.