问题描述
我的代码如下
describe("Smoke-Test-",function() {
beforeAll(async function() {
getSteps = await specGenerator.execute(); //value is returned properly here
return getSteps //this returns an array object
});
beforeAll(async function () {
const remote = launch.command;
return page = po.init(remote)
.maximizeWindow()
.get(url)
.sleep(2000);
});
testRunner(getSteps) `//I want to use return value in function and call spec below. Is this possible? Execute function should be run as per the count`
Here getSteps returns Number.
function testRunner(count) {
it('test',async function () {
for(var j=0;j< count;j++)
{
execute()
}
});
}
预期:要从beforeAll中获取返回值并在函数中使用它来调用或触发规范。
实际:返回的值不能在beforeAll之外访问。
更新:
it('test',async function () {
console.log(getSteps) //prints value as I moved inside it as suggested
testRunner(getSteps) //this should trigger testRunner function
}
但是失败并出现错误,
Error: 'it' should only be used in 'describe' function
我们如何从其他规范中触发一个规范?
解决方法
运行量角器时,它将拾取在config中指定的规范文件,并建立describe
,it
,beforeAll
和afterAll
块的队列。重要的信息是在浏览器启动之前发生的。
看这个例子
let conditionIsTrue; // undefined
it('name',() => {
conditionIsTrue = true;
})
if (conditionIsTrue) { // still undefined
it('name',() => {
})
}
到量角器到达if()
语句时,conditionIsTrue
的值仍为undefined
。当浏览器启动时(稍后),但可能不会在其内部覆盖它,但在构建队列时则不会覆盖它。所以它跳过了。