代码之家  ›  专栏  ›  技术社区  ›  matandked

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

  •  0
  • matandked  · 技术社区  · 7 年前

    我在准备端到端的测试 Page Object Model 模式。我用打字机,用量角器写测试。

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

    // 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`
    

    有没有可能不重复那些 imports const ?

    我试过 require 包含它们的单独文件,但似乎它们不包含在我的文件中。也不可能包括 Export 修饰语 import

    1 回复  |  直到 7 年前
        1
  •  2
  •   Farmijo    7 年前

    黄瓜形态 文件,您可以使用 准备() 函数将这些依赖项添加到节点全局对象中,并可对其进行访问。 我只建议EC和其他递归依赖项使用此方法,而不是页面对象 . 我用这样的东西:

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