【问题标题】:assert each item in list contains XYZ断言列表中的每个项目都包含 XYZ
【发布时间】:2012-02-20 15:50:14
【问题描述】:

我试图断言列表中的每个项目都包含“医院”一词 以下代码为我提供了每个医院的字符串列表:

List <WebElement> Hospital = driver.findElements(By.xpath("//tbody/tr/td/label"));
        for (WebElement webElement : Hospital){
        String servicenames = webElement.getText();

        System.out.println(servicenames);

我现在需要做什么来断言列表中的每个项目都包含我的字符串?

【问题讨论】:

  • 对局部变量使用小写/驼峰式命名。再说了,不是Strings的列表,怎么判断里面有没有“hospital”这个词呢?

标签: java testing webdriver


【解决方案1】:
List <WebElement> Hospital = driver.findElements(By.xpath("//tbody/tr/td/label"));
        for (WebElement webElement : Hospital){
        String servicenames = webElement.getText().toLowerCase();

        System.out.println(servicenames);

        try{
        assertTrue(servicenames.contains("hospital"));

        }catch(Error e){
        verificationErrors.append(e.toString());
        }

作为参考,这是我最终使用的东西,抱歉,没有得到启用断言的东西 - 我在某处读到断言应该作为 JUnit 的一部分自动启用,(因为它经常使用我猜在测试中) 无论如何,这似乎暂时有效......

【讨论】:

    猜你喜欢
    • 2018-01-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-04-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多