I am trying to port some of my WebDriver tests from JAVA to C#. What I’m stuck on is the situation when the driver cannot find some element on the page, in JAVA I do :
if (second >= 10) fail("timeout - " + list);
so if something takes more than 10 seconds the test fails with the timeout message.
I tried a similar approach in C# with
if (sec >= 10) Debug.Fail("timeout : " + vList);
but this actually did not fail the test, but gave me an option to do so with the exception message box. That was a no no, I need my automatic test to fail outright on its own. Then I tried
if (sec >= 10) Assert.Fail("timeout : " + vList);
but this is throwing an unhandled exception error. Should I enclose the Assert.Fail in try/catch block? Or should I use something completely different to fail the test?
I am using MSTest, as mentioned in the topic.
EDIT: The exact message is :
AssertFailedException was unhandled by user code. Assert.Fail failed.
timeout : someField.
on
Assert.Fail(“timeout : ” + vList);
I think you’re seeing that behaviour because you’ve got the debugger attached to the running test –
Assert.FailthrowsAssertFailedException, your debugger sees the exception and breaks – and you don’t get test results.On the Debug menu, go into Exceptions, find
AssertFailedException(or create an entry for it if it’s not there) and make sure break on throw is turned off for that exception type.Alternatively, run your tests without the debugger attached.