我有一个检查未选中复选框的方法,如果我可以验证是否选中了复选框,我想检查该方法。该方法验证未选中复选框。
class check {
public int notselectedboxes() throws InterruptedException {
//Checks if its not selected.
Thread.sleep(2000);
int i = 0;
for(MobileElement re: APList) {
if(re.getAttribute("checked").equals("false"))
{
i++;
}
}
return i;
}
check viva = new check();
int jk = viva.notselectedboxes();
Assert.assertTrue(jk == true);
System.out.println("checkbox is not selected");
答案 0 :(得分:0)
根据您列出的输入,我会将代码改为:
public int notselectedboxes(List<MobileElement> APList) throws InterruptedException {
// Checks if it's not selected.
Thread.sleep(2000);
int i = 0;
for(MobileElement re: APList) {
if(re.getAttribute("checked").equals("false")) {
i++;
}
}
return i; // you have returned the count on all the unchecked boxes
}
并进一步将其用作:
check viva = new check();
List<MobileElement> APList = ..some list of your elements
Assert.assertTrue("Some of the checkbox were selected.", viva.notselectedboxes(APList) == APList.size());
// if none of the boxes were selected then the method would return value equal to the size of the list of mobile elements