Analyzing a Test Result

Here, we will execute a modified version of the GiganticStoreTest that includes ignored and failed tests. We'll navigate a TestNG HTML report after the execution of a test. The steps for completion are as follows:

  1. Open https://github.com/TrainingByPackt/Beginning-Selenium/blob/master/docs/lesson_8/lesson8/src/test/java/com/beginningselenium/examples/tests/GiganticStoreTest.java on IntelliJ IDEA.
  2. Execute the test by typing mvn clean test in the root directory.
  3. Open the resulting target/surefire-reports/index.html file in Chrome.
  4. Open the report. Note the failures highlighted by TestNG from the start page, as follows:

Note that five of the six methods passed, and only one failed.

  1. Click on the 3 groups option. The report will list all of the existing groups and their methods, as follows:

Note that only methods that were executed are present on this list. This feature can help you to identify potential causes of errors in your test, if you are concerned about the following:

  • One or more of the groups should not be on the list. Did you create groups by accident?
  • One (or more) of the expected groups is not on the list. Did you forget to create it?
  • A method is listed under the wrong group. Did you list the method in the wrong group, or is the group named incorrectly?
  • A method is missed. Did you forget to include it in that particular group, or did you include it in a different group by accident?

You can infer that the list of groups and methods of your test can also be used to identify the causes of errors. If you think that one of the preceding scenarios (or a combination of them) might be happening, it would be wise to compare it to the actual code and to the documentation of your test.

  1. Click on the Times option. The report will list the overall time of the test, along with the individual time of every executed method:

Notice that this list contains the methods verifyProductsPageInformation and  verifyHomePageInformation, which were not present in the Groups report of step 2. That is because these two methods do not belong to any group.

  1. Click on Ignored methods. The report will present the methods that are a part of your test, but with the (enabled = false) clause added to them:

This feature of the TestNG report can be very useful in the three following scenarios:

    • You were not expecting any methods to be ignored.
    • One or more of the methods should not be listed. Did you set the enabled annotation for that method to false by accident?
    • Some methods that were expected to be ignored are not listed. Did you forget to set the enabled annotation for that method to true?

As you can see, the list of ignored methods can also be used to identify the causes of errors. If you think that any of the preceding scenarios (or a combination of them) are happening, it would be wise to compare them to the actual code and to the documentation of your test. If we look at the GiganticStoreTest test, we will find that the LoginTest1 and the SearchTest2 were ignored, by design:

  1. Click on Chronological view. The report will be listed in order of method execution time. This list will include all of the executed methods: Test, BeforeTest, AfterTest, BeforeSuite, AfterSuite, BeforeGroup, AfterGroup, BeforeClass, and AfterClass:

If your test has unexpected error messages, the Chronological view can be useful to verify that the methods are being executed in the expected order.

  1. In the Results section, click on the show option of Passed methods, as follows:

These are the five out of six methods that were executed and passed with no issues.

  1. In the Results section, click on the show option of Failed methods. This will present the one method that failed and a message stating what went wrong:
  1. As indicated by the error message, open the GiganticStoreTest.java file and go to line 36:

The error message indicates that the Assert command was expecting the expectedProductsMainInfo string to contain the text: "Here's the spuff we sell". However, what it found was, "Here's the stuff we sell". In this example, the error was caused by a simple misspelling.

  1. In the GiganticStoreTest.java file, correct the error on line 35:

Execute the test again by typing mvn clean test, and verify the newly generated target/surefire-reports/index.html file. The report should show that all six of the methods in your tests passed:

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.15.171.202