Giter Site home page Giter Site logo

doffy's Introduction

doffy

CircleCI npm GitHub stars GitHub license

Doffy a headless browser automation library with easy-use API.

Doffy provide a few simple methods to simulate user action like goto click fill, which are useful for headless web testing and crawling.

Feature

  • Base on chrome headless, use Chrome Devtools Protocol, while Nightmare base on Electron and Casper is base on PhantomJS.
  • All Promise, all API of Doffy return a Promise

QuickStart

install chrome headless

Mac: chrome headless is shipped on chrome-canary, install: https://www.google.com/chrome/browser/canary.html

Linux: chrome headless is also shipped on chrome 59. so you can install chrome 59 to use headless mode.

# https://askubuntu.com/questions/79280/how-to-install-chrome-browser-properly-via-command-line
sudo apt-get install libxss1 libappindicator1 libindicator7
wget https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb
sudo dpkg -i google-chrome*.deb  # Might show "errors", fixed by next line
sudo apt-get install -f

install doffy

# wait for npm publish

page automation:

import Doffy from '../src/doffy';
const doffy = new Doffy();

(async() => {
  await doffy.init();
  await doffy.goto('https://github.com/login');
  await doffy.screenshot('result/01-homepage.jpeg');
  await doffy.fill('#login_field', 'doffyjs');
  await doffy.fill('#password', 'doffy2017');
  await doffy.screenshot('result/02-fillaccount.jpeg');
  await doffy.click('[name="commit"]');
  await doffy.wait('.avatar');
  let isLogin = await doffy.visible('.avatar')
  isLogin && console.log('======== login success ========');
  await doffy.end(true);
})();

run mocha test

import Doffy from '../src/doffy';

const expect = require('chai').expect;
const doffy = new Doffy();

describe('test example', function() {

  before(async function() {
    try {
      await doffy.init();
      console.log('======== test begin ========');
    } catch(err) {
      console.error('error happen while init doffy', err);
    }
  });

  after(async function() {
    // runs after all tests in this block
    await doffy.end(true);
    console.log('====== test end ======');
  });

  it('open home page', async function() {
    await doffy.goto('https://www.baidu.com');
    let ret = await doffy.title();
    expect(ret.result.value).to.be.equal("百度一下,你就知道");
    await doffy.screenshot('temp/01.jpeg');
  });

  it('open signin dialog', async function() {
    await doffy.fill('#kw', 'github');
    await doffy.click('#su');
    let firstResult = await doffy.evaluate(() => {
      return document.querySelectorAll('.result h3')[0].innerText;
    });
    expect(firstResult).to.be.equal('GitHub · Build software better, together.官网');
    await doffy.screenshot('temp/02.jpeg');
  });

});

API

see wiki page => API doc please wait...

ChangeLog

2017.05.12

  • New

LICENSE

MIT

doffy's People

Contributors

qieguo2016 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 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.