ShuiRuTian / playwright-trx-reporter

playwright reporter for trx file format.
7 stars 3 forks source link

Duplicate test definitions in trx file #2

Closed marks234 closed 1 year ago

marks234 commented 1 year ago

When a test fails (eg. due to timeouts) and there is a retry, the same test definition is created in the trx file. This leads to an exception when trying to publish the test results (see below).

<TestDefinitions>
    <UnitTest id="58bd2c23-4d57-5ee4-ad34-9d2b8a3e536b" name="test1" storage="/e2e/tests/spec/feature1/feat1.spec.ts">
      <TestMethod className=....(omitted)/>
    </UnitTest>
    <UnitTest id="58bd2c23-4d57-5ee4-ad34-9d2b8a3e536b" name="test1" storage="/e2e/tests/spec/feature1/feat1.spec.ts">
      <TestMethod className=...(omitted)/>
    </UnitTest>
...
</TestDefinitions>

Azure DevOps exception

==============================================================================
Task         : Publish Test Results
Description  : Publish test results to Azure Pipelines
Version      : 2.216.2
Author       : Microsoft Corporation
Help         : https://docs.microsoft.com/azure/devops/pipelines/tasks/test/publish-test-results
==============================================================================
Result Attachments will be stored in LogStore
Run Attachments will be stored in LogStore
Failed to parse result files: System.ArgumentException: An item with the same key has already been added. Key: 58bd2c23-4d57-5ee4-ad34-9d2b8a3e536b
   at System.Collections.Generic.Dictionary`2.TryInsert(TKey key, TValue value, InsertionBehavior behavior)
   at Microsoft.TeamFoundation.TestClient.PublishTestResults.TrxResultParser.GetTestCaseDefinitionsDictionary(XmlDocument doc, Dictionary`2 xUnitTestCaseCounts)
   at Microsoft.TeamFoundation.TestClient.PublishTestResults.TrxResultParser.ParseTestResultFile(TestRunContext runContext, String filePath)
   at Microsoft.TeamFoundation.TestClient.PublishTestResults.TrxResultParser.<>c__DisplayClass1_0.<ParseTestResultFiles>b__0(String file)
   at System.Linq.Enumerable.SelectListIterator`2.MoveNext()
   at System.Linq.Enumerable.WhereEnumerableIterator`1.ToList()
   at Microsoft.TeamFoundation.TestClient.PublishTestResults.TrxResultParser.ParseTestResultFiles(TestRunContext runContext, IList`1 resultFilePaths)
   at Microsoft.VisualStudio.Services.Agent.Worker.TestResults.Parser.ParseFiles(IExecutionContext executionContext, TestRunContext testRunContext, List`1 testResultsFiles, ITestResultParser testResultParser) in /home/vsts/work/1/s/src/Agent.Worker/TestResults/Parser.cs:line 57
ShuiRuTian commented 1 year ago

Thanks for the good catch.

This issue is fixed in this commit(the content is kind of noisy....): https://github.com/ShuiRuTian/trx-reporter-for-playwright/commit/6cfdd25caffdb09cc1ac30cea98c42d4f50f3326

The latest version is 1.0.3 now, which includes the fix.

And it seems someone is really using this repo other than me, so I also create a rule to ensure every change from now on should be a PR if it could be part of main branch.

Thanks for the using!

marks234 commented 1 year ago

Thanks for the quick fix. Works now as expected :)