0

this is my first question here and I want to learn Selenuim. I am trying to add assertions in my script to verify that the text is available on the page. The code only works for the first assertion, and fails for the second. Is this the right way to user assertions? Thanks!

public void verifyCampaignStatusDropdownMenu() throws InterruptedException {

    driver.findElement(By.linkText("TextOne"));
    String wipText = "TextOne";
    Assert.assertTrue("TextOne".equals(wipText), "TextOne text is available");

    driver.findElement(By.linkText("TextTwo"));
    String tempText = "TextTwo";
    Assert.assertTrue("Template".equals(tempText), "TextTwo text is available" );
}
SiKing
  • 10,003
  • 10
  • 39
  • 90
familyGuy
  • 425
  • 2
  • 5
  • 22
  • Provide the exception you are getting – Saifur Dec 08 '14 at 20:34
  • This question has nothing to do with Selenium. You should read through some JUnit documentation. – SiKing Dec 08 '14 at 20:45
  • @SiKing. I guess the question is related to selenium somehow. I believe OP's requirement is to verify the text of `webelements` – Saifur Dec 08 '14 at 20:57
  • @Saifur The OP obviously needs to understand JUnit first, before he starts mixing Selenium into the confusion. – SiKing Dec 08 '14 at 21:43

1 Answers1

0

Use of multiple asserts are not best practice. The best practice is to have one assert per test case. If for any reason first assert fails there is no value of having second assert. See this. You should break them down to two different method and execute the test.

And, Your asserts do not make any sense to me since you are comparing the content of same variable with parent not the webelement and you method should look like the following

public void verifyCampaignStatusDropdownMenuOne() throws InterruptedException {

    String wipText = driver.findElement(By.linkText("TextOne")).getText() ;
    Assert.assertTrue("TextOne text is available", "TextOne".equals(wipText));
}

public void verifyCampaignStatusDropdownMenuTwo() throws InterruptedException {

    String tempText = driver.findElement(By.linkText("TextTwo")).getText() ;
    Assert.assertTrue("TextTwo text is available", "Template".equals(tempText));
}

using Java

Community
  • 1
  • 1
Saifur
  • 16,081
  • 6
  • 49
  • 73