gpt4 book ai didi

Java for 循环总是返回 true

转载 作者:行者123 更新时间:2023-12-01 06:12:19 25 4
gpt4 key购买 nike

我有以下代码。这里的结果总是通过,因为我有 2 个失败的场景。

List<WebElement> webElementslist = driver.findElements(By.className("android.widget.TextView"));
for (WebElement webElementlist : webElementslist)
{
// System.out.println("Start Application"+webElementlist.getText());
for (int i = 2; i <= DisText.getRowCount("TRAText"); i++)
{
// System.out.println("Start Excel"+DisText.getCellData("TRAText", "Description", i));
if (webElementlist.getText().equals(DisText.getCellData("TRAText", "Description", i)))
{
tflag = true;
}
}
if (tflag)
extent.log(LogStatus.PASS, "Display Text", "Its Pass");
// Reporter.log("Pass");
else
extent.log(LogStatus.FAIL, "Display Text", "Its Fail");
}

最佳答案

你错过了几件事。首先,您需要在内循环之前将 tflag 设置为 false,因为一旦将其设置为 true,它就永远不会设置为 false。其次,我认为一旦找到匹配项,您就会想要打破内循环。我已在下面的代码中添加了新语句和注释,以便您可以看到它们。

List<WebElement> webElementslist = driver.findElements(By.className("android.widget.TextView"));
for (WebElement webElementlist : webElementslist)
{
tflag = false; // need to reset tflag for each element
for (int i = 2; i <= DisText.getRowCount("TRAText"); i++)
{
if (webElementlist.getText().equals(DisText.getCellData("TRAText", "Description", i)))
{
tflag = true;
break; // break out of for loop when match is found... for each element
}
}
if (tflag)
extent.log(LogStatus.PASS, "Display Text", "Its Pass");
else
extent.log(LogStatus.FAIL, "Display Text", "Its Fail");
}

关于Java for 循环总是返回 true,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32754432/

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