0.1.6 • Published 9 years ago

elves v0.1.6

Weekly downloads
2
License
MIT
Repository
github
Last release
9 years ago

elves

Join the chat at https://gitter.im/ilife5/elves

An easy, lightweight, headless test tool for avalon.oniui。

Based on phantomJs, support mocha chai and jquery

elves

中文文档

Installation

install from npm

Use it as a command line tool.

npm install elves -g

If you only want to use it in a locally nodejs project.

npm install elves --save

Elves depends on Node.js and npm. Also make sure that phantomJs is installed.

Usage

Usage: 

    elves [options]
    elves [options] <config>
    elves [options] <caseUrl>
    elves [options] <caseUrl> <pageUrl>

Options:

    -h, --help                  output usage information
    -v, --version               output the version number
    -r, --remoteServer          take test on remote server
    -c, --configFile <path>     config file path. defaults to test/elves.config
    -a, --assertions <path>     assertions, defaults to chai
    -l, --localServer <string>  config localServer address, defaults to http://localhost:3000
    -g, --group <string>        runs a group of tests
    -t, --test <string>         runs a single test

hello world

First, we set up a page and case.

example/
└── hello world
    ├── helloworld.html
    └── helloworld.js

helloworld.html

<!DOCTYPE html>
<html>
<head lang="en">
    <meta charset="UTF-8">
    <title>Hello world</title>
</head>
<body>
    <p>hello world</p>
</body>
</html>

helloworld.js

var expect = chai.expect;

describe("Hello world", function() {
    it("#should contains 'hello world' in the p", function() {
        expect($("p").eq(0).text() == "hello world");
    })
});

Run the test

elves "example/hello world/helloworld.js" "example/hello world/helloworld.html"

The report

  Hello world
    ✓ #should contains 'hello world' in p 


    ✔ 1 test complete (5ms)

cases only

In some scenarios,we just want to test pure javascript cases without a page。We can be achieved through the following ways。

elves "example/case only/index.js"

Elves will open an empty page for running cases.

use config.json

We can also use a config file in test folder.

[
    {
        "caseUrl": "example/hello world/helloworld.js"
    }
]

Run

elves

Then we can get the reports.

simulate events and touch gestures

jQuery is integrated in Elves, and we can use it simulate events and touch gestures.

$("selector").simulate("click"); // event
$("selector").simulate("tap"); // gesture

support events:

  • click
  • mouse(over|out|down|up|move)
  • key(up|down|press)

support gestures(defination refered to Zepto.js(http://zeptojs.com/#Touch events) and Hammer.js):

  • tap
  • doubleTap
  • press(longTap)
  • swipe & swipe(Right|Left|Up|Down)

testing asynchronous code

It's the same to test with Mocha.Refered to Mocha.js. With elves, you can also delay your assertions.

it("should show press", function(done) {
    container.simulate("press")

    delay(done, function() {
        expect(content.text()).to.equal("press");
    }, 1000);
})

test on remote server

Elves also support test on remote server.

Create case

var expect = chai.expect;

describe("qunar", function() {
    it("#title should be 【去哪儿网】机票查询预订,酒店预订,旅游团购,度假搜索,门票预订-去哪儿网Qunar.com", function() {
        expect(document.title).to.equal("【去哪儿网】机票查询预订,酒店预订,旅游团购,度假搜索,门票预订-去哪儿网Qunar.com")
    });
});

Run

elves "example/remote server/remote server.js" "http://qunar.com" -r

Then we can get the reports.

  qunar
    ✓ #title should be 【去哪儿网】机票查询预订,酒店预订,旅游团购,度假搜索,门票预订-去哪儿网Qunar.com 


    ✔ 1 test complete (6ms)

assertions

Elves support changing assertions, includes chai and expect.

//test with expect
elves -a "expect"

reporters

Elves support changing reporters through change setupOptions

//setupOptions.js
if(typeof pageStatic === "undefined") {
    pageStatic = {};
}

pageStatic.mochaSetupOptions = {
    ui: "bdd",
    reporter: 'list',
    ignoreLeaks: true
};
elves -M setupOptions.js
0.1.6

9 years ago

0.1.5

9 years ago

0.1.4

9 years ago

0.1.3

9 years ago

0.1.2

9 years ago

0.1.1

9 years ago

0.1.0

9 years ago

0.0.9

9 years ago

0.0.8

9 years ago

0.0.7

9 years ago

0.0.6

9 years ago

0.0.5

9 years ago

0.0.4

9 years ago

0.0.3

9 years ago

0.0.2

9 years ago

0.0.1

9 years ago