0

I'm trying to pass a string value from my function editPage.CreateEntity();, I need to use that value on most of my test cases under the variable entityName, I'm able to get the value if I set the test case like this:

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

but how can I do it to get this value from the begining but NOT beforeEach() test case

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. when I try to get the value from the console.logs I get this:

Testing Start:
Promise { <pending> }
{}
Alan Díaz
  • 43
  • 1
  • 8

1 Answers1

0

Use beforeAll() to set this variable. For example

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);
  });
Ben Mohorc
  • 694
  • 6
  • 16