Skip to content

Commit eb07b93

Browse files
committed
fix: add functionality back to update test steps with execution results in Markdown tables
1 parent 64d6b1f commit eb07b93

File tree

8 files changed

+354
-49
lines changed

8 files changed

+354
-49
lines changed

samples/Runs/commitquality/TC-Documents-001.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,11 @@ The purpose of this test-case is to test the upload of a file to the system.
2121

2222
| Step ID | Description | Test Data | Expected Result | Actual Result |
2323
| -------:| ----------------------------- | ------------------------------------------------------------------------------- | ----------------------------------------- | ------------- |
24-
| 1 | File selector visible | Locator=GetByTestId Text=file-input Action=IsVisible | File selector is visible | |
25-
| 2 | Select file | Locator=GetByTestId Text=file-input Action=PickFile Value=../../samples/Definitions/commitquality/TC-Documents-001.md | File selected | |
26-
| 3 | Upload file | Locator=GetByRole AriaRole=Button Text=Submit Action=Click | Submit button clicked and file uploaded | |
24+
| 1 | File selector visible | Locator=GetByTestId Text=file-input Action=IsVisible | File selector is visible | |
25+
| 2 | Select file | Locator=GetByTestId Text=file-input Action=PickFile Value=../../samples/Definitions/commitquality/TC-Documents-001.md | File selected | |
26+
| 3 | Upload file | Locator=GetByRole AriaRole=Button Text=Submit Action=Click | Submit button clicked and file uploaded | |
2727

2828
## Postcondition
2929

3030
- no postcondition
31+

samples/Runs/localhost/Dashboard/TC-Dashboard-100.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,10 @@ When authenticated as administrator I see the dashboard with two available workf
2121

2222
| Step ID | Description | Test Data | Expected Result | Actual Result |
2323
| -------:| ---------------------- | -------------------------------------------------------------- | -----------------------------| ------------- |
24-
| 1 | nav Holiday | Locator=GetByRole AriaRole=Link Text=HOLIDAY Action=IsVisible | Holiday nav item is visible | - |
25-
| 2 | nav Issue | Locator=GetByRole AriaRole=Link Text=ISSUE Action=IsVisible | Issue nav item is visible | - |
24+
| 1 | nav Holiday | Locator=GetByRole AriaRole=Link Text=HOLIDAY Action=IsVisible | Holiday nav item is visible | |
25+
| 2 | nav Issue | Locator=GetByRole AriaRole=Link Text=ISSUE Action=IsVisible | Issue nav item is visible | |
2626

2727
## Postcondition
2828

2929
\-
30+

samples/Runs/localhost/TC-Login-001.md

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,12 @@ The purpose of this test-case is to satisfy the use-case UC-001-Login which is t
2020

2121
| Step ID | Description | Test Data | Expected Result | Actual Result |
2222
| -------:| ---------------------- | -------------------------------------------------------------- | ---------------------------------------------------------------- | ------------- |
23-
| 1 | enter username | Locator=GetByLabel Text=Username Action=Fill Value=admin | username is entered | - |
24-
| 2 | enter password | Locator=GetByLabel Text=Password Action=Fill Value=@Password | password is entered | - |
25-
| 3 | click login button | Locator=GetByRole AriaRole=Button Text=Login Action=Click | system validates the user credentials and redirects to dashboard | - |
26-
| 4 | displays the dashboard | Locator=GetByRole AriaRole=Button Text=Logout Action=IsVisible | Logout button visible in the main navigation | - |
23+
| 1 | enter username | Locator=GetByLabel Text=Username Action=Fill Value=admin | username is entered | |
24+
| 2 | enter password | Locator=GetByLabel Text=Password Action=Fill Value=@Password | password is entered | |
25+
| 3 | click login button | Locator=GetByRole AriaRole=Button Text=Login Action=Click | system validates the user credentials and redirects to dashboard | |
26+
| 4 | displays the dashboard | Locator=GetByRole AriaRole=Button Text=Logout Action=IsVisible | Logout button visible in the main navigation | |
2727

2828
## Postcondition
2929

3030
- The user is authenticated and has an active session.
31+

samples/Runs/localhost/TC-Login-002.md

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,12 @@ The purpose of this test-case is to validate the expected behavior when a user t
2020

