我需要在onPrepare阶段做更多的事情。对于这个启动代码,我需要一些外部库。如何为onPrepare函数包含一些文件?
我的应用程序需要浏览器中的websql数据库,所以我需要添加一些fixtures:创建表并在其中添加一些测试数据。我为websql db编写了一些简单的CRUD查询的小库。因此,我不想编写原始javascript来创建表格和附加数据。
我是否有任何推荐方法可以实现它?
答案 0 :(得分:1)
添加外部库我只是做
var env = require('./environment.js');
exports.config = {
seleniumAddress: env.seleniumAddress,
// Spec patterns are relative to this directory.
specs: [
'onPrepare/*_spec.js'
],
capabilities: env.capabilities,
baseUrl: env.baseUrl,
onPrepare: function() {
var UntrustedCertOverride = require('./untrusted-cert-override.js');
var OracleSsoPage = require('./claimsoverview/oracle-sso.po.js');
//Setup a global variable for using the non-angular driver
global.dvr = browser.driver;
dvr.get('/url');
UntrustedCertOverride(dvr);
var oracleSsoPage = new OracleSsoPage(dvr);
//etc.....
},
};
或者,如果你不想要你的onPrepare:做得很乱这个
var env = require('./environment.js');
// Configuration using a string in onPrepare to load a file with code to
// execute once before tests.
exports.config = {
seleniumAddress: env.seleniumAddress,
// Spec patterns are relative to this directory.
specs: [
'onPrepare/*_spec.js'
],
capabilities: env.capabilities,
baseUrl: env.baseUrl,
onPrepare: 'onPrepare/startup.js'
};
可以在此处找到更多示例和最佳做法:https://github.com/angular/protractor/tree/a368de0b74db35a90d9a2d8aa48a7e57a45a2aa7/spec