【问题标题】:Set global variable Protractor设置全局变量 Protractor
【发布时间】:2020-07-23 11:31:33
【问题描述】:

我正在尝试从我的函数editPage.CreateEntity(); 传递一个字符串值,我需要在变量entityName 下的大多数测试用例中使用该值,如果我设置像这样的测试用例:

  fit('Test Case', async () => {
        await editEntityPage.CreateEntity("Automation Entity: ", "California").then(function(name){
           console.log(name);
           return entityName = name;  
        });
        await entity.SearchAndClickEntity(entityName);
    });

但是我怎样才能从一开始就得到这个值但是 NOT beforeEach() 测试用例

describe('Test Suite', () => {
        var editPage = require('../pathtofile.js');
        var entityName = editPage.CreateEntity("Automation Entity: ", "California").then(function(name){
            return name;
        });
        console.log("Testing Start:");
        console.log(entityName);
        console.log(JSON.stringify(entityName));

    beforeEach(async function(){
        await browser.waitForAngularEnabled(false);
    });

    it('Test Case', async () => {
        await entity.SearchAndClickEntity(entityName);
    });

ps。当我尝试从console.logs 获取值时,我得到了这个:

Testing Start:
Promise { <pending> }
{}

【问题讨论】:

标签: javascript selenium automation protractor


【解决方案1】:

使用beforeAll() 设置此变量。例如

describe('Test Suite', () => {
  var entityName = '';
  beforeAll(async function(){
    //you might need to await this such as "entityName = await editPage.CreateEntity..."
    entityName = editPage.CreateEntity("Automation Entity: ", "California").then(function(name){
        return name;
    });
  });
  beforeEach(async function(){
    await browser.waitForAngularEnabled(false);
  });

  it('Test Case', async () => {
    await entity.SearchAndClickEntity(entityName);
  });

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-07-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多