将全局变量存储在单独的文件中以进行量角器测试 [英] Storing global variable in a separate file for Protractor Tests

查看:84
本文介绍了将全局变量存储在单独的文件中以进行量角器测试的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I am trying to create a separate inventory file for Protractor Test where I can store all the reusable variable to be used by different test scrips. The sample Variable list is called Vars.js and the specs should import the variables from this file and consume those. However, this fails as shown below. Can this approach actually be used for storing reusable variables? Can I actually create a separate inventory file for protractor tests outside of conf.js?

Vars.js具有以下内容:

Vars.js has the following content :

"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_I\FCPS\node_modules\protractor\built\browser.js:653:17)
        at Suite.<anonymous> (C:\FCPS_I\FCPS\TestBed_Scripts\TestBed.js:10:13)
        at Object.<anonymous> (C:\FCPS_I\FCPS\TestBed_Scripts\TestBed.js:5:1)

1 spec, 1 failure

更新:我使用如下所示的params的经过修订的Vars.js也返回了相同的失败.

Update: a revised Vars.js where I used params as shown below also return the same failure.

"use strict";

exports.config = {

params: {

    loginMain: 'https://dss-esy.insystechinc.com/auth/login',
    TestText : 'I am the test Text',

}
};

推荐答案

以下方法应该适合您.

conf.js

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

app.js

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

globalVariables.js

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

这篇关于将全局变量存储在单独的文件中以进行量角器测试的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