Skip to content

Commit 5dc2d6e

Browse files
ryanbrandenburgwtgodbe
authored andcommitted
Extend timeout and report failure to WarmUp for template tests (#16759)
* Extend timeout and report failure to WarmUp for template tests * Retry click events
1 parent cf3bf40 commit 5dc2d6e

File tree

3 files changed

+28
-15
lines changed

3 files changed

+28
-15
lines changed

src/ProjectTemplates/test/BlazorServerTemplateTest.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -146,17 +146,17 @@ private void TestBasicNavigation()
146146
Browser.Equal("Hello, world!", () => Browser.FindElement(By.TagName("h1")).Text);
147147

148148
// Can navigate to the counter page
149-
Browser.FindElement(By.PartialLinkText("Counter")).Click();
149+
Browser.Click(By.PartialLinkText("Counter"));
150150
Browser.Contains("counter", () => Browser.Url);
151151
Browser.Equal("Counter", () => Browser.FindElement(By.TagName("h1")).Text);
152152

153153
// Clicking the counter button works
154154
Browser.Equal("Current count: 0", () => Browser.FindElement(By.CssSelector("h1 + p")).Text);
155-
Browser.FindElement(By.CssSelector("p+button")).Click();
155+
Browser.Click(By.CssSelector("p+button"));
156156
Browser.Equal("Current count: 1", () => Browser.FindElement(By.CssSelector("h1 + p")).Text);
157157

158158
// Can navigate to the 'fetch data' page
159-
Browser.FindElement(By.PartialLinkText("Fetch data")).Click();
159+
Browser.Click(By.PartialLinkText("Fetch data"));
160160
Browser.Contains("fetchdata", () => Browser.Url);
161161
Browser.Equal("Weather forecast", () => Browser.FindElement(By.TagName("h1")).Text);
162162

src/ProjectTemplates/test/SpaTemplateTest/SpaTemplateTestBase.cs

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
33

44
using System;
5+
using System.Diagnostics;
56
using System.IO;
67
using System.Linq;
78
using System.Net;
@@ -193,8 +194,11 @@ private void ValidatePackageJson(string clientAppSubdirPath)
193194

194195
private static async Task WarmUpServer(AspNetProcess aspNetProcess)
195196
{
197+
var intervalInSeconds = 5;
196198
var attempt = 0;
197-
var maxAttempts = 3;
199+
var maxAttempts = 5;
200+
var stopwatch = new Stopwatch();
201+
stopwatch.Start();
198202
do
199203
{
200204
try
@@ -203,7 +207,7 @@ private static async Task WarmUpServer(AspNetProcess aspNetProcess)
203207
var response = await aspNetProcess.SendRequest("/");
204208
if (response.StatusCode == HttpStatusCode.OK)
205209
{
206-
break;
210+
return;
207211
}
208212
}
209213
catch (OperationCanceledException)
@@ -212,8 +216,11 @@ private static async Task WarmUpServer(AspNetProcess aspNetProcess)
212216
catch (HttpRequestException ex) when (ex.Message.StartsWith("The SSL connection could not be established"))
213217
{
214218
}
215-
await Task.Delay(TimeSpan.FromSeconds(5 * attempt));
219+
var currentDelay = intervalInSeconds * attempt;
220+
await Task.Delay(TimeSpan.FromSeconds(currentDelay));
216221
} while (attempt < maxAttempts);
222+
stopwatch.Stop();
223+
throw new TimeoutException($"Could not contact the server within {stopwatch.Elapsed.TotalSeconds} seconds");
217224
}
218225

219226
private void UpdatePublishedSettings()
@@ -246,50 +253,50 @@ private void TestBasicNavigation(bool visitFetchData, bool usesAuth, IWebDriver
246253
browser.Equal("Hello, world!", () => browser.FindElement(By.TagName("h1")).Text);
247254

248255
// Can navigate to the counter page
249-
browser.FindElement(By.PartialLinkText("Counter")).Click();
256+
browser.Click(By.PartialLinkText("Counter"));
250257
browser.Contains("counter", () => browser.Url);
251258

252259
browser.Equal("Counter", () => browser.FindElement(By.TagName("h1")).Text);
253260

254261
// Clicking the counter button works
255262
browser.Equal("0", () => browser.FindElement(By.CssSelector("p>strong")).Text);
256-
browser.FindElement(By.CssSelector("p+button")).Click();
263+
browser.Click(By.CssSelector("p+button")) ;
257264
browser.Equal("1", () => browser.FindElement(By.CssSelector("p>strong")).Text);
258265

259266
if (visitFetchData)
260267
{
261-
browser.FindElement(By.PartialLinkText("Fetch data")).Click();
268+
browser.Click(By.PartialLinkText("Fetch data"));
262269

263270
if (usesAuth)
264271
{
265272
// We will be redirected to the identity UI
266273
browser.Contains("/Identity/Account/Login", () => browser.Url);
267-
browser.FindElement(By.PartialLinkText("Register as a new user")).Click();
274+
browser.Click(By.PartialLinkText("Register as a new user"));
268275

269276
var userName = $"{Guid.NewGuid()}@example.com";
270277
var password = $"!Test.Password1$";
271278
browser.Exists(By.Name("Input.Email"));
272279
browser.FindElement(By.Name("Input.Email")).SendKeys(userName);
273280
browser.FindElement(By.Name("Input.Password")).SendKeys(password);
274281
browser.FindElement(By.Name("Input.ConfirmPassword")).SendKeys(password);
275-
browser.FindElement(By.Id("registerSubmit")).Click();
282+
browser.Click(By.Id("registerSubmit"));
276283

277284
// We will be redirected to the RegisterConfirmation
278285
browser.Contains("/Identity/Account/RegisterConfirmation", () => browser.Url);
279-
browser.FindElement(By.PartialLinkText("Click here to confirm your account")).Click();
286+
browser.Click(By.PartialLinkText("Click here to confirm your account"));
280287

281288
// We will be redirected to the ConfirmEmail
282289
browser.Contains("/Identity/Account/ConfirmEmail", () => browser.Url);
283290

284291
// Now we can login
285-
browser.FindElement(By.PartialLinkText("Login")).Click();
292+
browser.Click(By.PartialLinkText("Login"));
286293
browser.Exists(By.Name("Input.Email"));
287294
browser.FindElement(By.Name("Input.Email")).SendKeys(userName);
288295
browser.FindElement(By.Name("Input.Password")).SendKeys(password);
289-
browser.FindElement(By.Id("login-submit")).Click();
296+
browser.Click(By.Id("login-submit"));
290297

291298
// Need to navigate to fetch page
292-
browser.FindElement(By.PartialLinkText("Fetch data")).Click();
299+
browser.Click(By.PartialLinkText("Fetch data"));
293300
}
294301

295302
// Can navigate to the 'fetch data' page

src/Shared/E2ETesting/WaitAssert.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,12 @@ public static IWebElement Exists(this IWebDriver driver, By finder, TimeSpan tim
6363
return result;
6464
}, timeout);
6565

66+
public static void Click(this IWebDriver driver, By selector)
67+
=> WaitAssertCore(driver, () =>
68+
{
69+
driver.FindElement(selector).Click();
70+
});
71+
6672
private static void WaitAssertCore(IWebDriver driver, Action assertion, TimeSpan timeout = default)
6773
{
6874
WaitAssertCore<object>(driver, () => { assertion(); return null; }, timeout);

0 commit comments

Comments
 (0)