Litton Sinha
Litton Sinha

Reputation: 1

Looping stops when assertion fails

There is an excelsheet where all URLs (16) are listed in one column. Now once page gets loaded need to verify whether page title is matching with the expected title which is already stored in excel. I am able to perform it using for loop. It runs all URls if all are passed but stops when it fails. I need to run it completely and give a report which passed and which failed. I written the below code.

        rowCount = suite_pageload_xls.getRowCount("LoadURL");

        for(i=2,j=2;i<=rowCount;i++,j++) {
            String urlData = suite_pageload_xls.getCellData("LoadURL", "URL", i);
            Thread.sleep(3000);
            long start = System.currentTimeMillis();
            APP_LOGS.debug(start);
            driver.navigate().to(urlData);
            String actualtitle = driver.getTitle();
            long finish = System.currentTimeMillis();
            APP_LOGS.debug(finish);
            APP_LOGS.debug(urlData+ "-----" +driver.getTitle());
            long totalTime = finish - start;
            APP_LOGS.debug("Total time taken is "+totalTime+" ms");

            String expectedtitle = suite_pageload_xls.getCellData("LoadURL", "Label", j);
            Assert.assertEquals(actualtitle, expectedtitle);

            if (actualtitle.equalsIgnoreCase(expectedtitle)) {
                APP_LOGS.debug("PAGE LABEL MATCHING....");
                String resultpass = "PASS";
                APP_LOGS.debug(resultpass);
                APP_LOGS.debug("***********************************************************");
            } else {
                APP_LOGS.debug("PAGE LABEL NOT MATCHING....");
                String resultfail = "FAIL";
                APP_LOGS.debug(resultfail);
                APP_LOGS.debug("***********************************************************");
            }
        }

Kindly help me in this regard.

Upvotes: 0

Views: 235

Answers (1)

michael_bitard
michael_bitard

Reputation: 4222

This is the correct behavior of the assertion, it throws an Exception when the assertion is wrong.

You could store the actualTitles and expectedTitles in arrays and perform the assertions all at once.

For better assertions I suggest you try AssertJ, you could directly compare 2 lists, the actual and the expected, and it will return the complete difference.

Upvotes: 2

Related Questions