sigma
sigma

Reputation: 29

Verify the value of label in selenium

I am creating automation for for product prchase process for different countires. On order confirmation page I am veriying if tax price and shipping price is set to 0 or not.

Here is my code:

String expectedshippingprice = "$0.00"; 
String actualshipingprice = driver.findElement(By.xpath("html/body/div[1]/div[6]/div[1]/div/fieldset/div[2]/div[2]")).getText(); 

Assert.assertEquals("Verify Shipping Price", expectedshippingprice, actualshipingprice);

But I am getting error :

java.lang.AssertionError: $0.00 expected [$0.00] but found [Verify Price]

Here is is the HTML code:

<div class="row">
  <div class="col-sm-8 col-md-8 col-xs-8 col-lg-8">Product Price</div>
  <div class="col-xs-4 col-lg-4 col-md-4 col-sm-4">$19.95</div>
</div>
<div class="row">
  <div class="col-sm-6 col-md-4 col-xs-8 col-lg-8">Shipping</div>
  <div class="col-xs-4 col-lg-4 col-md-4 col-sm-4">$0.00</div>
</div>
<div class="row">
  <div class="col-sm-6 col-md-4 col-xs-8 col-lg-8">Tax</div>
  <div class="col-xs-4 col-lg-4 col-md-4 col-sm-4">$0.00</div>
</div>

Please help!

Upvotes: 0

Views: 2877

Answers (1)

timbre timbre
timbre timbre

Reputation: 13986

Provided you properly imported org.junit.Assert (and not some other Assert), function

 Assert.assertEquals(message, expected, actual);

will return AssertionException like this:

java.lang.AssertionError: <message> expected [<expected>] but found [<actual>]

So based on your exception (java.lang.AssertionError: $0.00 expected [$0.00] but found [Verify Price].), I can conclude that you called assertEquals like this:

 Assert.assertEquals(expectedshippingprice, actualshipingprice, "Verify Price");

Although your question shows the right way. So just change the order of parameters in the same way as your question currently shows:

Assert.assertEquals("Verify Shipping Price", expectedshippingprice, actualshipingprice);

Upvotes: 1

Related Questions