Hi All,
I extend Selenium's SeleneseTestNGHelper which has exposed the method
checkForVerificationErrors. This method is annotated with
@AfterMethod.
http://grepcode.com/file/repo1.maven.org/maven2/org.seleniumhq.selenium.client-drivers/selenium-java-testng-helper/1.0-beta-2/com/thoughtworks/selenium/SeleneseTestNgHelper.java#SeleneseTestNgHelper.checkForVerificationErrors%28%29
From what I have read on TestNG threads, if a configuration fails,
TestNG test runner considers the test environment to be in an unstable
state and skips execution of all tests that would have followed the
test that generated verification errors. Have I understood this
correctly?
If this is correct, this is causing me two problems:
1. Selenium does not immediately cease test execution but stored all
verification errors until you check for those errors. That means that
the test is considered to be successful by TestNG thus causing a false
positive.
2. It skips all executions of the tests that would have followed the
actual failed test.
Has any one had this problem before? I would like to
1. Verify errors but be able to mark the test as failed. This would
prevent any false positives. I looked at this link for soft asserts
http://beust.com/weblog2/archives/000514.html but I don't think I can
use this approach.
2. Prevent any skipped execution of tests. In my base class that
extends SeleniumTestNGHelper, I have overridden the behavior as
follows:
/**
* Asserts that there were no verification errors during the
current test,
* failing immediately if any are found */
@AfterMethod(alwaysRun = true)
public void checkForVerificationErrors(Method m, ITestContext
context) {
try {
super.checkForVerificationErrors();
} catch (AssertionError e) {
Reporter.log(this.verificationErrors.toString());
@SuppressWarnings("unchecked")
Map<String, String> failedMethods =
(Map<String, String>)
context.getAttribute(FAILED_METHODS);
failedMethods.put(m.getDeclaringClass().getSimpleName() +
"_"
+ m.getName(),
this.verificationErrors.toString());
}
}
But this could give false positives for a test that failed. Is there a
way I can change the test result after execution? I looked at
implementing a variation of this strategy but this does not return any
configuration methods.
http://beust.com/weblog/2010/03/23/better-mock-testing-with-testng/