Skip to content

Commit b9f325a

Browse files
authored
Introduce Chrome for testing (#2278)
* Introduce Chrome for testing * Fix some tests * Fix some tests * code factor * Fix firefox * More firefox fixes * cache versions * Refactor Firefox buildId * add some logging * add -v n to github actions * Improve error reporting * Fix firefox download * unflake * self review * Add chrome data tests * Add chrome cli test * Improve the test * Code factor * Fix tests * Add more data an cli tests * cleanup csproj * cr * cr
1 parent 2e21ecd commit b9f325a

36 files changed

+1063
-647
lines changed

lib/.editorconfig

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -285,6 +285,8 @@ dotnet_diagnostic.CA1001.severity = error
285285
dotnet_diagnostic.CA1304.severity = error
286286
# CA1305: String.Format with culture
287287
dotnet_diagnostic.CA1305.severity = error
288+
# CA1304: CA1308: Normalize strings to uppercase
289+
dotnet_diagnostic.CA1308.severity = none
288290
# CA1721: The property name 'DefaultArgs' is confusing given the existence of method 'GetDefaultArgs'. Rename or remove one of these members.
289291
dotnet_diagnostic.CA1721.severity = error
290292
# CA1724: The type name Extensions conflicts in whole or in part with the namespace name 'Microsoft.Extensions'. Change either name to eliminate the conflict.
Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
using System;
2+
using System.IO;
3+
using NUnit.Framework;
4+
using PuppeteerSharp.BrowserData;
5+
using PuppeteerSharp.Nunit;
6+
using PuppeteerSharp.Tests.Attributes;
7+
8+
namespace PuppeteerSharp.Tests.Browsers.Chrome
9+
{
10+
public class ChromeDataTests
11+
{
12+
[PuppeteerTest("chrome-data.spec.ts", "Chrome", "should resolve download URLs")]
13+
public void ShouldResolveDownloadUrls()
14+
{
15+
Assert.AreEqual(
16+
"https://edgedl.me.gvt1.com/edgedl/chrome/chrome-for-testing/113.0.5672.0/linux64/chrome-linux64.zip",
17+
BrowserData.Chrome.ResolveDownloadUrl(Platform.Linux, "113.0.5672.0", null));
18+
Assert.AreEqual(
19+
"https://edgedl.me.gvt1.com/edgedl/chrome/chrome-for-testing/113.0.5672.0/mac-x64/chrome-mac-x64.zip",
20+
BrowserData.Chrome.ResolveDownloadUrl(Platform.MacOS, "113.0.5672.0", null));
21+
Assert.AreEqual(
22+
"https://edgedl.me.gvt1.com/edgedl/chrome/chrome-for-testing/113.0.5672.0/mac-arm64/chrome-mac-arm64.zip",
23+
BrowserData.Chrome.ResolveDownloadUrl(Platform.MacOSArm64, "113.0.5672.0", null));
24+
Assert.AreEqual(
25+
"https://edgedl.me.gvt1.com/edgedl/chrome/chrome-for-testing/113.0.5672.0/win32/chrome-win32.zip",
26+
BrowserData.Chrome.ResolveDownloadUrl(Platform.Win32, "113.0.5672.0", null));
27+
Assert.AreEqual(
28+
"https://edgedl.me.gvt1.com/edgedl/chrome/chrome-for-testing/113.0.5672.0/win64/chrome-win64.zip",
29+
BrowserData.Chrome.ResolveDownloadUrl(Platform.Win64, "113.0.5672.0", null));
30+
}
31+
32+
[PuppeteerTest("chrome-data.spec.ts", "Chrome", "should resolve executable paths")]
33+
public void ShouldResolveExecutablePath()
34+
{
35+
Assert.AreEqual(
36+
Path.Combine("chrome-linux64", "chrome"),
37+
BrowserData.Chrome.RelativeExecutablePath(Platform.Linux, "12372323"));
38+
39+
Assert.AreEqual(
40+
Path.Combine(
41+
"chrome-mac-x64",
42+
"Google Chrome for Testing.app",
43+
"Contents",
44+
"MacOS",
45+
"Google Chrome for Testing"
46+
),
47+
BrowserData.Chrome.RelativeExecutablePath(Platform.MacOS, "12372323"));
48+
49+
Assert.AreEqual(
50+
Path.Combine(
51+
"chrome-mac-arm64",
52+
"Google Chrome for Testing.app",
53+
"Contents",
54+
"MacOS",
55+
"Google Chrome for Testing"
56+
),
57+
BrowserData.Chrome.RelativeExecutablePath(Platform.MacOSArm64, "12372323"));
58+
59+
Assert.AreEqual(
60+
Path.Combine("chrome-win32", "chrome.exe"),
61+
BrowserData.Chrome.RelativeExecutablePath(Platform.Win32, "12372323"));
62+
63+
Assert.AreEqual(
64+
BrowserData.Chrome.RelativeExecutablePath(Platform.Win64, "12372323"),
65+
Path.Combine("chrome-win64", "chrome.exe"));
66+
}
67+
68+
[PuppeteerTest("chrome-data.spec.ts", "Chrome", "should resolve system executable path")]
69+
[Skip(SkipAttribute.Targets.Linux, SkipAttribute.Targets.OSX)]
70+
public void ShouldResolveSystemExecutablePathWindows()
71+
{
72+
Assert.AreEqual(
73+
"C:\\Program Files\\Google\\Chrome Dev\\Application\\chrome.exe",
74+
BrowserData.Chrome.ResolveSystemExecutablePath(
75+
Platform.Win32,
76+
ChromeReleaseChannel.Dev));
77+
}
78+
79+
[PuppeteerTest("chrome-data.spec.ts", "Chrome", "should resolve system executable path")]
80+
public void ShouldResolveSystemExecutablePath()
81+
{
82+
Assert.AreEqual(
83+
"/Applications/Google Chrome Beta.app/Contents/MacOS/Google Chrome Beta",
84+
BrowserData.Chrome.ResolveSystemExecutablePath(
85+
Platform.MacOS,
86+
ChromeReleaseChannel.Beta));
87+
88+
var ex = Assert.Throws<PuppeteerException>(() => {
89+
BrowserData.Chrome.ResolveSystemExecutablePath(
90+
Platform.Linux,
91+
ChromeReleaseChannel.Canary);
92+
});
93+
94+
Assert.AreEqual("Canary is not supported", ex.Message);
95+
}
96+
}
97+
}
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
using System;
2+
using System.IO;
3+
using System.Threading.Tasks;
4+
using NUnit.Framework;
5+
using PuppeteerSharp.BrowserData;
6+
using PuppeteerSharp.Nunit;
7+
8+
namespace PuppeteerSharp.Tests.Browsers.Chrome
9+
{
10+
/// <summary>
11+
/// Puppeteer sharp doesn't have a CLI per se. But it matches the test we have upstream.
12+
/// </summary>
13+
public class CliTests
14+
{
15+
private readonly string _cacheDir = Path.Combine(Path.GetTempPath(), Path.GetRandomFileName());
16+
17+
[SetUp]
18+
public void CreateDir()
19+
=> new DirectoryInfo(_cacheDir).Create();
20+
21+
[TearDown]
22+
public void DeleteDir()
23+
=> new Cache(_cacheDir).Clear();
24+
25+
[PuppeteerTest("CLI.spec.ts", "Chrome CLI", "should download Chrome binaries")]
26+
public async Task ShouldDownloadChromeBinaries()
27+
{
28+
using var fetcher = new BrowserFetcher(SupportedBrowser.Chrome)
29+
{
30+
CacheDir = _cacheDir,
31+
Platform = Platform.Linux
32+
};
33+
await fetcher.DownloadAsync(BrowserData.Chrome.DefaultBuildId);
34+
35+
Assert.True(new FileInfo(Path.Combine(
36+
_cacheDir,
37+
"Chrome",
38+
$"Linux-{BrowserData.Chrome.DefaultBuildId}",
39+
"chrome-linux64",
40+
"chrome")).Exists);
41+
}
42+
}
43+
}
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
using System;
2+
using System.IO;
3+
using NUnit.Framework;
4+
using PuppeteerSharp.Nunit;
5+
6+
namespace PuppeteerSharp.Tests.Browsers.Chromium
7+
{
8+
public class ChromiumDataTests
9+
{
10+
[PuppeteerTest("chromium-data.spec.ts", "Chromium", "should resolve download URLs")]
11+
public void ShouldResolveDownloadUrls()
12+
{
13+
Assert.AreEqual(
14+
"https://storage.googleapis.com/chromium-browser-snapshots/Linux_x64/1083080/chrome-linux.zip",
15+
BrowserData.Chromium.ResolveDownloadUrl(Platform.Linux, "1083080", null));
16+
Assert.AreEqual(
17+
"https://storage.googleapis.com/chromium-browser-snapshots/Mac/1083080/chrome-mac.zip",
18+
BrowserData.Chromium.ResolveDownloadUrl(Platform.MacOS, "1083080", null));
19+
Assert.AreEqual(
20+
"https://storage.googleapis.com/chromium-browser-snapshots/Mac_Arm/1083080/chrome-mac.zip",
21+
BrowserData.Chromium.ResolveDownloadUrl(Platform.MacOSArm64, "1083080", null));
22+
Assert.AreEqual(
23+
"https://storage.googleapis.com/chromium-browser-snapshots/Win/1083080/chrome-win.zip",
24+
BrowserData.Chromium.ResolveDownloadUrl(Platform.Win32, "1083080", null));
25+
Assert.AreEqual(
26+
"https://storage.googleapis.com/chromium-browser-snapshots/Win_x64/1083080/chrome-win.zip",
27+
BrowserData.Chromium.ResolveDownloadUrl(Platform.Win64, "1083080", null));
28+
}
29+
30+
[PuppeteerTest("chromium-data.spec.ts", "Chromium", "should resolve executable paths")]
31+
public void ShouldResolveExecutablePath()
32+
{
33+
Assert.AreEqual(
34+
Path.Combine("chrome-linux", "chrome"),
35+
BrowserData.Chromium.RelativeExecutablePath(Platform.Linux, "12372323"));
36+
37+
Assert.AreEqual(
38+
Path.Combine(
39+
"chrome-mac",
40+
"Chromium.app",
41+
"Contents",
42+
"MacOS",
43+
"Chromium"
44+
),
45+
BrowserData.Chromium.RelativeExecutablePath(Platform.MacOS, "12372323"));
46+
47+
Assert.AreEqual(
48+
Path.Combine(
49+
"chrome-mac",
50+
"Chromium.app",
51+
"Contents",
52+
"MacOS",
53+
"Chromium"
54+
),
55+
BrowserData.Chromium.RelativeExecutablePath(Platform.MacOSArm64, "12372323"));
56+
57+
Assert.AreEqual(
58+
Path.Combine("chrome-win", "chrome.exe"),
59+
BrowserData.Chromium.RelativeExecutablePath(Platform.Win32, "12372323"));
60+
61+
Assert.AreEqual(
62+
BrowserData.Chromium.RelativeExecutablePath(Platform.Win64, "12372323"),
63+
Path.Combine("chrome-win", "chrome.exe"));
64+
}
65+
}
66+
}
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
using System;
2+
using System.IO;
3+
using System.Threading.Tasks;
4+
using NUnit.Framework;
5+
using PuppeteerSharp.BrowserData;
6+
using PuppeteerSharp.Nunit;
7+
8+
namespace PuppeteerSharp.Tests.Browsers.Firefox
9+
{
10+
/// <summary>
11+
/// Puppeteer sharp doesn't have a CLI per se. But it matches the test we have upstream.
12+
/// </summary>
13+
public class CliTests
14+
{
15+
private readonly string _cacheDir = Path.Combine(Path.GetTempPath(), Path.GetRandomFileName());
16+
17+
[SetUp]
18+
public void CreateDir()
19+
=> new DirectoryInfo(_cacheDir).Create();
20+
21+
[TearDown]
22+
public void DeleteDir()
23+
=> new Cache(_cacheDir).Clear();
24+
25+
[PuppeteerTest("CLI.spec.ts", "Chrome CLI", "should download Chrome binaries")]
26+
public async Task ShouldDownloadChromeBinaries()
27+
{
28+
using var fetcher = new BrowserFetcher(SupportedBrowser.Chrome)
29+
{
30+
CacheDir = _cacheDir,
31+
Platform = Platform.Linux
32+
};
33+
await fetcher.DownloadAsync(BrowserData.Chrome.DefaultBuildId);
34+
35+
Assert.True(new FileInfo(Path.Combine(
36+
_cacheDir,
37+
"Chrome",
38+
$"Linux-{BrowserData.Chrome.DefaultBuildId}",
39+
"chrome-linux64",
40+
"chrome")).Exists);
41+
}
42+
}
43+
}
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
using System;
2+
using System.IO;
3+
using NUnit.Framework;
4+
using PuppeteerSharp.BrowserData;
5+
using PuppeteerSharp.Nunit;
6+
using PuppeteerSharp.Tests.Attributes;
7+
8+
namespace PuppeteerSharp.Tests.Browsers.Firefox
9+
{
10+
public class FirefoxDataTests
11+
{
12+
[PuppeteerTest("firefox-data.spec.ts", "Firefox", "should resolve download URLs")]
13+
public void ShouldResolveDownloadUrls()
14+
{
15+
Assert.AreEqual(
16+
"https://archive.mozilla.org/pub/firefox/nightly/latest-mozilla-central/firefox-111.0a1.en-US.linux-x86_64.tar.bz2",
17+
BrowserData.Firefox.ResolveDownloadUrl(Platform.Linux, "111.0a1", null));
18+
Assert.AreEqual(
19+
"https://archive.mozilla.org/pub/firefox/nightly/latest-mozilla-central/firefox-111.0a1.en-US.mac.dmg",
20+
BrowserData.Firefox.ResolveDownloadUrl(Platform.MacOS, "111.0a1", null));
21+
Assert.AreEqual(
22+
"https://archive.mozilla.org/pub/firefox/nightly/latest-mozilla-central/firefox-111.0a1.en-US.mac.dmg",
23+
BrowserData.Firefox.ResolveDownloadUrl(Platform.MacOSArm64, "111.0a1", null));
24+
Assert.AreEqual(
25+
"https://archive.mozilla.org/pub/firefox/nightly/latest-mozilla-central/firefox-111.0a1.en-US.win32.zip",
26+
BrowserData.Firefox.ResolveDownloadUrl(Platform.Win32, "111.0a1", null));
27+
Assert.AreEqual(
28+
"https://archive.mozilla.org/pub/firefox/nightly/latest-mozilla-central/firefox-111.0a1.en-US.win64.zip",
29+
BrowserData.Firefox.ResolveDownloadUrl(Platform.Win64, "111.0a1", null));
30+
}
31+
32+
[PuppeteerTest("firefox-data.spec.ts", "Firefox", "should resolve executable paths")]
33+
public void ShouldResolveExecutablePath()
34+
{
35+
Assert.AreEqual(
36+
Path.Combine("firefox", "firefox"),
37+
BrowserData.Firefox.RelativeExecutablePath(Platform.Linux, "111.0a1"));
38+
39+
Assert.AreEqual(
40+
Path.Combine(
41+
"Firefox Nightly.app",
42+
"Contents",
43+
"MacOS",
44+
"firefox"
45+
),
46+
BrowserData.Firefox.RelativeExecutablePath(Platform.MacOS, "111.0a1"));
47+
48+
Assert.AreEqual(
49+
Path.Combine(
50+
"Firefox Nightly.app",
51+
"Contents",
52+
"MacOS",
53+
"firefox"
54+
),
55+
BrowserData.Firefox.RelativeExecutablePath(Platform.MacOSArm64, "111.0a1"));
56+
57+
Assert.AreEqual(
58+
Path.Combine("firefox", "firefox.exe"),
59+
BrowserData.Firefox.RelativeExecutablePath(Platform.Win32, "111.0a1"));
60+
61+
Assert.AreEqual(
62+
BrowserData.Firefox.RelativeExecutablePath(Platform.Win64, "111.0a1"),
63+
Path.Combine("firefox", "firefox.exe"));
64+
}
65+
}
66+
}

lib/PuppeteerSharp.Tests/CoverageTests/CSSCoverageTests.cs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,12 @@ public async Task ShouldWorkWithMediaQueries()
9191
new CoverageEntryRange
9292
{
9393
Start = 8,
94-
End = 40
94+
End = 15
95+
},
96+
new CoverageEntryRange
97+
{
98+
Start = 17,
99+
End = 38
95100
}
96101
}, coverage[0].Ranges);
97102
}
@@ -110,7 +115,11 @@ public async Task ShouldWorkWithComplicatedUsecases()
110115
},
111116
{
112117
""Start"": 306,
113-
""End"": 435
118+
""End"": 323
119+
},
120+
{
121+
""Start"": 327,
122+
""End"": 433
114123
}
115124
],
116125
""Text"": ""\n @charset \""utf - 8\"";\n@namespace svg url(http://www.w3.org/2000/svg);\n@font-face {\n font-family: \""Example Font\"";\n src: url(\""./Dosis-Regular.ttf\"");\n}\n\n#fluffy {\n border: 1px solid black;\n z-index: 1;\n /* -webkit-disabled-property: rgb(1, 2, 3) */\n -lol-cats: \""dogs\"" /* non-existing property */\n}\n\n@media (min-width: 1px) {\n span {\n -webkit-border-radius: 10px;\n font-family: \""Example Font\"";\n animation: 1s identifier;\n }\n}\n""

lib/PuppeteerSharp.Tests/CoverageTests/JSCoverageTests.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,8 @@ public async Task ShouldWorkWithConditionals()
172172
]";
173173
await Page.Coverage.StartJSCoverageAsync();
174174
await Page.GoToAsync(TestConstants.ServerUrl + "/jscoverage/involved.html");
175+
// Give the coverage some time.
176+
await Task.Delay(1000);
175177
var coverage = await Page.Coverage.StopJSCoverageAsync();
176178
Assert.AreEqual(
177179
TestUtils.CompressText(involved),

0 commit comments

Comments
 (0)