我应该导入哪个类才能使用 verifyTrue

发布于 2024-12-04 18:41:49 字数 791 浏览 4 评论 0原文

我使用 Selenium 和 TestNG 使用 dataProvider。我正在验证有一百个名字的列表。我已将所有这些添加到 Excel 工作表中,并在单元格中以逗号分隔。我用 Java 编程如下:

import static org.testng.AssertJUnit.*;
public class example extends Base{
    @Test(dataProvider="List")
    public void isListofNamesPresent(String names) throws Exception
    String list[] = names.split(",");
    for(int i=0; i<list.length; i++){
        assertTrue(selenium.isTextPresent(list[i]));
        Reporter.log("Type of Case:"+ names +" are present");
    }
}

上面的代码断言放入 CELL 中的名称列表为(Aaron、James、Jack、Hegin、Henry)。由于它只有一轮数据,因此如果出现任何错误,它将退出该方法由于assertTrue,实际值与预期值之间存在差异。如果我给出 verifyTrue 那么它应该执行所有列表,即使实际和预期之间存在不匹配。

谁能告诉我如何使用 verifyTrue 吗?我的意思是我需要导入哪个类。我无法扩展任何课程,因为我已经扩展了基础课程。所以任何导入都可以。我尝试使用 SeleneseTestCase 但没有运气。

提前致谢

I am using Selenium with TestNG using dataProvider. I am verifying the list which have hundred names. I have added all of these into an excel sheet with comma separated in A CELL. I have programmed in Java as below:

import static org.testng.AssertJUnit.*;
public class example extends Base{
    @Test(dataProvider="List")
    public void isListofNamesPresent(String names) throws Exception
    String list[] = names.split(",");
    for(int i=0; i<list.length; i++){
        assertTrue(selenium.isTextPresent(list[i]));
        Reporter.log("Type of Case:"+ names +" are present");
    }
}

The above code asserts the list of names which are put in A CELL as (Aaron, James, Jack, Hegin, Henry).Since it has only one round of data it exits the method if any error between actual and expected because of assertTrue. If i give verifyTrue then it should get execute all the list even though there is a mismatch between actual and expected.

Can anyone please tell me how to use verifyTrue? I mean which class i need to import. I cannot extend any class as I have already extended a Base Class. So any import will do. I tried with SeleneseTestCase but no luck.

Thanks in advance

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

迎风吟唱 2024-12-11 18:41:49

另一种方法是创建您自己的 verifyTrue() 方法,该方法执行类似以下操作来捕获断言错误:

public static void verifyTrue(boolean condition, String message) {
    try {
        Assert.assertTrue(condition, message);
        log("Expected value: true" + " Actual value: " + condition + " - PASSED ", true);
    } catch (Throwable e) {
        log("Expected value: true" + " Actual value: " + condition + " - FAILED " + message, true);
        addVerificationFailure(e);
    }
}

Another way you can do it would be to create your own verifyTrue() method that does something like this to catch the assert error:

public static void verifyTrue(boolean condition, String message) {
    try {
        Assert.assertTrue(condition, message);
        log("Expected value: true" + " Actual value: " + condition + " - PASSED ", true);
    } catch (Throwable e) {
        log("Expected value: true" + " Actual value: " + condition + " - FAILED " + message, true);
        addVerificationFailure(e);
    }
}

您可以导入 SeleneseTestBase 类来使用 verifyTrue() ,如下所示:

import com.thoughtworks.selenium.SeleneseTestBase;

也可以使用 SeleneseTestCase,但它已被弃用。所以。最好使用 SeleneseTestBase

You can import SeleneseTestBase class to use verifyTrue() as below:

import com.thoughtworks.selenium.SeleneseTestBase;

SeleneseTestCase can also be used, but it is deprecated. So. it is better to use SeleneseTestBase

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文