gpt4 book ai didi

javascript - 非 Angular 网站 - 检查结果已排序

转载 作者:行者123 更新时间:2023-11-28 07:17:40 25 4
gpt4 key购买 nike

请问如何验证非 Angular 网站搜索结果按排序顺序显示?

我试图捕获数组中的所有列出的项目,然后验证它们是否按排序顺序排列。但是无法将测试结果推送到数组中。请您查看以下代码片段并就此提出建议。

//element locator for all funds.
var fundingOpportunityList = element.all(by.css('#search-results-list li a article h3'));

//page object
var fundingOpportunityPage = function(){

this.checkFundingItemsSorted = function() {
//temporary array to store results
var temp = [];

//check 10 funding opportunities shown in first pagination tab
fundingOpportunityList.then(function(items) {
//Following section working i.e. 10 items shown in each page.
expect(items.length).toBe(10);

});

//This section is not working, unable to save results in Array
fundingOpportunityList.each(function(elem,index){
//retrieve all funding opportunities and store in an array
elem.getText().then(function (text) {
expect(text).toMatch('junk'); //this line added for debugging
temp.push(text); //trying to push text into an array

});


});

expect(temp.length).toBe(10); //length shown as 0
expect(temp).toEqual('hello');

}

以下是测试结果输出。

1) Test website - funding opportunity list - Check Funding list is displayed in sorted order Message: Expected 0 to be 10. Stacktrace: Error: Expected 0 to be 10.

2) test website - funding opportunity list - Check Funding list is displayed in sorted order Message: Expected [ ] to equal 'hello'. Stacktrace: Error: Expected [ ] to equal 'hello'. 3) test website - funding opportunity list - Check Funding list is displayed in sorted order Message: Expected '15 for 2015' to match 'junk'. 4) test website - funding opportunity list - Check Funding list is displayed in sorted order Message: Expected '3Rs Prize' to match 'junk'. 5) test website - funding opportunity list - Check Funding list is displayed in sorted order Message: Expected '3Rs Research Funding Scheme - Project Grants' to match 'junk'.

最佳答案

使用 map() 而不是 each() :

var fundingOpportunityList = element.all(by.css('#search-results-list li a article h3'));

var opportunities = fundingOpportunityList.map(function(elem) {
return elem.getText();
});

expect(opportunities).toEqual(['hello1', 'hello2']);

关于javascript - 非 Angular 网站 - 检查结果已排序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30672933/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com