Skip to content

Commit cef2fea

Browse files
committed
refactor: optimize async method calls in TestCaseExecutor
1 parent 76e884b commit cef2fea

File tree

1 file changed

+12
-13
lines changed

1 file changed

+12
-13
lines changed

src/testr.Cli/Domain/TestCaseExecutor.cs

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,6 @@ public async Task<IEnumerable<TestStepResult>> ExecuteAsync(
1919
CancellationToken cancellationToken
2020
)
2121
{
22-
var results = new List<TestStepResult>();
23-
2422
using var playwright = await Playwright.CreateAsync();
2523
await using var browser = await GetBrowserType(playwright)
2624
.LaunchAsync(new BrowserTypeLaunchOptions
@@ -49,6 +47,7 @@ await TestAsync(
4947

5048
await NavigateToRouteAsync(page, domain, executionParam.Route);
5149

50+
var results = new List<TestStepResult>();
5251
foreach (var instruction in executionParam.Instructions)
5352
{
5453
var result = await TestAsync(
@@ -115,7 +114,7 @@ string route
115114
}
116115
}
117116

118-
private async Task<TestStepResult> TestAsync(
117+
private static async Task<TestStepResult> TestAsync(
119118
IPage page,
120119
TestStepInstruction instruction,
121120
Action<TestStepInstruction> consoleAction
@@ -133,7 +132,7 @@ Action<TestStepInstruction> consoleAction
133132
return TestStepResult.Success(instruction.TestStep);
134133
}
135134

136-
private static async Task<bool> ProcessStepAsync(
135+
private static Task<bool> ProcessStepAsync(
137136
IPage page,
138137
TestStepInstruction instruction,
139138
Action<TestStepInstruction> consoleAction
@@ -143,7 +142,7 @@ Action<TestStepInstruction> consoleAction
143142

144143
ILocator? locator = EvaluateLocator(page, instruction);
145144

146-
return await ExecuteAction(instruction, locator);
145+
return ExecuteAction(instruction, locator);
147146
}
148147

149148
private static ILocator EvaluateLocator(
@@ -163,28 +162,28 @@ TestStepInstruction instruction
163162
return locator;
164163
}
165164

166-
private static async Task<bool> ExecuteAction(
165+
private static Task<bool> ExecuteAction(
167166
TestStepInstruction instruction,
168167
ILocator locator
169168
)
170169
{
171170
if (instruction.Action == ActionType.Click)
172171
{
173-
await locator.ClickAsync();
172+
locator.ClickAsync();
174173
}
175174
else if (instruction.Action == ActionType.Fill)
176175
{
177-
await locator.FillAsync(instruction.Value);
176+
locator.FillAsync(instruction.Value);
178177
}
179178
else if (instruction.Action == ActionType.PickFile)
180179
{
181-
await locator.SetInputFilesAsync(instruction.Value);
180+
locator.SetInputFilesAsync(instruction.Value);
182181
}
183-
else
182+
else if (instruction.Action == ActionType.IsVisible)
184183
{
185-
return await locator.IsVisibleAsync();
184+
return locator.IsVisibleAsync();
186185
}
187186

188-
return await Task.FromResult(true);
187+
return Task.FromResult(true);
189188
}
190-
}
189+
}

0 commit comments

Comments
 (0)