Skip to content

Commit 6e89999

Browse files
committed
test with teardown
1 parent 6fe47b4 commit 6e89999

File tree

1 file changed

+17
-16
lines changed

1 file changed

+17
-16
lines changed

src/Playwright.Tests/Attributes/PlaywrightTestAttribute.cs

+17-16
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
* SOFTWARE.
2323
*/
2424

25+
using System.Reflection;
2526
using NUnit.Framework.Interfaces;
2627
using NUnit.Framework.Internal;
2728
using NUnit.Framework.Internal.Commands;
@@ -235,22 +236,22 @@ public override TestResult Execute(TestExecutionContext context)
235236
context.CurrentResult.SetResult(
236237
ResultState.Failure,
237238
$"Test exceeded Timeout value of {_timeout}ms");
238-
// // When the timeout is reached the TearDown methods are not called. This is a best-effort
239-
// // attempt to call them and close the browser / http server.
240-
// foreach (var method in new string[] { "WorkerTeardown", "BrowserTearDown" })
241-
// {
242-
// var methodFun = context.CurrentTest.Method.MethodInfo.DeclaringType
243-
// .GetMethod(method, BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
244-
// if (methodFun != null)
245-
// {
246-
// var res = methodFun.Invoke(context.TestObject, null);
247-
// if (res is Task task)
248-
// {
249-
// Console.WriteLine($"Waiting for {method} task to complete");
250-
// task.GetAwaiter().GetResult();
251-
// }
252-
// }
253-
// }
239+
// When the timeout is reached the TearDown methods are not called. This is a best-effort
240+
// attempt to call them and close the browser / http server.
241+
foreach (var method in new string[] { "WorkerTeardown", "BrowserTearDown" })
242+
{
243+
var methodFun = context.CurrentTest.Method.MethodInfo.DeclaringType
244+
.GetMethod(method, BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
245+
if (methodFun != null)
246+
{
247+
var res = methodFun.Invoke(context.TestObject, null);
248+
if (res is Task task)
249+
{
250+
Console.WriteLine($"Waiting for {method} task to complete");
251+
task.GetAwaiter().GetResult();
252+
}
253+
}
254+
}
254255
}
255256
else
256257
{

0 commit comments

Comments
 (0)