Skip to content

Commit d4d8d5c

Browse files
captainsafiaHaoK
authored andcommitted
Migrate DownloadFileFromAnchor test to Playwright (#32499)
* Migrate DownloadFileFromAnchor test to Playwright * Unquarantine migrated test
1 parent da37c59 commit d4d8d5c

File tree

2 files changed

+66
-72
lines changed

2 files changed

+66
-72
lines changed

src/Components/test/E2ETest/Tests/DownloadAnchorTest.cs

Lines changed: 0 additions & 72 deletions
This file was deleted.
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
// Copyright (c) .NET Foundation. All rights reserved.
2+
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
3+
4+
using System;
5+
using System.Threading.Tasks;
6+
using BasicTestApp;
7+
using BasicTestApp.RouterTest;
8+
using Microsoft.AspNetCore.BrowserTesting;
9+
using Microsoft.AspNetCore.Components.E2ETest.Infrastructure;
10+
using Microsoft.AspNetCore.Components.E2ETest.Infrastructure.ServerFixtures;
11+
using Microsoft.AspNetCore.Testing;
12+
using Moq;
13+
using PlaywrightSharp;
14+
using Xunit;
15+
using Xunit.Abstractions;
16+
17+
namespace Microsoft.AspNetCore.Components.E2ETest.Tests
18+
{
19+
public class DownloadAnchorTest
20+
: ServerTestBase<ToggleExecutionModeServerFixture<Program>>
21+
{
22+
public DownloadAnchorTest(
23+
ToggleExecutionModeServerFixture<Program> serverFixture,
24+
ITestOutputHelper output)
25+
: base(serverFixture, output)
26+
{
27+
}
28+
29+
private IPage _page;
30+
private IBrowserContext _browser;
31+
32+
protected override async Task InitializeCoreAsync(TestContext context)
33+
{
34+
await base.InitializeCoreAsync(context);
35+
36+
_browser = await BrowserManager.GetBrowserInstance(BrowserKind.Chromium, BrowserContextInfo);
37+
var page = await _browser.NewPageAsync();
38+
var url = _serverFixture.RootUri + "subdir";
39+
var response = await page.GoToAsync(url);
40+
41+
await MountTestComponentAsync<TestRouter>(page);
42+
_page = page;
43+
}
44+
45+
[Fact]
46+
public async Task DownloadFileFromAnchor()
47+
{
48+
// Arrange
49+
var initialUrl = _page.Url;
50+
var downloadTask = _page.WaitForEventAsync(PageEvent.Download);
51+
52+
// Act
53+
await Task.WhenAll(
54+
downloadTask,
55+
_page.ClickAsync("a[download]"));
56+
57+
// Assert URL should still be same as before click
58+
Assert.Equal(initialUrl, _page.Url);
59+
60+
// Assert that the resource was downloaded
61+
var download = downloadTask.Result.Download;
62+
Assert.Equal($"{_serverFixture.RootUri}subdir/images/blazor_logo_1000x.png", download.Url);
63+
Assert.Equal("blazor_logo_1000x.png", download.SuggestedFilename);
64+
}
65+
}
66+
}

0 commit comments

Comments
 (0)