// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using OpenQA.Selenium; using System.IO; using System.Net; using Templates.Test.Helpers; using Templates.Test.Infrastructure; using Xunit; using Xunit.Abstractions; // Turn off parallel test run for Edge as the driver does not support multiple Selenium tests at the same time #if EDGE [assembly: CollectionBehavior(CollectionBehavior.CollectionPerAssembly)] #endif [assembly: TestFramework("Templates.Test.Helpers.XunitExtensions.XunitTestFrameworkWithAssemblyFixture", "Templates.Test")] namespace Templates.Test.SpaTemplateTest { public class SpaTemplateTestBase : BrowserTestBase { public SpaTemplateTestBase(BrowserFixture browserFixture, ITestOutputHelper output) : base(browserFixture, output) { } // Rather than using [Theory] to pass each of the different values for 'template', // it's important to distribute the SPA template tests over different test classes // so they can be run in parallel. Xunit doesn't parallelize within a test class. protected void SpaTemplateImpl(string targetFrameworkOverride, string template, bool noHttps = false) { RunDotNetNew(template, targetFrameworkOverride, noHttps: noHttps); // For some SPA templates, the NPM root directory is './ClientApp'. In other // templates it's at the project root. Strictly speaking we shouldn't have // to do the NPM restore in tests because it should happen automatically at // build time, but by doing it up front we can avoid having multiple NPM // installs run concurrently which otherwise causes errors when tests run // in parallel. var clientAppSubdirPath = Path.Combine(TemplateOutputDir, "ClientApp"); Assert.True(File.Exists(Path.Combine(clientAppSubdirPath, "package.json")), "Missing a package.json"); Npm.RestoreWithRetry(Output, clientAppSubdirPath); Npm.Test(Output, clientAppSubdirPath); TestApplication(targetFrameworkOverride, publish: false); TestApplication(targetFrameworkOverride, publish: true); } private void TestApplication(string targetFrameworkOverride, bool publish) { using (var aspNetProcess = StartAspNetProcess(targetFrameworkOverride, publish)) { aspNetProcess.AssertStatusCode("/", HttpStatusCode.OK, "text/html"); if (WebDriverFactory.HostSupportsBrowserAutomation) { aspNetProcess.VisitInBrowser(Browser); TestBasicNavigation(); } } } private void TestBasicNavigation() { Browser.WaitForElement("ul"); //