Answer the question
In order to leave comments, you need to log in
How to get information about whether an exception is currently thrown?
I do UI tests using WinAppDriver. When an exception occurs on the form, the tests are considered passed. Is there some way to check if an exception is thrown on the form or not? Or maybe there are other frameworks that would throw an exception in a similar situation?
[TestMethod]
public void TestMethod1()
{
session.FindElementByAccessibilityId("button1").Click();
}
private void button1_Click(object sender, EventArgs e)
{
throw new Exception();
}
Answer the question
In order to leave comments, you need to log in
[TestMethod]
public void TestMethod1()
{
var button = session.FindElementByAccessibilityId("button1");
try
{
button.Click();
} catch(Exception) {
// Тест пройден.
return;
}
throw new Exception("Тест не пройден.");
}
No way. You have an unhandled exception thrown on another (UI) thread.
The only way is to catch the exception in the click handler and then store information about it in some variable, or even the exception itself. And then access this variable from the test.
But in general, you can't do that. Unit tests should not interact with the UI, they are for unit testing . Your task is solved through integration testing.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question