How to use ShouldWorkWithEmojis method of PuppeteerSharp.Tests.PageTests.SetContentTests class

Best Puppeteer-sharp code snippet using PuppeteerSharp.Tests.PageTests.SetContentTests.ShouldWorkWithEmojis

Run Puppeteer-sharp automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

SetContentTests.cs

Source: SetContentTests.cs Github

copy
1using System;
2using System.Threading.Tasks;
3using Xunit;
4using Xunit.Abstractions;
5
6namespace PuppeteerSharp.Tests.PageTests
7{
8    [Collection("PuppeteerLoaderFixture collection")]
9    public class SetContentTests : PuppeteerPageBaseTest
10    {
11        const string ExpectedOutput = "<html><head></head><body><div>hello</div></body></html>";
12
13        public SetContentTests(ITestOutputHelper output) : base(output)
14        {
15        }
16
17        [Fact]
18        public async Task ShouldWork()
19        {
20            await Page.SetContentAsync("<div>hello</div>");
21            var result = await Page.GetContentAsync();
22
23            Assert.Equal(ExpectedOutput, result);
24        }
25
26        [Fact]
27        public async Task ShouldWorkWithDoctype()
28        {
29            const string doctype = "<!DOCTYPE html>";
30
31            await Page.SetContentAsync($"{doctype}<div>hello</div>");
32            var result = await Page.GetContentAsync();
33
34            Assert.Equal($"{doctype}{ExpectedOutput}", result);
35        }
36
37        [Fact]
38        public async Task ShouldWorkWithHtml4Doctype()
39        {
40            const string doctype = "<!DOCTYPE html PUBLIC \" -//W3C//DTD HTML 4.01//EN\" " +
41                "\"http://www.w3.org/TR/html4/strict.dtd\">";
42
43            await Page.SetContentAsync($"{doctype}<div>hello</div>");
44            var result = await Page.GetContentAsync();
45
46            Assert.Equal($"{doctype}{ExpectedOutput}", result);
47        }
48
49        [Fact]
50        public async Task ShouldRespectTimeout()
51        {
52            const string imgPath = "/img.png";
53            Server.SetRoute(imgPath, context => Task.Delay(-1));
54
55            await Page.GoToAsync(TestConstants.EmptyPage);
56            var exception = await Assert.ThrowsAnyAsync<TimeoutException>(async () =>
57                await Page.SetContentAsync($"<img src='{TestConstants.ServerUrl + imgPath}'></img>", new NavigationOptions
58                {
59                    Timeout = 1
60                }));
61
62            Assert.Contains("Timeout Exceeded: 1ms", exception.Message);
63        }
64
65        [Fact]
66        public async Task ShouldRespectDefaultTimeout()
67        {
68            const string imgPath = "/img.png";
69            Server.SetRoute(imgPath, context => Task.Delay(-1));
70
71            await Page.GoToAsync(TestConstants.EmptyPage);
72            Page.DefaultTimeout = 1;
73            var exception = await Assert.ThrowsAnyAsync<TimeoutException>(async () =>
74                await Page.SetContentAsync($"<img src='{TestConstants.ServerUrl + imgPath}'></img>"));
75
76            Assert.Contains("Timeout Exceeded: 1ms", exception.Message);
77        }
78
79        [Fact]
80        public async Task ShouldAwaitResourcesToLoad()
81        {
82            var imgPath = "/img.png";
83            var imgResponse = new TaskCompletionSource<bool>();
84            Server.SetRoute(imgPath, context => imgResponse.Task);
85            var loaded = false;
86            var waitTask = Server.WaitForRequest(imgPath);
87            var contentTask = Page.SetContentAsync($"<img src=\"{TestConstants.ServerUrl + imgPath}\"></img>")
88                .ContinueWith(_ => loaded = true);
89            await waitTask;
90            Assert.False(loaded);
91            imgResponse.SetResult(true);
92            await contentTask;
93        }
94
95        [Fact]
96        public async Task ShouldWorkFastEnough()
97        {
98            for (var i = 0; i < 20; ++i)
99            {
100                await Page.SetContentAsync("<div>yo</div>");
101            }
102        }
103
104        [Fact]
105        public async Task ShouldWorkWithTrickyContent()
106        {
107            await Page.SetContentAsync("<div>hello world</div>\x7F");
108            Assert.Equal("hello world", await Page.QuerySelectorAsync("div").EvaluateFunctionAsync<string>("div => div.textContent"));
109        }
110
111        [Fact]
112        public async Task ShouldWorkWithAccents()
113        {
114            await Page.SetContentAsync("<div>aberración</div>");
115            Assert.Equal("aberración", await Page.QuerySelectorAsync("div").EvaluateFunctionAsync<string>("div => div.textContent"));
116        }
117
118        [Fact]
119        public async Task ShouldWorkWithEmojis()
120        {
121            await Page.SetContentAsync("<div>🐥</div>");
122            Assert.Equal("🐥", await Page.QuerySelectorAsync("div").EvaluateFunctionAsync<string>("div => div.textContent"));
123        }
124
125        [Fact]
126        public async Task ShouldWorkWithNewline()
127        {
128            await Page.SetContentAsync("<div>\n</div>");
129            Assert.Equal("\n", await Page.QuerySelectorAsync("div").EvaluateFunctionAsync<string>("div => div.textContent"));
130        }
131    }
132}
133
Full Screen

Accelerate Your Automation Test Cycles With LambdaTest

Leverage LambdaTest’s cloud-based platform to execute your automation tests in parallel and trim down your test execution time significantly. Your first 100 automation testing minutes are on us.

Try LambdaTest

Trigger ShouldWorkWithEmojis code on LambdaTest Cloud Grid

Execute automation tests with ShouldWorkWithEmojis on a cloud-based Grid of 3000+ real browsers and operating systems for both web and mobile applications.

Test now for Free
LambdaTestX

We use cookies to give you the best experience. Cookies help to provide a more personalized experience and relevant advertising for you, and web analytics for us. Learn More in our Cookies policy, Privacy & Terms of service

Allow Cookie
Sarah

I hope you find the best code examples for your project.

If you want to accelerate automated browser testing, try LambdaTest. Your first 100 automation testing minutes are FREE.

Sarah Elson (Product & Growth Lead)