How to use ShouldAcceptObjectHandleAsAnArgument method of PuppeteerSharp.Tests.JSHandleTests.PageEvaluateHandle class

Best Puppeteer-sharp code snippet using PuppeteerSharp.Tests.JSHandleTests.PageEvaluateHandle.ShouldAcceptObjectHandleAsAnArgument

Run Puppeteer-sharp automation tests on LambdaTest cloud grid

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

PageEvaluateHandle.cs

Source: PageEvaluateHandle.cs Github

copy
1using System.Threading.Tasks;
2using PuppeteerSharp.Tests.Attributes;
3using PuppeteerSharp.Xunit;
4using Xunit;
5using Xunit.Abstractions;
6
7namespace PuppeteerSharp.Tests.JSHandleTests
8{
9    [Collection(TestConstants.TestFixtureCollectionName)]
10    public class PageEvaluateHandle : PuppeteerPageBaseTest
11    {
12        public PageEvaluateHandle(ITestOutputHelper output) : base(output)
13        {
14        }
15
16        [PuppeteerTest("jshandle.spec.ts", "Page.evaluateHandle", "should work")]
17        [PuppeteerFact]
18        public async Task ShouldWork()
19            => Assert.NotNull(await Page.EvaluateFunctionHandleAsync("() => window"));
20
21        [PuppeteerTest("jshandle.spec.ts", "Page.evaluateHandle", "should accept object handle as an argument")]
22        [PuppeteerFact]
23        public async Task ShouldAcceptObjectHandleAsAnArgument()
24        {
25            var navigatorHandle = await Page.EvaluateFunctionHandleAsync("() => navigator");
26            var text = await Page.EvaluateFunctionAsync<string>(
27                "(e) => e.userAgent",
28                navigatorHandle);
29            Assert.Contains("Mozilla", text);
30        }
31
32        [PuppeteerTest("jshandle.spec.ts", "Page.evaluateHandle", "should accept object handle to primitive types")]
33        [PuppeteerFact]
34        public async Task ShouldAcceptObjectHandleToPrimitiveTypes()
35        {
36            var aHandle = await Page.EvaluateFunctionHandleAsync("() => 5");
37            var isFive = await Page.EvaluateFunctionAsync<bool>(
38                "(e) => Object.is(e, 5)",
39                aHandle);
40            Assert.True(isFive);
41        }
42
43        [PuppeteerTest("jshandle.spec.ts", "Page.evaluateHandle", "should warn on nested object handles")]
44        [PuppeteerFact]
45        public async Task ShouldWarnOnNestedObjectHandles()
46        {
47            var aHandle = await Page.EvaluateFunctionHandleAsync("() => document.body");
48            var exception = await Assert.ThrowsAsync<EvaluationFailedException>(() =>
49                Page.EvaluateFunctionHandleAsync("(opts) => opts.elem.querySelector('p')", new { aHandle }));
50            Assert.Contains("Are you passing a nested JSHandle?", exception.Message);
51        }
52
53        [PuppeteerTest("jshandle.spec.ts", "Page.evaluateHandle", "should accept object handle to unserializable value")]
54        [PuppeteerFact]
55        public async Task ShouldAcceptObjectHandleToUnserializableValue()
56        {
57            var aHandle = await Page.EvaluateFunctionHandleAsync("() => Infinity");
58            Assert.True(await Page.EvaluateFunctionAsync<bool>(
59                "(e) => Object.is(e, Infinity)",
60                aHandle));
61        }
62
63        [PuppeteerTest("jshandle.spec.ts", "Page.evaluateHandle", "should use the same JS wrappers")]
64        [PuppeteerFact]
65        public async Task ShouldUseTheSameJSWrappers()
66        {
67            var aHandle = await Page.EvaluateFunctionHandleAsync(@"() => {
68                globalThis.FOO = 123;
69                return window;
70            }");
71            Assert.Equal(123, await Page.EvaluateFunctionAsync<int>(
72                "(e) => e.FOO",
73                aHandle));
74        }
75    }
76}
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 ShouldAcceptObjectHandleAsAnArgument code on LambdaTest Cloud Grid

Execute automation tests with ShouldAcceptObjectHandleAsAnArgument 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)