将全局变量存储在用于量角器测试的单独文件中



我正在尝试为量角器测试创建一个单独的库存文件,我可以在其中存储所有可重用的变量以供不同的测试脚本使用。示例变量列表称为 Vars.js规范应从此文件导入变量并使用这些变量。但是,此操作失败,如下所示。这种方法真的可以用于存储可重用的变量吗?我实际上可以在 conf.js 之外为量角器测试创建一个单独的库存文件吗?

Vars.js 具有以下内容:

"use strict";
exports.config = {
function() {
    global.loginMain = 'https://mytestsite.com/auth/login';
    global.TestText = 'I am the test Text';
}
};

规范文件如下:

require ('./Vars.js')
require('..\waitAbsent.js')
require("../node_modules/jasmine-expect/index.js")
describe('Vairables Import Test', function() {
console.log(global.loginMain);
console.log(global.TestText);
browser.get(global.loginMain);
it('Text Validation', function(){
expect(browser.getCurrentUrl()).toEqual('https://mytestsite.com/auth/login')

})
});

日志

    [10:55:29] I/local - Selenium standalone server started at http://192.168.1.187:51256/wd/hub
undefined
undefined
Started
(node:17800) [DEP0005] DeprecationWarning: Buffer() is deprecated due to security and usability issues. Please use the Buffer.alloc(), Buffer.allocUnsafe(), or Buffer.from() methods
instead.
F
Failures:
1) Vairables Import Test encountered a declaration exception
  Message:
    TypeError [ERR_INVALID_ARG_TYPE]: The "url" argument must be of type string. Received type undefined
  Stack:
    TypeError [ERR_INVALID_ARG_TYPE]: The "url" argument must be of type string. Received type undefined
        at Url.parse (url.js:152:11)
        at urlParse (url.js:146:13)
        at Url.resolve (url.js:661:29)
        at Object.urlResolve [as resolve] (url.js:657:40)
        at ProtractorBrowser.get (C:FCPS_IFCPSnode_modulesprotractorbuiltbrowser.js:653:17)
        at Suite.<anonymous> (C:FCPS_IFCPSTestBed_ScriptsTestBed.js:10:13)
        at Object.<anonymous> (C:FCPS_IFCPSTestBed_ScriptsTestBed.js:5:1)
1 spec, 1 failure

更新:修订后的 Vars.js我使用了如下所示的参数也返回了相同的失败。

"use strict";
exports.config = {
params: {
    loginMain: 'https://dss-esy.insystechinc.com/auth/login',
    TestText : 'I am the test Text',
}
};

以下方法应该适合您。

.js

exports.config = {
  framework: 'jasmine',
  seleniumAddress: 'http://localhost:4444/wd/hub',
  specs: ['app.js'],
  onPrepare: async() => {
      global.globalVariables = require('./globalVariables');
  }
};

应用.js

describe('desribe the test', () => {
  it('the it', async () => {
      console.log(globalVariables.loginMain);
      console.log(globalVariables.TestText);
  })
})

全局变量.js

module.exports = {
  loginMain :'https://mytestsite.com/auth/login',
  TestText : 'I am the test Text'
}

最新更新