https://github.com/qieguo2016/doffy
a web auto run lib base on chrome headless
https://github.com/qieguo2016/doffy
casper chrome-headless crawler nightmare uitest
Last synced: 3 months ago
JSON representation
a web auto run lib base on chrome headless
- Host: GitHub
- URL: https://github.com/qieguo2016/doffy
- Owner: qieguo2016
- License: mit
- Created: 2017-05-11T15:26:32.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2017-06-03T13:33:10.000Z (over 8 years ago)
- Last Synced: 2025-06-19T05:50:56.229Z (4 months ago)
- Topics: casper, chrome-headless, crawler, nightmare, uitest
- Language: JavaScript
- Size: 28.3 KB
- Stars: 13
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# doffy
[](https://github.com/qieguo2016/doffy) [](https://www.npmjs.com/package/doffy) [](https://github.com/qieguo2016/doffy/stargazers) [](https://raw.githubusercontent.com/qieguo2016/doffy/master/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](#feature)
* [QuickStart](#quickstart)
* [API](#api)
* [ChangeLog](#changelog)
* [Contribute](#contribute)## Feature
- Base on chrome headless, use Chrome Devtools Protocol, while [Nightmare](https://github.com/segmentio/nightmare) base on [Electron](http://electron.atom.io/) and [Casper](https://github.com/casperjs/casperjs) is base on [PhantomJS](https://github.com/ariya/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](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.
```bash
# 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
```bash
# wait for npm publish
```### page automation:
```js
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
```js
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