是否可以创建用于每个规格测试的功能,例如conf.js
文件中的登录功能,或者直接从sendKeys
的{{1}}到conf.js
的登录功能。
答案 0 :(得分:1)
通过nodejs语法,它支持如下操作:
// conf.js
exports.config = {
// put config at here as usual
};
exports.login = function(username, password) {
browser.get('');
element.sendKeys('');
};
// spec.js
var login = require('./conf.js').login;
// actually, you can move the login function to another .js file to keep
// conf.js more dedicated on configuration purpose.
describe("A spec (with setup and tear-down)", function() {
it('', function(){
login('username', 'password')
});
});
但这不是一个好习惯。因为主测试框架支持在每个测试用例之前执行某些操作。对于茉莉花,它提供beforeEach
:
describe("A spec (with setup and tear-down)", function() {
var foo;
beforeEach(function() {
foo = 0;
foo += 1;
});
afterEach(function() {
foo = 0;
});
it("is just a function, so it can contain any code", function() {
expect(foo).toEqual(1);
});
it("can have more than one expectation", function() {
expect(foo).toEqual(1);
expect(true).toEqual(true);
});
});
最后,我看不到您需要做的好处/优点。