GithubHelp home page GithubHelp logo

ismlsmile / ui4j Goto Github PK

View Code? Open in Web Editor NEW

This project forked from gitter-badger/ui4j

0.0 2.0 0.0 1.45 MB

Web Automation for Java

License: MIT License

Java 78.68% HTML 2.78% JavaScript 18.53%

ui4j's Introduction

Ui4j

License Coverage Status

Talk with us and ask questions via Gitter

![Gitter](https://badges.gitter.im/Join Chat.svg)

Ui4j is a web-automation library for Java. It is a thin wrapper library around the JavaFx WebKit Engine, and can be used for automating the use of web pages and for testing web pages.

Supported Java Versions

Oracle Java 8.

Both the JRE and the JDK are suitable for use with this library.

Licensing

Ui4j is released under the terms of the MIT License (MIT).

You are free to use Ui4j or any of its constituent parts in any other project (even commercial projects) so long as its copyright headers are left intact.

Support

![JProfiler] (https://www.ej-technologies.com/images/product_banners/jprofiler_large.png)

Ui4j is optimized using JProfiler.

Thanks so much to ej-technologies to let us to use the JProfiler with an open source project license.

Stability

This library is suitable for use in production systems.

If you have found a defect or you want to request a feature enhancement an issue report is the way to bring the attention to the Ui4j Community.

Integration with Maven

To use the official release of Ui4j, please use the following snippet in your pom.xml

Add the following to your POM's <repositories> tag:

<repository>
      <id>jitpack.io</id>
      <url>https://jitpack.io</url>
</repository>

then add the following dependency:

<dependency>
    <groupId>com.github.ui4j.ui4j</groupId>
    <artifactId>ui4j-all</artifactId>
    <version>2.2.5</version>
</dependency>

Using Ui4j without Maven

If you use Ui4j without Maven, download pre built jar file.

Supported Platforms

Ui4j has been tested under Windows 8.1 and Ubuntu 14.04, but should work on any platform where a Java 8 JRE or JDK is available.

Headless Mode

Ui4j can be run in "headless" mode using Xfvb or with using Monocle.

Headless Mode with Xfvb

Sample configuration for ubuntu running with headless mode:

  1. First install these packages: sudo apt-get install xvfb x11-xkb-utils libxrender-dev libxtst-dev libgtk2.0-0

  2. Then start the xvfb nohup xvfb :99 -ac &

  3. Then export the DISPLAY variable export DISPLAY=:99.0

Headless Mode with Monocle

  1. Download and add the maven dependency of latest openjfx-monocle
  2. Add -Dui4j.headless Java system parameter from command line or with using api System.setProperty("ui4j.headless", "true");

Logging

Both simple logger for java (SLF4J) and Java utility logger (JUL) is supported. If slf4j is available on classpath com.ui4j.api.util.LoggerFactory use slf4j else java utility logger is used.

CSS Selector Engine

Ui4j use W3C selector engine which is default selector engine of WebKit. Alternatively Sizzle selector engine might be used. Sizzle is the css selector engine of JQuery and it supports extra selectors like :has(div), :text, contains(text) etc. Check the Sizzle.java for using sizzle with Ui4j.

Usage Examples

Here is a very basic sample program that uses Ui4j to display a web page with a "hello, world!" message. See the ui4j-sample project for more sample code snippets.

package com.ui4j.sample;

import com.ui4j.api.browser.BrowserEngine;
import com.ui4j.api.browser.BrowserFactory;
import com.ui4j.api.browser.Page;

public class HelloWorld {

    public static void main(String[] args) {
        // get the instance of the webkit
        BrowserEngine browser = BrowserFactory.getWebKit();

        // navigate to blank page
        Page page = browser.navigate("about:blank");

        // show the browser page
        page.show();

        // append html header to the document body
        page.getDocument().getBody().append("<h1>Hello, World!</h1>");
    }
}

Here is another sampe code that list all front page news from Hacker News.

package com.ui4j.sample;

import static com.ui4j.api.browser.BrowserFactory.getWebKit;

import com.ui4j.api.browser.Page;

public class HackerNews {

    public static void main(String[] args) {

        try (Page page = getWebKit().navigate("https://news.ycombinator.com")) {
            page
                .getDocument()
                .queryAll(".title a")
                .forEach(e -> {
                    System.out.println(e.getText().get());
                });
        }
    }
}

Building Ui4j

mvn install

Getting help and getting involved

Please do not hesitate to submit pull requests. We are happy to accept documentation and sample code contributions.

FAQ

How can i set the user agent string?

See UserAgent.java sample.

How can i execute javascript?

See JavaScriptExecution.java sample.

How can i handle browser login, prompt or confirmation dialog?

See DialogTest.java for custom handlers or use default handlers from Dialogs.java.

What is the easiest way clear all input elements?

Use clear method of the Form class.

Donations

Donations are accepted via Amazon.

Ui4j Amazon Wishlist

ui4j's People

Contributors

mikekaufman avatar mwberry avatar ruimateus avatar webfolderio avatar

Watchers

James Cloos avatar  avatar

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.