System.StackOverflowException on #3201
-
This code thrown System.StackOverflowException. Without attribute works fine |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
|
in logs Stack overflow. |
Beta Was this translation helpful? Give feedback.
-
|
Hi, @Toliar The easiest workaround is to ignore the [AllureStep("Check tab is active")]
public async Task CheckTabIsActiveAsync([Allure.NUnit.Attributes.Skip] ILocator locator)
{
await Assertions.Expect(locator).ToHaveClassAsync(new Regex("active"));
}If you prefer keeping the argument, the type formatters API should be used. Unfortunately, it's not very convenient to use in your case since it doesn't support matching by an interface and the actual type of the locator is internal. This is something I gonna address as well (see allure-framework/allure-csharp#644). Until it's done, you have to use reflection: class ToStringFormatter<T>: TypeFormatter<T>
{
public static string Format(T value) => value?.ToString() ?? "null";
}
public static class SetUp
{
[ModuleInitializer]
public static void Initialize()
{
// Use reflection to get the AddTypeFormatter<T>(TypeFormatter<T> formatter) method
var addTypeFormatter = typeof(AllureLifecycle).GetMethod(
nameof(AllureLifecycle.AddTypeFormatter),
1,
[typeof(TypeFormatter<>).MakeGenericType(Type.MakeGenericMethodParameter(0))]
);
// Get the actual type of locator. Alternatively, scan the whole assembly for the types that implement `ILocator`.
var locatorType = Assembly.GetAssembly(typeof(ILocator)).GetType("Microsoft.Playwright.Core.Locator");
var formatterType = typeof(ToStringTypeFormatter<>).MakeGenericType(locatorType);
var formatter = Activator.CreateInstance(formatterType);
// The same as AllureLifecycle.Instance.AddTypeFormatter(new ToStringFormatter<Locator>()) but for a non-public type
addTypeFormatter.MakeGenericMethod(locatorType).Invoke(AllureLifecycle.Instance, [formatter]);
}
} |
Beta Was this translation helpful? Give feedback.
Hi, @Toliar
This happens because
[AllureStep]tries to serialize the arguments. By default, it tries to convert the value to JSON. In your case this fails badly as Playwright locators aren't JSON-friendly. While there is room for improvement on our side (see allure-framework/allure-csharp#482 and allure-framework/allure-csharp#502), there are some workarounds that may help.The easiest workaround is to ignore the
locatorargument with[Allure.NUnit.Attributes.Skip]:If you prefer keeping…