我有一个JSON,每个键都包含一个字符串数组,我添加了两个循环
- 一个获取所有密钥
- 第二个针对键获取数组
我正在使用第二个循环来测试数组中的每个值。但现在发生的是,它从未进入it
块,也在before
上抛出错误
Cannot read value of the function(waitForReadiness) from null (resultPage)
代码在这里:
//SearchData is the JSON
for (const key of allKeys) {
const valuesArray: string[] = (SearchData as any)[key];
for (const value of valuesArray) {
let someURL = new UrlHandler().SearchResultUrl(destination, 30, 35);
let resultPage: ResultPageMarketing = new ResultPageMarketing();
before(async() => {
someURL = someURL.concat(`?${key}=${value}`);
resultPage = await BrowserHelper.open(someURL) as ResultPageMarketing;
await resultPage.waitForReadiness();
await resultPage.waitForResultsListContainer();
})
it('should have appended filter option applied and selected HRP')
.test(async () => {
const url: boolean = (await BrowserHelper.getCurrentUrl()).includes(`param=${key}=${value}`);
assert.isTrue(url, `Property Filter '${key}=${value}' wasn't appended to URL`);
});
it('should filter results according to the selected option')
.test(async () => {
const hasResults: boolean = await resultPage.hasResults();
assert.isTrue(hasResults, `Page doesn't have any results against property filter '${key}=${value}'`);
});
}
}
这些值在浏览器中正确附加,但页面不会等待加载和附加下一个值,因此不会运行测试。
我正在使用量角器、chai和摩卡
尝试使用
let flow = protractor.promise.controllFlow();
flow.execute(function(){
for(){
//your codeenter code here
}
})