【问题标题】:Protractor tests - how to define import and consts once instead of repeating them in each test specification file?量角器测试 - 如何定义一次导入和常量,而不是在每个测试规范文件中重复它们?
【发布时间】:2019-11-06 00:41:17
【问题描述】:

我正在尝试使用Page Object Model 模式准备端到端测试。我使用 Protractor 在 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

【问题讨论】:

    标签: typescript protractor


    【解决方案1】:

    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');
     },
    ...
    

    【讨论】:

    猜你喜欢
    • 2016-04-18
    • 1970-01-01
    • 2018-12-09
    • 1970-01-01
    • 2019-07-31
    • 1970-01-01
    • 1970-01-01
    • 2021-12-10
    • 2022-07-21
    相关资源
    最近更新 更多