How to use ShouldFire method of PuppeteerSharp.Tests.DialogTests.DialogTests class

Best Puppeteer-sharp code snippet using PuppeteerSharp.Tests.DialogTests.DialogTests.ShouldFire

Run Puppeteer-sharp automation tests on LambdaTest cloud grid

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

DialogTests.cs

Source: DialogTests.cs Github

copy
1using System;
2using System.Linq;
3using System.Collections.Generic;
4using System.Threading.Tasks;
5using Xunit;
6using Xunit.Abstractions;
7using PuppeteerSharp.Tests.Attributes;
8using PuppeteerSharp.Xunit;
9
10namespace PuppeteerSharp.Tests.DialogTests
11{
12    [Collection(TestConstants.TestFixtureCollectionName)]
13    public class DialogTests : PuppeteerPageBaseTest
14    {
15        public DialogTests(ITestOutputHelper output) : base(output)
16        {
17        }
18
19        [PuppeteerTest("dialog.spec.ts", "Page.Events.Dialog", "should fire")]
20        [PuppeteerFact]
21        public async Task ShouldFire()
22        {
23            Page.Dialog += async (_, e) =>
24            {
25                Assert.Equal(DialogType.Alert, e.Dialog.DialogType);
26                Assert.Equal(string.Empty, e.Dialog.DefaultValue);
27                Assert.Equal("yo", e.Dialog.Message);
28
29                await e.Dialog.Accept();
30            };
31
32            await Page.EvaluateExpressionAsync("alert('yo');");
33        }
34
35        [PuppeteerTest("dialog.spec.ts", "Page.Events.Dialog", "should allow accepting prompts")]
36        [SkipBrowserFact(skipFirefox: true)]
37        public async Task ShouldAllowAcceptingPrompts()
38        {
39            Page.Dialog += async (_, e) =>
40            {
41                Assert.Equal(DialogType.Prompt, e.Dialog.DialogType);
42                Assert.Equal("yes.", e.Dialog.DefaultValue);
43                Assert.Equal("question?", e.Dialog.Message);
44
45                await e.Dialog.Accept("answer!");
46            };
47
48            var result = await Page.EvaluateExpressionAsync<string>("prompt('question?', 'yes.')");
49            Assert.Equal("answer!", result);
50        }
51
52        [PuppeteerTest("dialog.spec.ts", "Page.Events.Dialog", "should dismiss the prompt")]
53        [PuppeteerFact]
54        public async Task ShouldDismissThePrompt()
55        {
56            Page.Dialog += async (_, e) =>
57            {
58                await e.Dialog.Dismiss();
59            };
60
61            var result = await Page.EvaluateExpressionAsync<string>("prompt('question?')");
62            Assert.Null(result);
63        }
64    }
65}
66
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 ShouldFire code on LambdaTest Cloud Grid

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