In order to pass a string value from the function editPage.CreateEntity();
, you can use that value in multiple test cases by assigning it to the variable entityName
. You are able to retrieve the value by setting up the test case as follows:
fit('Test Case', async () => {
await editEntityPage.CreateEntity("Automation Entity: ", "California").then(function(name){
console.log(name);
return entityName = name;
});
await entity.SearchAndClickEntity(entityName);
});
However, if you want to obtain this value right at the beginning without using the beforeEach() method, you can structure your code like this:
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);
});
Note that when you attempt to access the value from the console.logs
, you might encounter the following output:
Testing Start:
Promise { <pending> }
{}