How to use PuppeteerTest method of PuppeteerSharp.Tests.ChromiumSpecificTests.BrowserUrlOptionTests class

Best Puppeteer-sharp code snippet using PuppeteerSharp.Tests.ChromiumSpecificTests.BrowserUrlOptionTests.PuppeteerTest

Run Puppeteer-sharp automation tests on LambdaTest cloud grid

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

BrowserUrlOptionTests.cs

Source: BrowserUrlOptionTests.cs Github

copy
1using System.Threading.Tasks;
2using PuppeteerSharp.Tests.Attributes;
3using PuppeteerSharp.Xunit;
4using Xunit;
5using Xunit.Abstractions;
6
7namespace PuppeteerSharp.Tests.ChromiumSpecificTests
8{
9    [Collection(TestConstants.TestFixtureCollectionName)]
10    public class BrowserUrlOptionTests : PuppeteerPageBaseTest
11    {
12        public BrowserUrlOptionTests(ITestOutputHelper output) : base(output)
13        {
14        }
15
16        [PuppeteerTest("chromiumonly.spec.ts", "Puppeteer.launch |browserURL| option", "should be able to connect using browserUrl, with and without trailing slash")]
17        [SkipBrowserFact(skipFirefox: true)]
18        public async Task ShouldBeAbleToConnectUsingBrowserURLWithAndWithoutTrailingSlash()
19        {
20            var options = TestConstants.DefaultBrowserOptions();
21            options.Args = new string[] { "--remote-debugging-port=21222" };
22            var originalBrowser = await Puppeteer.LaunchAsync(options);
23            var browserURL = "http://127.0.0.1:21222";
24
25            var browser1 = await Puppeteer.ConnectAsync(new ConnectOptions { BrowserURL = browserURL });
26            var page1 = await browser1.NewPageAsync();
27            Assert.Equal(56, await page1.EvaluateExpressionAsync<int>("7 * 8"));
28            browser1.Disconnect();
29
30            var browser2 = await Puppeteer.ConnectAsync(new ConnectOptions { BrowserURL = browserURL + "/" });
31            var page2 = await browser2.NewPageAsync();
32            Assert.Equal(56, await page2.EvaluateExpressionAsync<int>("7 * 8"));
33            browser2.Disconnect();
34            await originalBrowser.CloseAsync();
35        }
36
37        [PuppeteerTest("chromiumonly.spec.ts", "Puppeteer.launch |browserURL| option", "should throw when using both browserWSEndpoint and browserURL")]
38        [SkipBrowserFact(skipFirefox: true)]
39        public async Task ShouldThrowWhenUsingBothBrowserWSEndpointAndBrowserURL()
40        {
41            var options = TestConstants.DefaultBrowserOptions();
42            options.Args = new string[] { "--remote-debugging-port=21222" };
43            var originalBrowser = await Puppeteer.LaunchAsync(options);
44            var browserURL = "http://127.0.0.1:21222";
45
46            await Assert.ThrowsAsync<PuppeteerException>(() => Puppeteer.ConnectAsync(new ConnectOptions
47            {
48                BrowserURL = browserURL,
49                BrowserWSEndpoint = originalBrowser.WebSocketEndpoint
50            }));
51
52            await originalBrowser.CloseAsync();
53        }
54
55        [PuppeteerTest("chromiumonly.spec.ts", "Puppeteer.launch |browserURL| option", "should throw when trying to connect to non-existing browser")]
56        [SkipBrowserFact(skipFirefox: true)]
57        public async Task ShouldThrowWhenTryingToConnectToNonExistingBrowser()
58        {
59            var options = TestConstants.DefaultBrowserOptions();
60            options.Args = new string[] { "--remote-debugging-port=21222" };
61            var originalBrowser = await Puppeteer.LaunchAsync(options);
62            var browserURL = "http://127.0.0.1:2122";
63
64            await Assert.ThrowsAsync<ProcessException>(() => Puppeteer.ConnectAsync(new ConnectOptions
65            {
66                BrowserURL = browserURL
67            }));
68
69            await originalBrowser.CloseAsync();
70        }
71    }
72}
73
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 PuppeteerTest code on LambdaTest Cloud Grid

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