forked from hardkoded/puppeteer-sharp
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Introduce Page.EmulateVisionDeficiencyAsync and Page.EmulateCPUThrott…
…lingAsync (hardkoded#1839) closes hardkoded#1764
- Loading branch information
Showing
10 changed files
with
178 additions
and
5 deletions.
There are no files selected for viewing
1 change: 0 additions & 1 deletion
1
lib/PuppeteerSharp.Tests/EmulationTests/EmulateMediaFeaturesTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
24 changes: 24 additions & 0 deletions
24
lib/PuppeteerSharp.Tests/EmulationTests/PageEmulateCPUThrottlingTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
using System.Threading.Tasks; | ||
using PuppeteerSharp.Tests.Attributes; | ||
using PuppeteerSharp.Xunit; | ||
using Xunit; | ||
using Xunit.Abstractions; | ||
|
||
namespace PuppeteerSharp.Tests.EmulationTests | ||
{ | ||
[Collection(TestConstants.TestFixtureCollectionName)] | ||
public class PageEmulateCPUThrottlingTests : PuppeteerPageBaseTest | ||
{ | ||
public PageEmulateCPUThrottlingTests(ITestOutputHelper output) : base(output) | ||
{ | ||
} | ||
|
||
[PuppeteerTest("emulation.spec.ts", "Page.emulateCPUThrottling", "should change the CPU throttling rate successfully")] | ||
[SkipBrowserFact(skipFirefox: true)] | ||
public async Task ShouldChangeTheCPUThrottlingRateSuccessfully() | ||
{ | ||
await Page.EmulateCPUThrottlingAsync(100); | ||
await Page.EmulateCPUThrottlingAsync(); | ||
} | ||
} | ||
} |
7 changes: 3 additions & 4 deletions
7
...mulationTests/EmulateNetworkConditions.cs → ...ests/PageEmulateNetworkConditionsTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
52 changes: 52 additions & 0 deletions
52
lib/PuppeteerSharp.Tests/EmulationTests/PageEmulateVisionDeficiencyTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
using System.Threading.Tasks; | ||
using PuppeteerSharp.Tests.Attributes; | ||
using PuppeteerSharp.Xunit; | ||
using Xunit; | ||
using Xunit.Abstractions; | ||
|
||
namespace PuppeteerSharp.Tests.EmulationTests | ||
{ | ||
[Collection(TestConstants.TestFixtureCollectionName)] | ||
public class PageEmulateVisionDeficiencyTests : PuppeteerPageBaseTest | ||
{ | ||
public PageEmulateVisionDeficiencyTests(ITestOutputHelper output) : base(output) | ||
{ | ||
} | ||
|
||
[PuppeteerTest("emulation.spec.ts", "Page.emulateVisionDeficiency", "should work")] | ||
[SkipBrowserFact(skipFirefox: true)] | ||
public async Task ShouldWork() | ||
{ | ||
await Page.SetViewportAsync(new ViewPortOptions { Width = 500, Height = 500 }); | ||
await Page.GoToAsync(TestConstants.ServerUrl + "/grid.html"); | ||
|
||
await Page.EmulateVisionDeficiencyAsync(VisionDeficiency.None); | ||
var screenshot = await Page.ScreenshotDataAsync(); | ||
Assert.True(ScreenshotHelper.PixelMatch("screenshot-sanity.png", screenshot)); | ||
|
||
await Page.EmulateVisionDeficiencyAsync(VisionDeficiency.Achromatopsia); | ||
screenshot = await Page.ScreenshotDataAsync(); | ||
Assert.True(ScreenshotHelper.PixelMatch("vision-deficiency-achromatopsia.png", screenshot)); | ||
|
||
await Page.EmulateVisionDeficiencyAsync(VisionDeficiency.BlurredVision); | ||
screenshot = await Page.ScreenshotDataAsync(); | ||
Assert.True(ScreenshotHelper.PixelMatch("vision-deficiency-blurredVision.png", screenshot)); | ||
|
||
await Page.EmulateVisionDeficiencyAsync(VisionDeficiency.Deuteranopia); | ||
screenshot = await Page.ScreenshotDataAsync(); | ||
Assert.True(ScreenshotHelper.PixelMatch("vision-deficiency-deuteranopia.png", screenshot)); | ||
|
||
await Page.EmulateVisionDeficiencyAsync(VisionDeficiency.Protanopia); | ||
screenshot = await Page.ScreenshotDataAsync(); | ||
Assert.True(ScreenshotHelper.PixelMatch("vision-deficiency-protanopia.png", screenshot)); | ||
|
||
await Page.EmulateVisionDeficiencyAsync(VisionDeficiency.Tritanopia); | ||
screenshot = await Page.ScreenshotDataAsync(); | ||
Assert.True(ScreenshotHelper.PixelMatch("vision-deficiency-tritanopia.png", screenshot)); | ||
|
||
await Page.EmulateVisionDeficiencyAsync(VisionDeficiency.None); | ||
screenshot = await Page.ScreenshotDataAsync(); | ||
Assert.True(ScreenshotHelper.PixelMatch("screenshot-sanity.png", screenshot)); | ||
} | ||
} | ||
} |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
7 changes: 7 additions & 0 deletions
7
lib/PuppeteerSharp/Messaging/EmulationSetCPUThrottlingRateRequest.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
namespace PuppeteerSharp.Messaging | ||
{ | ||
internal class EmulationSetCPUThrottlingRateRequest | ||
{ | ||
public decimal Rate{ get; set; } | ||
} | ||
} |
7 changes: 7 additions & 0 deletions
7
lib/PuppeteerSharp/Messaging/EmulationSetEmulatedVisionDeficiencyRequest.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
namespace PuppeteerSharp.Messaging | ||
{ | ||
internal class EmulationSetEmulatedVisionDeficiencyRequest | ||
{ | ||
public VisionDeficiency Type { get; set; } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
using System.Runtime.Serialization; | ||
using Newtonsoft.Json; | ||
using Newtonsoft.Json.Converters; | ||
|
||
namespace PuppeteerSharp | ||
{ | ||
/// <summary> | ||
/// Types of vision deficiency to emulate using <see cref="Page.EmulateVisionDeficiencyAsync(VisionDeficiency)"/> | ||
/// </summary> | ||
[JsonConverter(typeof(StringEnumConverter))] | ||
public enum VisionDeficiency | ||
{ | ||
/// <summary> | ||
/// None | ||
/// </summary> | ||
[EnumMember(Value = "none")] | ||
None, | ||
|
||
/// <summary> | ||
/// Achromatopsia | ||
/// </summary> | ||
[EnumMember(Value = "achromatopsia")] | ||
Achromatopsia, | ||
|
||
/// <summary> | ||
/// BlurredVision | ||
/// </summary> | ||
[EnumMember(Value = "blurredVision")] | ||
BlurredVision, | ||
|
||
/// <summary> | ||
/// Deuteranopia | ||
/// </summary> | ||
[EnumMember(Value = "deuteranopia")] | ||
Deuteranopia, | ||
|
||
/// <summary> | ||
/// Protanopia | ||
/// </summary> | ||
[EnumMember(Value = "protanopia")] | ||
Protanopia, | ||
|
||
/// <summary> | ||
/// Tritanopia | ||
/// </summary> | ||
[EnumMember(Value = "tritanopia")] | ||
Tritanopia, | ||
} | ||
} |