forked from dotnet/try
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathTryDotNetJsIntegrationTests.cs
More file actions
124 lines (98 loc) · 4.75 KB
/
TryDotNetJsIntegrationTests.cs
File metadata and controls
124 lines (98 loc) · 4.75 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
// Copyright (c) .NET Foundation and contributors. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Threading.Tasks;
using AwesomeAssertions;
using Microsoft.AspNetCore.WebUtilities;
using Microsoft.Playwright;
using Pocket.For.Xunit;
using Xunit.Abstractions;
namespace Microsoft.TryDotNet.IntegrationTests;
[LogToPocketLogger(FileNameEnvironmentVariable = "POCKETLOGGER_LOG_PATH")]
[Trait("TestType", "Integration")]
public class TryDotNetJsIntegrationTests : PlaywrightTestBase
{
public TryDotNetJsIntegrationTests(IntegratedServicesFixture services, ITestOutputHelper output) : base(services, output)
{
}
[IntegrationTestFact(Skip = "Flaky in CI")]
public async Task loads_trydotnet_editor()
{
var page = await NewPageAsync();
var learnRoot = (await Services.GetLearnServerAsync()).Url;
var trydotnetOrigin = await TryDotNetUrlAsync();
var trydotnetUrl = new Uri(trydotnetOrigin, "api/trydotnet.min.js");
var param = new Dictionary<string, string>
{
["trydotnetUrl"] = trydotnetUrl.ToString(),
["trydotnetOrigin"] = trydotnetOrigin.ToString()
};
var pageUri = new Uri(QueryHelpers.AddQueryString(new Uri(learnRoot,"DocsHost.html").ToString(), param!));
await page.GotoAsync(pageUri.ToString());
await page.WaitForLoadStateAsync(LoadState.NetworkIdle);
await page.FindEditor();
}
[IntegrationTestFact(Skip = "Flaky in CI")]
public async Task can_load_code()
{
var page = await NewPageAsync();
var interceptor = new MessageInterceptor();
await interceptor.InstallAsync(page);
var learnRoot = (await Services.GetLearnServerAsync()).Url;
var trydotnetOrigin = (await Services.GetTryDotNetServerAsync()).Url;
var trydotnetUrl = new Uri(trydotnetOrigin, "api/trydotnet.min.js");
var param = new Dictionary<string, string>
{
["trydotnetUrl"] = trydotnetUrl.ToString(),
["trydotnetOrigin"] = trydotnetOrigin.ToString(),
};
var pageUri = new Uri(QueryHelpers.AddQueryString(new Uri(learnRoot, "DocsHost.html").ToString(), param!));
await page.GotoAsync(pageUri.ToString());
await page.WaitForLoadStateAsync(LoadState.NetworkIdle);
var dotnetOnline = new DotNetOnline(page);
await dotnetOnline.FocusAsync();
await page.SetCodeUsingTryDotNetJsApi(interceptor, "Console.WriteLine(123);");
await page.TestScreenShotAsync();
var text = await page.FrameLocator("body > div > div.dotnet-online-editor-section > iframe").GetEditorContentAsync();
text.Should().Contain("Console.WriteLine(123);");
}
[IntegrationTestFact(Skip = "Flaky in CI")]
public async Task outputs_are_rendered()
{
var page = await NewPageAsync();
var interceptor = new MessageInterceptor();
await interceptor.InstallAsync(page);
var learnRoot = await LearnUrlAsync();
var trydotnetOrigin = await TryDotNetUrlAsync();
var trydotnetUrl = new Uri(trydotnetOrigin, "api/trydotnet.min.js");
var param = new Dictionary<string, string>
{
["trydotnetUrl"] = trydotnetUrl.ToString(),
["trydotnetOrigin"] = trydotnetOrigin.ToString(),
};
var pageUri = new Uri(QueryHelpers.AddQueryString(new Uri(learnRoot, "DocsHost.html").ToString(), param!));
await page.GotoAsync(pageUri.ToString());
await page.WaitForLoadStateAsync(LoadState.NetworkIdle);
var dotnetOnline = new DotNetOnline(page);
await dotnetOnline.FocusAsync();
await page.SetCodeUsingTryDotNetJsApi(interceptor, "Console.WriteLine(123);");
await page.TestScreenShotAsync("before_run");
var run = interceptor.AwaitForMessage("RunCompleted", TimeSpan.FromMinutes(10));
await page.RunAndWaitForConsoleMessageAsync(async () =>
{
await dotnetOnline.ExecuteAsync();
}, new PageRunAndWaitForConsoleMessageOptions
{
Timeout = Debugger.IsAttached ? 0.0f: (float) TimeSpan.FromMinutes(10).TotalMilliseconds,
Predicate = message => message.Text.Contains("---- resolving response awaiter for") && message.Text.Contains("and type [RunCompleted]")
});
await run;
await page.TestScreenShotAsync("after_run");
var outputElement = page.Locator("body > div > div.dotnet-online-editor-section > pre");
await page.TestScreenShotAsync("output_grabbed");
var result = await outputElement.TextContentAsync();
result.Should().Be("123\n");
}
}