Selenium中的两个值之间的ComparisonFailure。

huangapple go评论69阅读模式
英文:

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);

这是结果部分:

&lt;br&gt;&lt;br&gt;
first value : 1.189 TL Bucket Value : &lt;br&gt;
1.189  TL&lt;br&gt;
basarisiz&lt;br&gt;
FAILED: signInTestCase&lt;br&gt;
org.junit.ComparisonFailure: expected:&lt;[1.189] TL&gt; but was:&lt;[&lt;br&gt;
1.189 ] TL&gt;
英文:

This is the code:

    List&lt;WebElement&gt; ProductPrices1 = driver.findElements(By.className(&quot;prc-slg&quot;));
	String text1Price = ProductPrices1.get(0).getText();
  	
	thread(1500);
	element(ClickBucket).click();
	thread(1500);

  	
	List&lt;WebElement&gt; elements = driver.findElements(By.xpath(&quot;//div[contains(@class, &#39;pb-basket-item-price&#39;)]&quot;));
	for (WebElement element : elements) {
	    str = element.getText();

	    int cntTL = (str.length() - str.replace(&quot;TL&quot;, &quot;&quot;).length()) / 2;
	    if (2 == cntTL) {
	        str = str.split(&quot;TL&quot;)[1].replace(&quot;\&quot;&quot;, &quot;&quot;) + &quot; TL&quot;;
	    }
  	  
	}
  	
	System.out.println(&quot;first value : &quot;+text1Price+&quot;Bucket Value : &quot;+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(&quot;TL&quot;, &quot;&quot;).trim(), str.replace(&quot;TL&quot;, &quot;&quot;).trim());

huangapple
  • 本文由 发表于 2020年9月4日 19:18:04
  • 转载请务必保留本文链接:https://go.coder-hub.com/63740138.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定