如何从断言中删除空间

时间:2018-12-17 17:31:45

标签: java selenium assertion

如何从.size中删除空间。

  

java.lang.AssertionError:预期[9]但发现[9]

List<WebElement> editicons = 
   driver.findElements(By.xpath("//i[@class='material-icons']"));
        for (int j = 1; j <= editicons.size(); j++) {
            editicons = driver.findElements(By.xpath("//i[@class='material-icons']"));
            String porfolioName = driver.findElement(By.xpath("(//mat-table//mat-row)[" + j + "]//mat-cell[2]"))
                    .getText(); 
            Thread.sleep(1000); 
            Reporter.log("Successfully rendered  no " + porfolioName);
            Add_Log.info("Successfully rendered no " + porfolioName);   
        }   
        String savecount = driver.findElement(By.xpath("//div[@class='mat-paginator-range-label']")).getText();
        String[] trimmedText = savecount.split("of");   
        Reporter.log("Total number of Approve: " + trimmedText[1]);
        Add_Log.info("Total number of Approve: " + trimmedText[1]);
    Assert.assertEquals(editicons.size(), trimmedText[1]);
}

1 个答案:

答案 0 :(得分:1)

使用Integer类(int数据类型的包装器类)的静态方法StringInteger转换为parseInt。要消除开头和结尾的空格,我们可以使用Stringtrim方法。

Assert.assertEquals(editicons.size(), Integer.parseInt(trimmedText[1].trim));