2121
| Step ID | Description | Test Data | Expected Result | Actual Result |
2222
| -------:| ---------------------- | ----------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------- | ------------- |
23-
| 1 | enter username | Locator=GetByLabel Text=Username Action=Fill Value=Albert | username Albert is entered | - |
24-
| 2 | enter password | Locator=GetByLabel Text=Password Action=Fill Value=@Password | password is entered | - |
25-
| 3 | click login button | Locator=GetByRole AriaRole=Button Text=Login Action=Click | system validates the user credentials and displays an error message that the tried login attempt is invalid | - |
26-
| 4 | displays error message | Locator=GetByText Text=\"Invalid login attempt for user 'Albert'\" Action=IsVisible | Validation result of invalid login attempt is visible | - |
23+
| 1 | enter username | Locator=GetByLabel Text=Username Action=Fill Value=Albert | username Albert is entered | |
24+
| 2 | enter password | Locator=GetByLabel Text=Password Action=Fill Value=@Password | password is entered | |
25+
| 3 | click login button | Locator=GetByRole AriaRole=Button Text=Login Action=Click | system validates the user credentials and displays an error message that the tried login attempt is invalid | |
26+
| 4 | displays error message | Locator=GetByText Text=\"Invalid login attempt for user 'Albert'\" Action=IsVisible | Validation result of invalid login attempt is visible | |
2727

2828
## Postcondition
2929

3030
\-
31+

samples/Runs/localhost/TC-Login-003.md

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,12 @@ The purpose of this test-case is to validate the expected behavior when a user t
2020

2121
| Step ID | Description | Test Data | Expected Result | Actual Result |
2222
| -------:| ---------------------- | ---------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------- | ------------- |
23-
| 1 | enter username | Locator=GetByLabel Text=Username Action=Fill Value=admin | username admin is entered | - |
24-
| 2 | enter wrong password | Locator=GetByLabel Text=Password Action=Fill Value=test | password test is entered | - |
25-
| 3 | click login button | Locator=GetByRole AriaRole=Button Text=Login Action=Click | system validates the user credentials and displays an error message that the tried login attempt is invalid | - |
26-
| 4 | displays error message | Locator=GetByText Text=\"Invalid login attempt for user 'admin'\" Action=IsVisible | Validation result of invalid login attempt is visible | - |
23+
| 1 | enter username | Locator=GetByLabel Text=Username Action=Fill Value=admin | username admin is entered | |
24+
| 2 | enter wrong password | Locator=GetByLabel Text=Password Action=Fill Value=test | password test is entered | |
25+
| 3 | click login button | Locator=GetByRole AriaRole=Button Text=Login Action=Click | system validates the user credentials and displays an error message that the tried login attempt is invalid | |
26+
| 4 | displays error message | Locator=GetByText Text=\"Invalid login attempt for user 'admin'\" Action=IsVisible | Validation result of invalid login attempt is visible | |
2727

2828
## Postcondition
2929

3030
\-
31+

src/testr.Cli/Domain/MarkdownTableParser.cs

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,45 @@ public IEnumerable<TestStep> ParseTestSteps()
4848
return testSteps.OrderBy(ts => ts.Id);
4949
}
5050

51+
52+
/// <summary>
53+
/// Updates the "Actual Result" column in test steps table with test execution results
54+
/// </summary>
55+
/// <param name="testResults">Collection of test step results to apply</param>
56+
/// <returns>Updated markdown content with results applied to the table</returns>
57+
public string UpdateTestStepsWithResults(IEnumerable<TestStepResult> testResults)
58+
{
59+
var lines = _content.Split('\n');
60+
var inTable = false;
61+
62+
// First pass: find the test steps table
63+
for (int i = 0; i < lines.Length; i++)
64+
{
65+
var line = lines[i].Trim();
66+
67+
if (line.StartsWith("|") && line.EndsWith("|"))
68+
{
69+
if (!inTable && IsValidStepsTableHeader(line))
70+
{
71+
inTable = true;
72+
}
73+
else if (inTable && !IsSeparatorRow(line))
74+
{
75+
// This is a data row in our table
76+
var updatedRow = UpdateTableRowWithResults(line, testResults);
77+
lines[i] = updatedRow;
78+
}
79+
}
80+
else if (inTable)
81+
{
82+
// End of table
83+
break;
84+
}
85+
}
86+
87+
return string.Join('\n', lines);
88+
}
89+
5190
/// <summary>
5291
/// Extracts test steps by finding markdown tables with the expected column structure
5392
/// </summary>
@@ -268,6 +307,44 @@ private List<string> ParseTableCells(string row)
268307
return cells;
269308
}
270309

