gpt4 book ai didi

angularjs - 在 AngularJS 端到端测试中使用 opportunity.js

转载 作者:行者123 更新时间:2023-12-02 22:47:23 28 4
gpt4 key购买 nike

我正在尝试为我的 e2e 测试生成一些随机数据。似乎我找到的唯一库是 chance.js 。但无法使其发挥作用。这是我到目前为止所尝试过的:

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.

});
});

但是如果我尝试

beforeEach(function(){

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

});
});

这就是我到目前为止所拥有的一切......有什么线索/想法吗?

最佳答案

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

npm install chance --save-dev

这会将 opportunity.js 作为节点模块安装在您的项目中。然后将其包含在您的规范中并实例化:

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

然后调用您的规范。例如:

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

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

希望有帮助...

关于angularjs - 在 AngularJS 端到端测试中使用 opportunity.js,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27571292/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com