Skip to content

Commit a8db79c

Browse files
Allure testops scenario (#54)
* Allure TestOps: add scenario
1 parent 95e5c6b commit a8db79c

File tree

10 files changed

+486
-61
lines changed

10 files changed

+486
-61
lines changed

CHANGELOG.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ All notable changes to this project will be documented in this file.
44
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
55
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
66

7-
[3.15.0] - 2022-09-02
7+
[3.16.0] - 2022-09-12
88

99
### Added
10-
- Allure TestOps: Add statuses info
10+
- Allure TestOps: Add scenario

GherkinSyncTool.Synchronizers.AllureTestOps/AllureTestOpsSynchronizer.cs

Lines changed: 43 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using System.Collections.Generic;
1+
using System;
2+
using System.Collections.Generic;
23
using System.Diagnostics;
34
using System.Linq;
45
using System.Reflection;
@@ -8,6 +9,7 @@
89
using GherkinSyncTool.Synchronizers.AllureTestOps.Client;
910
using GherkinSyncTool.Synchronizers.AllureTestOps.Content;
1011
using GherkinSyncTool.Synchronizers.AllureTestOps.Exception;
12+
using GherkinSyncTool.Synchronizers.AllureTestOps.Model;
1113
using NLog;
1214
using Quantori.AllureTestOpsClient.Model;
1315
using Scenario = Gherkin.Ast.Scenario;
@@ -35,6 +37,7 @@ public void Sync(List<IFeatureFile> featureFiles)
3537
Log.Info("# Start synchronization with Allure TestOps");
3638

3739
var allureTestCases = _allureClientWrapper.GetAllTestCases().ToList();
40+
var featureFilesTagIds = new List<ulong>();
3841

3942
foreach (var featureFile in featureFiles)
4043
{
@@ -44,14 +47,14 @@ public void Sync(List<IFeatureFile> featureFiles)
4447
{
4548
var tagId = scenario.Tags.FirstOrDefault(tag => tag.Name.Contains(_gherkinSyncToolConfig.TagIdPrefix));
4649

47-
var caseRequest = _caseContentBuilder.BuildCaseRequest(scenario, featureFile);
50+
var caseRequestExtended = _caseContentBuilder.BuildCaseRequest(scenario, featureFile);
4851

4952
// Create test case for feature file which is getting synced for the first time, so no tag id present.
5053
if (tagId is null)
5154
{
52-
var newTestCase = CreateTestCase(caseRequest);
53-
if(newTestCase is null) continue;
54-
55+
var newTestCase = CreateNewTestCase(caseRequestExtended);
56+
if (newTestCase is null) continue;
57+
5558
var lineNumberToInsert = scenario.Location.Line - 1 + insertedTagIdsCount;
5659
var formattedTagId = GherkinHelper.FormatTagId(newTestCase.Id.ToString());
5760
TextFilesEditMethods.InsertLineToTheFile(featureFile.AbsolutePath, lineNumberToInsert,
@@ -63,14 +66,15 @@ public void Sync(List<IFeatureFile> featureFiles)
6366
if (tagId is not null)
6467
{
6568
var caseIdFromFile = GherkinHelper.GetTagId(tagId);
66-
//featureFilesTagIds.Add(caseId);
69+
featureFilesTagIds.Add(caseIdFromFile);
70+
6771
var allureTestCase = allureTestCases.FirstOrDefault(c => c.Id == caseIdFromFile);
6872
if (allureTestCase is null)
6973
{
7074
Log.Warn($"Case with id {caseIdFromFile} not found. Recreating missing case");
71-
var newTestCase = CreateTestCase(caseRequest);
72-
if(newTestCase is null) continue;
73-
75+
var newTestCase = CreateNewTestCase(caseRequestExtended);
76+
if (newTestCase is null) continue;
77+
7478
var formattedTagId = GherkinHelper.FormatTagId(newTestCase.Id.ToString());
7579
TextFilesEditMethods.ReplaceLineInTheFile(featureFile.AbsolutePath,
7680
tagId.Location.Line - 1 + insertedTagIdsCount, formattedTagId);
@@ -79,35 +83,56 @@ public void Sync(List<IFeatureFile> featureFiles)
7983
{
8084
try
8185
{
82-
_allureClientWrapper.UpdateTestCase(allureTestCase, caseRequest);
86+
_allureClientWrapper.UpdateTestCase(allureTestCase, caseRequestExtended);
8387
}
8488
catch (AllureException e)
8589
{
86-
Log.Error(e, $"The test case has not been updated: {caseRequest.Name}");
90+
Log.Error(e, $"The test case has not been updated: {caseRequestExtended.CreateTestCaseRequest.Name}");
8791
_context.IsRunSuccessful = false;
8892
}
8993
}
9094
}
9195
}
9296
}
93-
97+
//TODO:
98+
//DeleteNotExistingScenarios(allureTestCases, featureFilesTagIds);
9499
Log.Debug(@$"Synchronization with Allure TestOps finished in: {stopwatch.Elapsed:mm\:ss\.fff}");
95100
}
96101

97-
private TestCase CreateTestCase(CreateTestCaseRequest caseRequest)
102+
private void DeleteNotExistingScenarios(List<TestCaseContent> allureTestCases, List<ulong> featureFilesTagIds)
103+
{
104+
throw new NotImplementedException("The method should be implemented in future versions");
105+
}
106+
107+
private TestCase CreateNewTestCase(CreateTestCaseRequestExtended caseRequestExtended)
98108
{
99-
TestCase result = null;
109+
TestCase newTestCase = null;
100110
try
101111
{
102-
result = _allureClientWrapper.AddTestCase(caseRequest);
103-
return result;
112+
newTestCase = _allureClientWrapper.AddTestCase(caseRequestExtended.CreateTestCaseRequest);
104113
}
105114
catch (AllureException e)
106115
{
107-
Log.Error(e, $"The case has not been created: {caseRequest.Name}");
116+
Log.Error(e, $"The case has not been created: {caseRequestExtended.CreateTestCaseRequest.Name}");
108117
_context.IsRunSuccessful = false;
109-
return result;
110118
}
119+
120+
if (newTestCase is null) return null;
121+
122+
if (caseRequestExtended.StepsAttachments.Any())
123+
{
124+
try
125+
{
126+
_allureClientWrapper.UploadStepAttachments(caseRequestExtended, newTestCase);
127+
}
128+
catch (AllureException e)
129+
{
130+
Log.Error(e, $"The test case steps attachment has not been uploaded: [{newTestCase.Id}]{caseRequestExtended.CreateTestCaseRequest.Name}");
131+
_context.IsRunSuccessful = false;
132+
}
133+
}
134+
135+
return newTestCase;
111136
}
112137
}
113138
}

0 commit comments

Comments
 (0)