Skip to content

Commit

Permalink
Introduce Chrome for testing (#2278)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
kblok committed Aug 16, 2023
1 parent 2e21ecd commit b9f325a
Show file tree
Hide file tree
Showing 36 changed files with 1,063 additions and 647 deletions.
2 changes: 2 additions & 0 deletions lib/.editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,8 @@ dotnet_diagnostic.CA1001.severity = error
dotnet_diagnostic.CA1304.severity = error
# CA1305: String.Format with culture
dotnet_diagnostic.CA1305.severity = error
# CA1304: CA1308: Normalize strings to uppercase
dotnet_diagnostic.CA1308.severity = none
# CA1721: The property name 'DefaultArgs' is confusing given the existence of method 'GetDefaultArgs'. Rename or remove one of these members.
dotnet_diagnostic.CA1721.severity = error
# CA1724: The type name Extensions conflicts in whole or in part with the namespace name 'Microsoft.Extensions'. Change either name to eliminate the conflict.
Expand Down
97 changes: 97 additions & 0 deletions lib/PuppeteerSharp.Tests/Browsers/Chrome/ChromeDataTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
using System;
using System.IO;
using NUnit.Framework;
using PuppeteerSharp.BrowserData;
using PuppeteerSharp.Nunit;
using PuppeteerSharp.Tests.Attributes;

namespace PuppeteerSharp.Tests.Browsers.Chrome
{
public class ChromeDataTests
{
[PuppeteerTest("chrome-data.spec.ts", "Chrome", "should resolve download URLs")]
public void ShouldResolveDownloadUrls()
{
Assert.AreEqual(
"https://edgedl.me.gvt1.com/edgedl/chrome/chrome-for-testing/113.0.5672.0/linux64/chrome-linux64.zip",
BrowserData.Chrome.ResolveDownloadUrl(Platform.Linux, "113.0.5672.0", null));
Assert.AreEqual(
"https://edgedl.me.gvt1.com/edgedl/chrome/chrome-for-testing/113.0.5672.0/mac-x64/chrome-mac-x64.zip",
BrowserData.Chrome.ResolveDownloadUrl(Platform.MacOS, "113.0.5672.0", null));
Assert.AreEqual(
"https://edgedl.me.gvt1.com/edgedl/chrome/chrome-for-testing/113.0.5672.0/mac-arm64/chrome-mac-arm64.zip",
BrowserData.Chrome.ResolveDownloadUrl(Platform.MacOSArm64, "113.0.5672.0", null));
Assert.AreEqual(
"https://edgedl.me.gvt1.com/edgedl/chrome/chrome-for-testing/113.0.5672.0/win32/chrome-win32.zip",
BrowserData.Chrome.ResolveDownloadUrl(Platform.Win32, "113.0.5672.0", null));
Assert.AreEqual(
"https://edgedl.me.gvt1.com/edgedl/chrome/chrome-for-testing/113.0.5672.0/win64/chrome-win64.zip",
BrowserData.Chrome.ResolveDownloadUrl(Platform.Win64, "113.0.5672.0", null));
}

[PuppeteerTest("chrome-data.spec.ts", "Chrome", "should resolve executable paths")]
public void ShouldResolveExecutablePath()
{
Assert.AreEqual(
Path.Combine("chrome-linux64", "chrome"),
BrowserData.Chrome.RelativeExecutablePath(Platform.Linux, "12372323"));

Assert.AreEqual(
Path.Combine(
"chrome-mac-x64",
"Google Chrome for Testing.app",
"Contents",
"MacOS",
"Google Chrome for Testing"
),
BrowserData.Chrome.RelativeExecutablePath(Platform.MacOS, "12372323"));

Assert.AreEqual(
Path.Combine(
"chrome-mac-arm64",
"Google Chrome for Testing.app",
"Contents",
"MacOS",
"Google Chrome for Testing"
),
BrowserData.Chrome.RelativeExecutablePath(Platform.MacOSArm64, "12372323"));

Assert.AreEqual(
Path.Combine("chrome-win32", "chrome.exe"),
BrowserData.Chrome.RelativeExecutablePath(Platform.Win32, "12372323"));

Assert.AreEqual(
BrowserData.Chrome.RelativeExecutablePath(Platform.Win64, "12372323"),
Path.Combine("chrome-win64", "chrome.exe"));
}

[PuppeteerTest("chrome-data.spec.ts", "Chrome", "should resolve system executable path")]
[Skip(SkipAttribute.Targets.Linux, SkipAttribute.Targets.OSX)]
public void ShouldResolveSystemExecutablePathWindows()
{
Assert.AreEqual(
"C:\\Program Files\\Google\\Chrome Dev\\Application\\chrome.exe",
BrowserData.Chrome.ResolveSystemExecutablePath(
Platform.Win32,
ChromeReleaseChannel.Dev));
}

[PuppeteerTest("chrome-data.spec.ts", "Chrome", "should resolve system executable path")]
public void ShouldResolveSystemExecutablePath()
{
Assert.AreEqual(
"/Applications/Google Chrome Beta.app/Contents/MacOS/Google Chrome Beta",
BrowserData.Chrome.ResolveSystemExecutablePath(
Platform.MacOS,
ChromeReleaseChannel.Beta));

var ex = Assert.Throws<PuppeteerException>(() => {
BrowserData.Chrome.ResolveSystemExecutablePath(
Platform.Linux,
ChromeReleaseChannel.Canary);
});

Assert.AreEqual("Canary is not supported", ex.Message);
}
}
}
43 changes: 43 additions & 0 deletions lib/PuppeteerSharp.Tests/Browsers/Chrome/CliTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
using System;
using System.IO;
using System.Threading.Tasks;
using NUnit.Framework;
using PuppeteerSharp.BrowserData;
using PuppeteerSharp.Nunit;

namespace PuppeteerSharp.Tests.Browsers.Chrome
{
/// <summary>
/// Puppeteer sharp doesn't have a CLI per se. But it matches the test we have upstream.
/// </summary>
public class CliTests
{
private readonly string _cacheDir = Path.Combine(Path.GetTempPath(), Path.GetRandomFileName());

[SetUp]
public void CreateDir()
=> new DirectoryInfo(_cacheDir).Create();

[TearDown]
public void DeleteDir()
=> new Cache(_cacheDir).Clear();

[PuppeteerTest("CLI.spec.ts", "Chrome CLI", "should download Chrome binaries")]
public async Task ShouldDownloadChromeBinaries()
{
using var fetcher = new BrowserFetcher(SupportedBrowser.Chrome)
{
CacheDir = _cacheDir,
Platform = Platform.Linux
};
await fetcher.DownloadAsync(BrowserData.Chrome.DefaultBuildId);

Assert.True(new FileInfo(Path.Combine(
_cacheDir,
"Chrome",
$"Linux-{BrowserData.Chrome.DefaultBuildId}",
"chrome-linux64",
"chrome")).Exists);
}
}
}
66 changes: 66 additions & 0 deletions lib/PuppeteerSharp.Tests/Browsers/Chromium/ChromiumDataTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
using System;
using System.IO;
using NUnit.Framework;
using PuppeteerSharp.Nunit;

namespace PuppeteerSharp.Tests.Browsers.Chromium
{
public class ChromiumDataTests
{
[PuppeteerTest("chromium-data.spec.ts", "Chromium", "should resolve download URLs")]
public void ShouldResolveDownloadUrls()
{
Assert.AreEqual(
"https://storage.googleapis.com/chromium-browser-snapshots/Linux_x64/1083080/chrome-linux.zip",
BrowserData.Chromium.ResolveDownloadUrl(Platform.Linux, "1083080", null));
Assert.AreEqual(
"https://storage.googleapis.com/chromium-browser-snapshots/Mac/1083080/chrome-mac.zip",
BrowserData.Chromium.ResolveDownloadUrl(Platform.MacOS, "1083080", null));
Assert.AreEqual(
"https://storage.googleapis.com/chromium-browser-snapshots/Mac_Arm/1083080/chrome-mac.zip",
BrowserData.Chromium.ResolveDownloadUrl(Platform.MacOSArm64, "1083080", null));
Assert.AreEqual(
"https://storage.googleapis.com/chromium-browser-snapshots/Win/1083080/chrome-win.zip",
BrowserData.Chromium.ResolveDownloadUrl(Platform.Win32, "1083080", null));
Assert.AreEqual(
"https://storage.googleapis.com/chromium-browser-snapshots/Win_x64/1083080/chrome-win.zip",
BrowserData.Chromium.ResolveDownloadUrl(Platform.Win64, "1083080", null));
}

[PuppeteerTest("chromium-data.spec.ts", "Chromium", "should resolve executable paths")]
public void ShouldResolveExecutablePath()
{
Assert.AreEqual(
Path.Combine("chrome-linux", "chrome"),
BrowserData.Chromium.RelativeExecutablePath(Platform.Linux, "12372323"));

Assert.AreEqual(
Path.Combine(
"chrome-mac",
"Chromium.app",
"Contents",
"MacOS",
"Chromium"
),
BrowserData.Chromium.RelativeExecutablePath(Platform.MacOS, "12372323"));

Assert.AreEqual(
Path.Combine(
"chrome-mac",
"Chromium.app",
"Contents",
"MacOS",
"Chromium"
),
BrowserData.Chromium.RelativeExecutablePath(Platform.MacOSArm64, "12372323"));

Assert.AreEqual(
Path.Combine("chrome-win", "chrome.exe"),
BrowserData.Chromium.RelativeExecutablePath(Platform.Win32, "12372323"));

Assert.AreEqual(
BrowserData.Chromium.RelativeExecutablePath(Platform.Win64, "12372323"),
Path.Combine("chrome-win", "chrome.exe"));
}
}
}
43 changes: 43 additions & 0 deletions lib/PuppeteerSharp.Tests/Browsers/Firefox/CliTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
using System;
using System.IO;
using System.Threading.Tasks;
using NUnit.Framework;
using PuppeteerSharp.BrowserData;
using PuppeteerSharp.Nunit;

namespace PuppeteerSharp.Tests.Browsers.Firefox
{
/// <summary>
/// Puppeteer sharp doesn't have a CLI per se. But it matches the test we have upstream.
/// </summary>
public class CliTests
{
private readonly string _cacheDir = Path.Combine(Path.GetTempPath(), Path.GetRandomFileName());

[SetUp]
public void CreateDir()
=> new DirectoryInfo(_cacheDir).Create();

[TearDown]
public void DeleteDir()
=> new Cache(_cacheDir).Clear();

[PuppeteerTest("CLI.spec.ts", "Chrome CLI", "should download Chrome binaries")]
public async Task ShouldDownloadChromeBinaries()
{
using var fetcher = new BrowserFetcher(SupportedBrowser.Chrome)
{
CacheDir = _cacheDir,
Platform = Platform.Linux
};
await fetcher.DownloadAsync(BrowserData.Chrome.DefaultBuildId);

Assert.True(new FileInfo(Path.Combine(
_cacheDir,
"Chrome",
$"Linux-{BrowserData.Chrome.DefaultBuildId}",
"chrome-linux64",
"chrome")).Exists);
}
}
}
66 changes: 66 additions & 0 deletions lib/PuppeteerSharp.Tests/Browsers/Firefox/FirefoxDataTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
using System;
using System.IO;
using NUnit.Framework;
using PuppeteerSharp.BrowserData;
using PuppeteerSharp.Nunit;
using PuppeteerSharp.Tests.Attributes;

namespace PuppeteerSharp.Tests.Browsers.Firefox
{
public class FirefoxDataTests
{
[PuppeteerTest("firefox-data.spec.ts", "Firefox", "should resolve download URLs")]
public void ShouldResolveDownloadUrls()
{
Assert.AreEqual(
"https://archive.mozilla.org/pub/firefox/nightly/latest-mozilla-central/firefox-111.0a1.en-US.linux-x86_64.tar.bz2",
BrowserData.Firefox.ResolveDownloadUrl(Platform.Linux, "111.0a1", null));
Assert.AreEqual(
"https://archive.mozilla.org/pub/firefox/nightly/latest-mozilla-central/firefox-111.0a1.en-US.mac.dmg",
BrowserData.Firefox.ResolveDownloadUrl(Platform.MacOS, "111.0a1", null));
Assert.AreEqual(
"https://archive.mozilla.org/pub/firefox/nightly/latest-mozilla-central/firefox-111.0a1.en-US.mac.dmg",
BrowserData.Firefox.ResolveDownloadUrl(Platform.MacOSArm64, "111.0a1", null));
Assert.AreEqual(
"https://archive.mozilla.org/pub/firefox/nightly/latest-mozilla-central/firefox-111.0a1.en-US.win32.zip",
BrowserData.Firefox.ResolveDownloadUrl(Platform.Win32, "111.0a1", null));
Assert.AreEqual(
"https://archive.mozilla.org/pub/firefox/nightly/latest-mozilla-central/firefox-111.0a1.en-US.win64.zip",
BrowserData.Firefox.ResolveDownloadUrl(Platform.Win64, "111.0a1", null));
}

[PuppeteerTest("firefox-data.spec.ts", "Firefox", "should resolve executable paths")]
public void ShouldResolveExecutablePath()
{
Assert.AreEqual(
Path.Combine("firefox", "firefox"),
BrowserData.Firefox.RelativeExecutablePath(Platform.Linux, "111.0a1"));

Assert.AreEqual(
Path.Combine(
"Firefox Nightly.app",
"Contents",
"MacOS",
"firefox"
),
BrowserData.Firefox.RelativeExecutablePath(Platform.MacOS, "111.0a1"));

Assert.AreEqual(
Path.Combine(
"Firefox Nightly.app",
"Contents",
"MacOS",
"firefox"
),
BrowserData.Firefox.RelativeExecutablePath(Platform.MacOSArm64, "111.0a1"));

Assert.AreEqual(
Path.Combine("firefox", "firefox.exe"),
BrowserData.Firefox.RelativeExecutablePath(Platform.Win32, "111.0a1"));

Assert.AreEqual(
BrowserData.Firefox.RelativeExecutablePath(Platform.Win64, "111.0a1"),
Path.Combine("firefox", "firefox.exe"));
}
}
}
13 changes: 11 additions & 2 deletions lib/PuppeteerSharp.Tests/CoverageTests/CSSCoverageTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,12 @@ public async Task ShouldWorkWithMediaQueries()
new CoverageEntryRange
{
Start = 8,
End = 40
End = 15
},
new CoverageEntryRange
{
Start = 17,
End = 38
}
}, coverage[0].Ranges);
}
Expand All @@ -110,7 +115,11 @@ public async Task ShouldWorkWithComplicatedUsecases()
},
{
""Start"": 306,
""End"": 435
""End"": 323
},
{
""Start"": 327,
""End"": 433
}
],
""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""
Expand Down
2 changes: 2 additions & 0 deletions lib/PuppeteerSharp.Tests/CoverageTests/JSCoverageTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,8 @@ public async Task ShouldWorkWithConditionals()
]";
await Page.Coverage.StartJSCoverageAsync();
await Page.GoToAsync(TestConstants.ServerUrl + "/jscoverage/involved.html");
// Give the coverage some time.
await Task.Delay(1000);
var coverage = await Page.Coverage.StopJSCoverageAsync();
Assert.AreEqual(
TestUtils.CompressText(involved),
Expand Down
Loading

0 comments on commit b9f325a

Please sign in to comment.