109 lines
4.9 KiB
C#
109 lines
4.9 KiB
C#
// 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 System.Net;
|
|
using System.Threading;
|
|
using System.Threading.Tasks;
|
|
using Microsoft.AspNetCore.E2ETesting;
|
|
using Microsoft.AspNetCore.Testing;
|
|
using Microsoft.AspNetCore.Testing.xunit;
|
|
using OpenQA.Selenium;
|
|
using Templates.Test.Helpers;
|
|
using Xunit;
|
|
using Xunit.Abstractions;
|
|
|
|
namespace Templates.Test
|
|
{
|
|
public class RazorComponentsTemplateTest : BrowserTestBase
|
|
{
|
|
public RazorComponentsTemplateTest(ProjectFactoryFixture projectFactory, BrowserFixture browserFixture, ITestOutputHelper output) : base(browserFixture, output)
|
|
{
|
|
ProjectFactory = projectFactory;
|
|
}
|
|
|
|
public ProjectFactoryFixture ProjectFactory { get; set; }
|
|
|
|
public Project Project { get; private set; }
|
|
|
|
[Fact]
|
|
[Flaky("https://github.com/aspnet/AspNetCore-Internal/issues/2407", FlakyOn.AzP.Windows)]
|
|
public async Task RazorComponentsTemplateWorks()
|
|
{
|
|
Project = await ProjectFactory.GetOrCreateProject("blazorserverside", Output);
|
|
|
|
var createResult = await Project.RunDotNetNewAsync("blazorserverside");
|
|
Assert.True(0 == createResult.ExitCode, ErrorMessages.GetFailedProcessMessage("create/restore", Project, createResult));
|
|
|
|
var publishResult = await Project.RunDotNetPublishAsync();
|
|
Assert.True(0 == publishResult.ExitCode, ErrorMessages.GetFailedProcessMessage("publish", Project, publishResult));
|
|
|
|
// Run dotnet build after publish. The reason is that one uses Config = Debug and the other uses Config = Release
|
|
// The output from publish will go into bin/Release/netcoreapp3.0/publish and won't be affected by calling build
|
|
// later, while the opposite is not true.
|
|
|
|
var buildResult = await Project.RunDotNetBuildAsync();
|
|
Assert.True(0 == buildResult.ExitCode, ErrorMessages.GetFailedProcessMessage("build", Project, buildResult));
|
|
|
|
using (var aspNetProcess = Project.StartBuiltProjectAsync())
|
|
{
|
|
Assert.False(
|
|
aspNetProcess.Process.HasExited,
|
|
ErrorMessages.GetFailedProcessMessageOrEmpty("Run built project", Project, aspNetProcess.Process));
|
|
|
|
await aspNetProcess.AssertStatusCode("/", HttpStatusCode.OK, "text/html");
|
|
if (BrowserFixture.IsHostAutomationSupported())
|
|
{
|
|
aspNetProcess.VisitInBrowser(Browser);
|
|
TestBasicNavigation();
|
|
}
|
|
}
|
|
|
|
using (var aspNetProcess = Project.StartPublishedProjectAsync())
|
|
{
|
|
Assert.False(
|
|
aspNetProcess.Process.HasExited,
|
|
ErrorMessages.GetFailedProcessMessageOrEmpty("Run published project", Project, aspNetProcess.Process));
|
|
|
|
await aspNetProcess.AssertStatusCode("/", HttpStatusCode.OK, "text/html");
|
|
if (BrowserFixture.IsHostAutomationSupported())
|
|
{
|
|
aspNetProcess.VisitInBrowser(Browser);
|
|
TestBasicNavigation();
|
|
}
|
|
}
|
|
}
|
|
|
|
private void TestBasicNavigation()
|
|
{
|
|
// Give components.server enough time to load so that it can replace
|
|
// the prerendered content before we start making assertions.
|
|
Thread.Sleep(5000);
|
|
Browser.Exists(By.TagName("ul"));
|
|
// <title> element gets project ID injected into it during template execution
|
|
Browser.Equal(Project.ProjectName.Trim(), () => Browser.Title.Trim());
|
|
|
|
// Initially displays the home page
|
|
Browser.Equal("Hello, world!", () => Browser.FindElement(By.TagName("h1")).Text);
|
|
|
|
// Can navigate to the counter page
|
|
Browser.FindElement(By.PartialLinkText("Counter")).Click();
|
|
Browser.Contains("counter", () => Browser.Url);
|
|
Browser.Equal("Counter", () => Browser.FindElement(By.TagName("h1")).Text);
|
|
|
|
// Clicking the counter button works
|
|
Browser.Equal("Current count: 0", () => Browser.FindElement(By.CssSelector("h1 + p")).Text);
|
|
Browser.FindElement(By.CssSelector("p+button")).Click();
|
|
Browser.Equal("Current count: 1", () => Browser.FindElement(By.CssSelector("h1 + p")).Text);
|
|
|
|
// Can navigate to the 'fetch data' page
|
|
Browser.FindElement(By.PartialLinkText("Fetch data")).Click();
|
|
Browser.Contains("fetchdata", () => Browser.Url);
|
|
Browser.Equal("Weather forecast", () => Browser.FindElement(By.TagName("h1")).Text);
|
|
|
|
// Asynchronously loads and displays the table of weather forecasts
|
|
Browser.Exists(By.CssSelector("table>tbody>tr"));
|
|
Browser.Equal(5, () => Browser.FindElements(By.CssSelector("p+table>tbody>tr")).Count);
|
|
}
|
|
}
|
|
}
|