英文:
Selenium ComparisonFailure between 2 value
问题
这是代码部分:
List<WebElement> ProductPrices1 = driver.findElements(By.className("prc-slg"));
String text1Price = ProductPrices1.get(0).getText();
thread(1500);
element(ClickBucket).click();
thread(1500);
List<WebElement> elements = driver.findElements(By.xpath("//div[contains(@class, 'pb-basket-item-price')]"));
for (WebElement element : elements) {
str = element.getText();
int cntTL = (str.length() - str.replace("TL", "").length()) / 2;
if (2 == cntTL) {
str = str.split("TL")[1].replace("\"", "") + " TL";
}
}
System.out.println("first value : "+text1Price+"Bucket Value : "+str);
Assert.assertEquals(text1Price,str);
这是结果部分:
<br><br>
first value : 1.189 TL Bucket Value : <br>
1.189 TL<br>
basarisiz<br>
FAILED: signInTestCase<br>
org.junit.ComparisonFailure: expected:<[1.189] TL> but was:<[<br>
1.189 ] TL>
英文:
This is the code:
List<WebElement> ProductPrices1 = driver.findElements(By.className("prc-slg"));
String text1Price = ProductPrices1.get(0).getText();
thread(1500);
element(ClickBucket).click();
thread(1500);
List<WebElement> elements = driver.findElements(By.xpath("//div[contains(@class, 'pb-basket-item-price')]"));
for (WebElement element : elements) {
str = element.getText();
int cntTL = (str.length() - str.replace("TL", "").length()) / 2;
if (2 == cntTL) {
str = str.split("TL")[1].replace("\"", "") + " TL";
}
}
System.out.println("first value : "+text1Price+"Bucket Value : "+str);
Assert.assertEquals(text1Price,str);
This is the result: <br><br>
first value : 1.189 TL Bucket Value : <br>
1.189 TL<br>
basarisiz<br>
FAILED: signInTestCase<br>
org.junit.ComparisonFailure: expected:<[1.189] TL> but was:<[<br>
1.189 ] TL>
答案1
得分: 1
有几种方法可以解决这个问题。其中之一是:
Assert.assertEquals(text1Price.replace("TL", "").trim(), str.replace("TL", "").trim());
英文:
There are several ways to solve the problem. One of them is:
Assert.assertEquals(text1Price.replace("TL", "").trim(), str.replace("TL", "").trim());
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论