[英]How to test elements are sorted in the list using javascript?
Hi guys i am working on a apple UI Automation project where i have to test on a click of a button are elements in the list getting sorted properly or not ? 嗨,大家好,我正在研究一个Apple UI自动化项目,我必须按一下按钮进行测试,列表中的元素是否正确排序了? can anyone help me to find how can i test it ? 谁能帮助我找到如何测试它?
A simple solution would be to iterate over the elements in the list and verify that each element is smaller than the next one: 一个简单的解决方案是遍历列表中的元素,并验证每个元素都小于下一个:
function is_sorted(arr) {
var len = arr.length - 1;
for(var i = 0; i < len; ++i) {
if(arr[i] > arr[i+1]) {
return false;
}
}
return true;
} }
You will have to adapt this code to sort UIElements, in particular the clause below: 您将必须修改此代码以对UIElement进行排序,尤其是下面的子句:
arr[i] > arr[i+1]
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.