使用AngularJS端到端的测试里面chance.js [英] Using chance.js inside AngularJS end to end tests

查看:180
本文介绍了使用AngularJS端到端的测试里面chance.js的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想为我的端到端测试一些随机数据。看来我找到的唯一库是 chance.js 。但不能让它工作。这是我到目前为止已经试过:

I'm trying to generate some random data for my e2e tests. Seems that the only library I found was chance.js. But can't make it works. This is what I've tried so far:

describe('In the login page', function () {
  var chance = new Chance(); // ReferenceError: Chance is not defined

}

然后添加

beforeEach(function(){

        browser.executeScript(
            function() {
                return chance;
            }).then(function(_chance){
                chance = _chance; //It returns an object, but can't use any of the methods.

            });
        });

但是,如果我尝试

But if I try

beforeEach(function(){

        browser.executeScript(
            function() {
                return chance.email(); //Note this line here
            }).then(function(_chance){
                chance = _chance; //It returns an email

            });
        });

这就是所有我到目前为止...任何线索/想法?

Thats all I have so far... any clue/idea?

推荐答案

首先,在您的项目安装chance.js:

First, install chance.js in your project:

npm install chance --save-dev

此安装chance.js作为您的项目的节点模块。然后包括在您的规格和实例:

This installs chance.js as a node module in your project. Then include it in your spec and instantiate:

var chance = require('../node_modules/chance').Chance();

然后在你打电话规范。例如:

Then call in your spec. For example:

it('should add a new friend', function() {
    var friendName = chance.string()
    friendPage.addFriend(friendName);

    expect(friendPage.inResults(friendName)).toBeTruthy();
});

希望帮助...

Hope that helps...

这篇关于使用AngularJS端到端的测试里面chance.js的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