[英]Set global variable Protractor
I'm trying to pass a string value from my function editPage.CreateEntity();
我正在尝试从我的 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: ,我需要在变量
entityName
下的大多数测试用例中使用该值,如果我像这样设置测试用例,我可以获得该值:
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但是我怎样才能从一开始而不是
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.附言。 when I try to get the value from the
console.logs
I get this:当我尝试从
console.logs
获取值时,我得到了这个:
Testing Start:
Promise { <pending> }
{}
Use beforeAll()
to set this variable.使用
beforeAll()
设置此变量。 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);
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.