量角器测试 - 如何定义一次导入和常量,而不是在每个测试规范文件中重复它们?



我正在尝试使用页面对象模型模式准备端到端测试。我用 TypeScript 编写我的测试,使用量角器。

我注意到每个测试规范文件的前几行看起来非常相似:

// repeated in almost every test spec file
import { protractor, browser, element, by, promise } from 'protractor';
const EC = protractor.ExpectedConditions;
const until = protractor.until;
// this is changing from test to test
const SomePage = require('./pages/99-SomePage');
// code with `describe` and `it`

有没有可能不重复这些importsconst

我试图require包含它们的单独文件,但似乎它们不包含在我的文件中。也无法包含Export修饰符来import

cucumber.conf文件上,您可以使用onPrepare((函数将这些依赖项添加到节点全局对象中,以便随时访问。我只建议对EC和其他循环依赖项执行此操作,而不是针对页面对象。我使用这样的东西:

...,
onPrepare: function(){
global.EC = protractor.ExpectedConditions;
global.until = protractor.until;
var Logger = require('./Logger.js');
global.logger = new Logger();
global.data = require('./test.data.json');
},
...

最新更新