【taiko】一个通过 js 代码操作 chrome 浏览器并能保存为一段 js 代码的工具

luoyjx · 2018-09-13 12:22 · 21次阅读


Getting started

$ npm install -g taiko

On Windows, make sure that the location %AppData%\npm(or wherever npm ends up installing the module on your Windows flavor) is present in PATH environment variable.

On Linux, install taiko to a NODE_PATH with executable permission.


Command line

Use the Read–eval–print Loop to record a script.

$ taiko

> openBrowser()
✔ Browser and page initialized

> goto("http://todomvc.com/examples/react/#/");
✔ Navigated to url "http://todomvc.com/examples/react/#/"

> write("automate with taiko");
✔ Wrote automate with taiko into the focused element.

> press("Enter");
✔ Pressed the Enter key

> click(checkBox(near("automate with taiko")));
✔ Clicked checkbox Near automate with taiko

> .code
const { openBrowser, goto, write, press, near, checkBox, click } = require('taiko');

(async () => {
    await openBrowser({headless:false});
    await goto("http://todomvc.com/examples/react/#/");
    await write("automate with taiko");
    await press("Enter");
    await click(checkBox(near("automate with taiko")));

> .code code.js

Running a taiko script

$ taiko code.js

As a Module

$ npm install <path_to_taiko_repo> --save
$ node code.js

Install from source

$ git clone https://github.com/getgauge/taiko.git
$ npm install -g <path_to_taiko_repo>

Run tests

Test are written using gauge. Install and setup gauge following instructions here

git clone https://github.com/getgauge-examples/js-taiko.git
cd js-taiko
npm install

gauge run specs or gauge run specs --tags=\!knownIssue (to ignore specs for knownissue)