310+
/// <summary>
311+
/// Updates a single table row with test execution results
312+
/// </summary>
313+
private string UpdateTableRowWithResults(string row, IEnumerable<TestStepResult> testResults)
314+
{
315+
try
316+
{
317+
var cells = ParseTableCells(row);
318+
319+
// Ensure we have at least 5 cells (including Actual Result column)
320+
while (cells.Count < 5)
321+
{
322+
cells.Add(" - ");
323+
}
324+
325+
// Parse Step ID (first cell)
326+
if (int.TryParse(cells[0].Trim(), out var stepId))
327+
{
328+
// Find matching test result
329+
var testResult = testResults
330+
.FirstOrDefault(r => r.Step.Id == stepId && !r.IsSuccess);
331+
332+
// Update the Actual Result column (5th cell, index 4)
333+
cells[4] = testResult != null
334+
? $" ❌ {testResult.Error} "
335+
: " ✅ ";
336+
}
337+
338+
// Reconstruct the row
339+
return $"| {string.Join(" | ", cells.Select(c => c.Trim()))} |";
340+
}
341+
catch
342+
{
343+
// If parsing fails, return original row
344+
return row;
345+
}
346+
}
347+
271348
/// <summary>
272349
/// Unescapes markdown content, particularly handling escaped quotes and special characters
273350
/// </summary>

src/testr.Cli/Domain/TestCaseRun.cs

Lines changed: 8 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,16 @@ internal async Task SaveAsync(
2020
CancellationToken cancellationToken
2121
)
2222
{
23-
var lines = await File.ReadAllLinesAsync(_testCase.File, cancellationToken);
23+
var content = await File.ReadAllTextAsync(_testCase.File, cancellationToken);
24+
25+
// Update test steps using MarkdownTableParser
26+
var parser = new MarkdownTableParser(content);
27+
var updatedContent = parser.UpdateTestStepsWithResults(_results);
28+
29+
var lines = updatedContent.Split('\n');
2430

2531
SetProperties(lines, _results.All(r => r.IsSuccess));
2632
if (_testCase.HasDomain) lines = AppendDomainProperty(lines, _testCase.Domain);
27-
UpdateTestSteps(lines, _results);
2833

2934
// Ensure directory structure based on the input directory
3035
var relativePath = Path.GetRelativePath(inputDirectory, _testCase.File);
@@ -72,33 +77,4 @@ private string[] AppendDomainProperty(string[] lines, string domain)
7277
.Concat(lines.Skip(index))
7378
.ToArray();
7479
}
75-
76-
private void UpdateTestSteps(string[] lines, IEnumerable<TestStepResult> testResults)
77-
{
78-
// <!-- STEPS:BEGIN -->
79-
// | Step ID | Description | Test Data | Expected Result | Actual Result |
80-
// | ------- | ----------- | --------- | --------------- | ------------- |
81-
// | 1 | tbd | tbd | tbd | ✅ |
82-
// | 2 | tbd | tbd | tbd | ❌ error txt |
83-
// <!-- STEPS:END -->
84-
85-
var stepsBegin = Array.IndexOf(lines, "<!-- STEPS:BEGIN -->") + 3;
86-
var stepsEnd = Array.IndexOf(lines, "<!-- STEPS:END -->");
87-
var failed = false;
88-
89-
for (var i = stepsBegin; i < stepsEnd; i++)
90-
{
91-
var splittedItems = lines[i].Split('|');
92-
var stepId = splittedItems[1].Trim();
93-
var testResult = testResults
94-
.FirstOrDefault(r => r.Step.Id.ToString().ToLowerInvariant() == stepId.ToLowerInvariant()
95-
&& r.IsSuccess == false);
96-
failed = testResult != null;
97-
98-
splittedItems[5] = !failed
99-
? " ✅ "
100-
: $" ❌ {testResult?.Error} ";
101-
lines[i] = string.Join('|', splittedItems);
102-
}
103-
}
104-
}
80+
}

0 commit comments

Comments
 (0)