Hi Dmitri,
Strictly speaking, this works, e.g.:
{font:style=font-family: courier new,courier; font-size: 8pt;} try { \\ Assert.assertTrue({font}{font:style=font-family: courier new,courier; font-size: 8pt;}selenium.isTextPresent("some text to find"){font}{font:style=font-family: courier new,courier; font-size: 8pt;}); \\ } catch (Throwable ex) { \\ System.out.println(ex.getMessage()); \\ ex.printStackTrace(); \\ }{font}
{font:style=font-family: courier new,courier; font-size: 8pt;} \\{font}
{font:style=font-family: courier new,courier; font-size: 8pt;} try { \\ Assert.assertTrue({font}{font:style=font-family: courier new,courier; font-size: 8pt;}selenium.isElementPresent("link=Other Media"){font}{font:style=font-family: courier new,courier; font-size: 8pt;}); \\ } catch (Throwable ex) { \\ System.out.println(ex.getMessage()); \\ ex.printStackTrace(); \\ }{font}
However, this doesn't seem like an effective solution because this doesn't get reported to JUnit or TestNG as a failure. We'd have to manually check the console/logs after each test.
To get around that problem, I overloaded the verifyTrue method to accept a String message, and tried using {font:style=font-family: courier new,courier; font-size: 10pt;}fail(){font} in the catch blocks, e.g. +{font:style=font-family: courier new,courier;}{font}+
{font:style=font-family: courier new,courier; font-size: 8pt;} private void verifyTrue(boolean condition, String msg) { \\ try { \\ Assert.assertTrue(condition); \\ } catch (Throwable ex) { \\ System.out.println("verifyTrue(false) for: " + msg); \\ fail("verifyTrue(false) for: " + msg); \\ } \\ }{font}
The fail() method is used by the SeleneseTestBase class, and JUnit now reports this as a failure... but it throws an AssertionError and immediately ends the test, reporting only the first failure.
In Selenium IDE, verify* will note the failure but finishes the test (unless it fails a later assert* of course), and the total number of failures is shown. I expected this to work the same way under JUnit/TestNG and Selenium RC, am I completely wrong in this assumption?
Thanks for your help!