Giter Site home page Giter Site logo

klieber / phantomjs-maven-plugin Goto Github PK

View Code? Open in Web Editor NEW
63.0 6.0 31.0 1.82 MB

A maven plugin for installing the phantomjs binary on your system automatically.

Home Page: http://klieber.github.io/phantomjs-maven-plugin

License: MIT License

Shell 0.43% JavaScript 0.38% Groovy 2.62% HTML 0.08% Java 96.49%
phantomjs java junit-test maven-plugin

phantomjs-maven-plugin's Introduction

phantomjs-maven-plugin

This project is no longer being actively maintained. This aligns with the announcement that the PhantomsJS is no longer in active development. Please consider using Headless Chrome as an alternative. Thank you everyone for your support!

Build Status Coverage Status Maven Central Stories in Ready Flattr this git repo

A maven plugin for installing the phantomjs binary on your system automatically. You no longer need to have phantomjs pre-installed on your CI server or development workstation in order to use it as part of your build. Just add the following to your build:

<project>
  ...
  <!-- phantomjs-maven-plugin needs maven 3.1+ -->
  <prerequisites>
    <maven>3.1</maven>
  </prerequisites>
  ...
  <build>
    <plugins>
      <plugin>
        <groupId>com.github.klieber</groupId>
        <artifactId>phantomjs-maven-plugin</artifactId>
        <version>${phantomjs-maven-plugin.version}</version>
        <executions>
          <execution>
            <goals>
              <goal>install</goal>
            </goals>
          </execution>
        </executions>
        <configuration>
          <version>1.9.7</version>
        </configuration>
      </plugin>
    </plugins>
 </build>
 ...
</projects>

The plugin also makes the property phantomjs.binary available after it installs phantomjs so that you can use it to configure other maven plugins that use phantomjs or so that it can be used in your JUnit testing.

Example using with jasmine-maven-plugin:

<project>
  ...
  <build>
    <plugins>
      <plugin>
        <groupId>com.github.klieber</groupId>
        <artifactId>phantomjs-maven-plugin</artifactId>
        <version>${phantomjs-maven-plugin.version}</version>
        <executions>
          <execution>
            <goals>
              <goal>install</goal>
            </goals>
          </execution>
        </executions>
        <configuration>
          <version>1.9.7</version>
        </configuration>
      </plugin>
      <plugin>
        <groupId>com.github.searls</groupId>
        <artifactId>jasmine-maven-plugin</artifactId>
        <version>${jasmine-maven-plugin-version}</version>
        <executions>
          <execution>
            <goals>
              <goal>test</goal>
            </goals>
            <configuration>
              <webDriverClassName>org.openqa.selenium.phantomjs.PhantomJSDriver</webDriverClassName>
              <webDriverCapabilities>
                <capability>
                  <name>phantomjs.binary.path</name>
                  <value>${phantomjs.binary}</value>
                </capability>
              </webDriverCapabilities>
            </configuration>
          </execution>
        </executions>
      </plugin>
    </plugins>
  </build>
 ...
</projects>

Example using in a JUnit test:

<project>
  ...
  <build>
    <plugins>
      <plugin>
        <groupId>com.github.klieber</groupId>
        <artifactId>phantomjs-maven-plugin</artifactId>
        <version>${phantomjs-maven-plugin.version}</version>
        <executions>
          <execution>
            <goals>
              <goal>install</goal>
            </goals>
          </execution>
        </executions>
        <configuration>
          <version>1.9.7</version>
        </configuration>
      </plugin>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-surefire-plugin</artifactId>
        <version>2.17</version>
        <configuration>
          <systemPropertyVariables>
            <phantomjs.binary>${phantomjs.binary}</phantomjs.binary>
          </systemPropertyVariables>
        </configuration>
      </plugin>
    </plugins>
  </build>
 ...
</projects>

Then your JUnit test can access it like this:

package org.example;

import org.junit.Test;
import java.io.File;

import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;

public class ExampleTest {

  @Test
  public void shouldHavePhantomJsBinary() {
    String binary = System.getProperty("phantomjs.binary");
    assertNotNull(binary);
    assertTrue(new File(binary).exists());
  }

}

The plugin can also execute phantomjs scripts for you as well. The following downloads phantomjs automatically if it isn't already present on the system and then executes the script hello.js with the argument Bob (see full example here):

<project>
  ...
  <build>
    <plugins>
      <plugin>
        <groupId>com.github.klieber</groupId>
        <artifactId>phantomjs-maven-plugin</artifactId>
        <version>${phantomjs-maven-plugin.version}</version>
        <executions>
          <execution>
            <goals>
              <goal>install</goal>
              <goal>exec</goal>
            </goals>
          </execution>
        </executions>
        <configuration>
          <version>1.9.7</version>
          <checkSystemPath>true</checkSystemPath>
          <script>hello.js</script>
          <arguments>
            <argument>Bob</argument>
          </arguments>
        </configuration>
      </plugin>
    </plugins>
 </build>
 ...
</projects>

More documentation can be found on the plugin site: http://klieber.github.io/phantomjs-maven-plugin

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.