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> }
{}
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);
});
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.