如何对列表进行排序

时间:2015-01-08 01:00:36

标签: selenium

我需要检查列表是否按字母顺序排列。 SysPrint似乎是按字母顺序排列的,但断言会抛出错误,列表不按字母顺序排列。非常感谢任何帮助!

java.lang.AssertionError:广告商不按字母顺序排列。期望[true]但发现[false]"。

我的剧本:

try {
        WebDriverWait wait = new WebDriverWait(driver, 30);
        List<String> displayed = new ArrayList<String>();
        List<String> sorted = new ArrayList<String>();

        List<WebElement> verifyAdvertiser = wait
                .until(ExpectedConditions.visibilityOfAllElementsLocatedBy(By
                        .xpath(".//*[@id='basic']/div[4]/table/tbody[2]/tr")));
        System.out.println("NUMBER OF ROWS IN THIS TABLE = "
                + verifyAdvertiser.size());

        for (WebElement element : verifyAdvertiser) {
            System.out.println("" + element.getText());
            displayed.add(element.getText());
            sorted.add(element.getText());
        }

        Collections.sort(sorted);
        log.info(sorted);

        if (!displayed.equals(sorted)) {

            final String failedMsg = "Advertiser is not in alphabetical order.";
            log.error(failedMsg, null);
            boolean passed = false;
            Assert.assertTrue(passed, failedMsg);
        }

    } catch (Exception e) {

        final String failedMsg = "Failed trying to check agency names in alphabetical order.";
        log.error(failedMsg, e);
        boolean passed = false;
        Assert.assertTrue(passed, failedMsg);
    }

0 个答案:

没有答案