Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Atata with Parallel MSTests #846

Open
gregwinterstein opened this issue Dec 9, 2024 · 1 comment
Open

Atata with Parallel MSTests #846

gregwinterstein opened this issue Dec 9, 2024 · 1 comment

Comments

@gregwinterstein
Copy link

We are using MSTest and are having issues with Atata when running UI tests in parallel.

The Current Context seems to only refer to the most recently created Atata context. This seems reasonable as it is CurrentContext. Many of our tests use AtataContext.Current.TakeScreenshot() at the very least this causes confusion in the logs. Many of the contexts created in parallel tests have a different base URL because they are used for different web sites in different domains.

The ArtifactsRootPathTemplate is set at AtataContext.GlobalProperties.UseArtifactsRootPathTemplate(). We keep track of this path on a per-test basis (set to $"TestContext.DeploymentDirectory\art{DateTime.Now:yyyyMMdd.HHmmssfff}". As global Atata property, this only works for the last context created. This isn't a huge issue as we use an event handler for ArtifactAddedEvent and the events contain the path to the artifact.

We are also having issues setting a handler for the ArtifactAddedEvent to handle screenshots. The handler is set in the GlobalConfiguration.EventSubscriptions. If we set one handler for each Atata instance, there will be multiple handlers and most of them will fail (because the event was handled by one of the other handlers). Setting a single handler for all instances also runs into issues because our logger is a different instance for each test and is written-to in the handler. In this case, the handler doesn't fail, but all of the screenshots are handled by one test logger, and many of the screenshots are logged to the wrong test.

How can we manage multiple Atata contexts, event handlers, and screenshot requests when tests are running in parallel so that everything stays separate on a per-test basis?

@YevgeniyShunevych
Copy link
Member

YevgeniyShunevych commented Dec 10, 2024

There might be some misconfiguration. Have you checked MSTest sample project? I've just reviewed and verified it works well with parallel tests. By the way, I added a fix to UITestFixture. Nevertheless, mainly UITestFixture.SetUp method should be similar to:

[TestInitialize]
public void SetUp() =>
    AtataContext.Configure()
        .UseTestName(TestContext.TestName)
        .UseTestSuiteType(GetType())
        .LogConsumers.Add(new TextOutputLogConsumer(TestContext.WriteLine))
        .Build();

Fixture file links:

You can also post in a comment your global and test setup methods.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants