Best Puppeteer-sharp code snippet using PuppeteerSharp.Launcher.ConnectAsync
Browser.cs
Source:Browser.cs
...28 /// <![CDATA[29 /// var browser = await Puppeteer.LaunchAsync(new LaunchOptions());30 /// var browserWSEndpoint = browser.WebSocketEndpoint;31 /// browser.Disconnect();32 /// var browser2 = await Puppeteer.ConnectAsync(new ConnectOptions { BrowserWSEndpoint = browserWSEndpoint });33 /// await browser2.CloseAsync();34 /// ]]>35 /// </code>36 /// </example>37 public class Browser : IDisposable, IAsyncDisposable38 {39 /// <summary>40 /// Time in milliseconds for process to exit gracefully.41 /// </summary>42 private const int CloseTimeout = 5000;43 private readonly ConcurrentDictionary<string, BrowserContext> _contexts;44 private readonly ILogger<Browser> _logger;45 private readonly Func<TargetInfo, bool> _targetFilterCallback;46 private Task _closeTask;47 internal Browser(48 Connection connection,49 string[] contextIds,50 bool ignoreHTTPSErrors,51 ViewPortOptions defaultViewport,52 LauncherBase launcher,53 Func<TargetInfo, bool> targetFilter)54 {55 Connection = connection;56 IgnoreHTTPSErrors = ignoreHTTPSErrors;57 DefaultViewport = defaultViewport;58 TargetsMap = new ConcurrentDictionary<string, Target>();59 ScreenshotTaskQueue = new TaskQueue();60 DefaultContext = new BrowserContext(Connection, this, null);61 _contexts = new ConcurrentDictionary<string, BrowserContext>(contextIds.ToDictionary(62 contextId => contextId,63 contextId => new BrowserContext(Connection, this, contextId)));64 Connection.Disconnected += Connection_Disconnected;65 Connection.MessageReceived += Connect_MessageReceived;66 Launcher = launcher;67 _logger = Connection.LoggerFactory.CreateLogger<Browser>();68 _targetFilterCallback = targetFilter ?? ((TargetInfo _) => true);69 }70 /// <summary>71 /// Raised when the <see cref="Browser"/> gets closed.72 /// </summary>73 public event EventHandler Closed;74 /// <summary>75 /// Raised when puppeteer gets disconnected from the Chromium instance. This might happen because one of the following76 /// - Chromium is closed or crashed77 /// - <see cref="Disconnect"/> method was called78 /// </summary>79 public event EventHandler Disconnected;80 /// <summary>81 /// Raised when the url of a target changes82 /// </summary>83 public event EventHandler<TargetChangedArgs> TargetChanged;84 /// <summary>85 /// Raised when a target is created, for example when a new page is opened by <c>window.open</c> <see href="https://developer.mozilla.org/en-US/docs/Web/API/Window/open"/> or <see cref="NewPageAsync"/>.86 /// </summary>87 public event EventHandler<TargetChangedArgs> TargetCreated;88 /// <summary>89 /// Raised when a target is destroyed, for example when a page is closed90 /// </summary>91 public event EventHandler<TargetChangedArgs> TargetDestroyed;92 /// <summary>93 /// Gets the Browser websocket url94 /// </summary>95 /// <remarks>96 /// Browser websocket endpoint which can be used as an argument to <see cref="Puppeteer.ConnectAsync(ConnectOptions, ILoggerFactory)"/>.97 /// The format is <c>ws://${host}:${port}/devtools/browser/[id]</c>98 /// You can find the <c>webSocketDebuggerUrl</c> from <c>http://${host}:${port}/json/version</c>.99 /// Learn more about the devtools protocol <see href="https://chromedevtools.github.io/devtools-protocol"/>100 /// and the browser endpoint <see href="https://chromedevtools.github.io/devtools-protocol/#how-do-i-access-the-browser-target"/>101 /// </remarks>102 public string WebSocketEndpoint => Connection.Url;103 /// <summary>104 /// Gets the spawned browser process. Returns <c>null</c> if the browser instance was created with <see cref="Puppeteer.ConnectAsync(ConnectOptions, ILoggerFactory)"/> method.105 /// </summary>106 public Process Process => Launcher?.Process;107 /// <summary>108 /// Gets or Sets whether to ignore HTTPS errors during navigation109 /// </summary>110 public bool IgnoreHTTPSErrors { get; set; }111 /// <summary>112 /// Gets a value indicating if the browser is closed113 /// </summary>114 public bool IsClosed115 {116 get117 {118 if (Launcher == null)...
PuppeteerConnectTests.cs
Source:PuppeteerConnectTests.cs
...23 var options = new ConnectOptions()24 {25 BrowserWSEndpoint = Browser.WebSocketEndpoint26 };27 var browser = await Puppeteer.ConnectAsync(options, TestConstants.LoggerFactory);28 await using (var page = await browser.NewPageAsync())29 {30 var response = await page.EvaluateExpressionAsync<int>("7 * 8");31 Assert.Equal(56, response);32 }33 await using (var originalPage = await Browser.NewPageAsync())34 {35 var response = await originalPage.EvaluateExpressionAsync<int>("7 * 6");36 Assert.Equal(42, response);37 }38 }39 [PuppeteerTest("launcher.spec.ts", "Puppeteer.connect", "should be able to close remote browser")]40 [PuppeteerFact]41 public async Task ShouldBeAbleToCloseRemoteBrowser()42 {43 var originalBrowser = await Puppeteer.LaunchAsync(TestConstants.DefaultBrowserOptions());44 var remoteBrowser = await Puppeteer.ConnectAsync(new ConnectOptions45 {46 BrowserWSEndpoint = originalBrowser.WebSocketEndpoint47 });48 var tcsDisconnected = new TaskCompletionSource<bool>();49 originalBrowser.Disconnected += (_, _) => tcsDisconnected.TrySetResult(true);50 await Task.WhenAll(51 tcsDisconnected.Task,52 remoteBrowser.CloseAsync());53 }54 [PuppeteerTest("launcher.spec.ts", "Puppeteer.connect", "should support ignoreHTTPSErrors option")]55 [PuppeteerFact]56 public async Task ShouldSupportIgnoreHTTPSErrorsOption()57 {58 await using (var originalBrowser = await Puppeteer.LaunchAsync(TestConstants.DefaultBrowserOptions()))59 await using (var browser = await Puppeteer.ConnectAsync(new ConnectOptions60 {61 BrowserWSEndpoint = originalBrowser.WebSocketEndpoint,62 IgnoreHTTPSErrors = true63 }))64 await using (var page = await browser.NewPageAsync())65 {66 var requestTask = HttpsServer.WaitForRequest(67 "/empty.html",68 request => request?.HttpContext?.Features?.Get<ITlsHandshakeFeature>()?.Protocol);69 var responseTask = page.GoToAsync(TestConstants.HttpsPrefix + "/empty.html");70 await Task.WhenAll(71 requestTask,72 responseTask).WithTimeout(Puppeteer.DefaultTimeout);73 var response = responseTask.Result;74 Assert.True(response.Ok);75 Assert.NotNull(response.SecurityDetails);76 Assert.Equal(77 TestUtils.CurateProtocol(requestTask.Result.ToString()),78 TestUtils.CurateProtocol(response.SecurityDetails.Protocol));79 }80 }81 [PuppeteerTest("launcher.spec.ts", "Puppeteer.connect", "should support targetFilter option")]82 [SkipBrowserFact(skipFirefox: true)]83 public async Task ShouldSupportTargetFilter()84 {85 await using (var originalBrowser = await Puppeteer.LaunchAsync(TestConstants.DefaultBrowserOptions()))86 {87 var page1 = await originalBrowser.NewPageAsync();88 await page1.GoToAsync(TestConstants.EmptyPage);89 var page2 = await originalBrowser.NewPageAsync();90 await page2.GoToAsync(TestConstants.EmptyPage + "?should-be-ignored");91 var browser = await Puppeteer.ConnectAsync(new ConnectOptions {92 BrowserWSEndpoint = originalBrowser.WebSocketEndpoint,93 TargetFilter = (TargetInfo targetInfo) => !targetInfo.Url.Contains("should-be-ignored"),94 });95 var pages = await browser.PagesAsync();96 await page2.CloseAsync();97 await page1.CloseAsync();98 await browser.CloseAsync();99 Assert.Equal(100 new string[]101 {102 "about:blank",103 TestConstants.EmptyPage104 },105 pages.Select((Page p) => p.Url).OrderBy(t => t));106 }107 }108 [PuppeteerFact]109 public async Task ShouldBeAbleToSetBrowserPropertiesUsingConnectOptions()110 {111 var initActionExecuted = false;112 var options = new ConnectOptions113 {114 BrowserWSEndpoint = Browser.WebSocketEndpoint,115 InitAction = brw =>116 {117 initActionExecuted = true;118 }119 };120 var browser = await Puppeteer.ConnectAsync(options, TestConstants.LoggerFactory);121 Assert.True(initActionExecuted);122 await browser.CloseAsync();123 }124 [PuppeteerTest("launcher.spec.ts", "Puppeteer.connect", "should be able to reconnect to a disconnected browser")]125 [SkipBrowserFact(skipFirefox: true)]126 public async Task ShouldBeAbleToReconnectToADisconnectedBrowser()127 {128 var options = new ConnectOptions()129 {130 BrowserWSEndpoint = Browser.WebSocketEndpoint131 };132 var url = TestConstants.ServerUrl + "/frames/nested-frames.html";133 var page = await Browser.NewPageAsync();134 await page.GoToAsync(url);135 Browser.Disconnect();136 await using (var browser = await Puppeteer.ConnectAsync(options, TestConstants.LoggerFactory))137 {138 var pages = (await browser.PagesAsync()).ToList();139 var restoredPage = pages.FirstOrDefault(x => x.Url == url);140 Assert.NotNull(restoredPage);141 var frameDump = FrameUtils.DumpFrames(restoredPage.MainFrame);142 Assert.Equal(TestConstants.NestedFramesDumpResult, frameDump);143 var response = await restoredPage.EvaluateExpressionAsync<int>("7 * 8");144 Assert.Equal(56, response);145 }146 }147 [PuppeteerTest("launcher.spec.ts", "Puppeteer.connect", "should be able to connect to the same page simultaneously")]148 [SkipBrowserFact(skipFirefox: true)]149 public async Task ShouldBeAbleToConnectToTheSamePageSimultaneously()150 {151 var browserOne = await Puppeteer.LaunchAsync(new LaunchOptions());152 var browserTwo = await Puppeteer.ConnectAsync(new ConnectOptions153 {154 BrowserWSEndpoint = browserOne.WebSocketEndpoint155 });156 var tcs = new TaskCompletionSource<Page>();157 async void TargetCreated(object sender, TargetChangedArgs e)158 {159 tcs.TrySetResult(await e.Target.PageAsync());160 browserOne.TargetCreated -= TargetCreated;161 }162 browserOne.TargetCreated += TargetCreated;163 var page2Task = browserTwo.NewPageAsync();164 await Task.WhenAll(tcs.Task, page2Task);165 var page1 = tcs.Task.Result;166 var page2 = page2Task.Result;167 Assert.Equal(56, await page1.EvaluateExpressionAsync<int>("7 * 8"));168 Assert.Equal(42, await page2.EvaluateExpressionAsync<int>("7 * 6"));169 await browserOne.CloseAsync();170 }171 [PuppeteerTest("launcher.spec.ts", "Puppeteer.connect", "should be able to reconnect")]172 [SkipBrowserFact(skipFirefox: true)]173 public async Task ShouldBeAbleToReconnect()174 {175 var browserOne = await Puppeteer.LaunchAsync(new LaunchOptions());176 var browserWSEndpoint = browserOne.WebSocketEndpoint;177 var page1 = await browserOne.NewPageAsync();178 await page1.GoToAsync(TestConstants.EmptyPage);179 browserOne.Disconnect();180 var browserTwo = await Puppeteer.ConnectAsync(new ConnectOptions181 {182 BrowserWSEndpoint = browserWSEndpoint183 });184 var pages = await browserTwo.PagesAsync();185 var pageTwo = pages.First(page => page.Url == TestConstants.EmptyPage);186 await pageTwo.ReloadAsync();187 var bodyHandle = await pageTwo.WaitForSelectorAsync("body", new WaitForSelectorOptions { Timeout = 10000 });188 await bodyHandle.DisposeAsync();189 await browserTwo.CloseAsync();190 }191 [PuppeteerFact]192 public async Task ShouldSupportCustomWebSocket()193 {194 var customSocketCreated = false;195 var options = new ConnectOptions()196 {197 BrowserWSEndpoint = Browser.WebSocketEndpoint,198 WebSocketFactory = (uri, socketOptions, cancellationToken) =>199 {200 customSocketCreated = true;201 return WebSocketTransport.DefaultWebSocketFactory(uri, socketOptions, cancellationToken);202 }203 };204 await using (await Puppeteer.ConnectAsync(options, TestConstants.LoggerFactory))205 {206 Assert.True(customSocketCreated);207 }208 }209 [PuppeteerFact]210 public async Task ShouldSupportCustomTransport()211 {212 var customTransportCreated = false;213 var options = new ConnectOptions()214 {215 BrowserWSEndpoint = Browser.WebSocketEndpoint,216 TransportFactory = (url, opt, cancellationToken) =>217 {218 customTransportCreated = true;219 return WebSocketTransport.DefaultTransportFactory(url, opt, cancellationToken);220 }221 };222 await using (await Puppeteer.ConnectAsync(options, TestConstants.LoggerFactory))223 {224 Assert.True(customTransportCreated);225 }226 }227 }228}...
Launcher.cs
Source:Launcher.cs
...74 /// Attaches Puppeteer to an existing Chromium instance. The browser will be closed when the Browser is disposed.75 /// </summary>76 /// <param name="options">Options for connecting.</param>77 /// <returns>A connected browser.</returns>78 public async Task<Browser> ConnectAsync(ConnectOptions options)79 {80 EnsureSingleLaunchOrConnect();81 try82 {83 var connection = await Connection.Create(options.BrowserWSEndpoint, options, _loggerFactory).ConfigureAwait(false);84 var response = await connection.SendAsync<GetBrowserContextsResponse>("Target.getBrowserContexts");85 return await Browser86 .CreateAsync(connection, response.BrowserContextIds, options.IgnoreHTTPSErrors, options.DefaultViewport, null)87 .ConfigureAwait(false);88 }89 catch (Exception ex)90 {91 throw new ChromiumProcessException("Failed to create connection", ex);92 }...
FixturesTests.cs
Source:FixturesTests.cs
...38 var ChromiumLauncher = new ChromiumLauncher(39 (await browserFetcher.GetRevisionInfoAsync()).ExecutablePath,40 new LaunchOptions { Headless = true });41 await ChromiumLauncher.StartAsync().ConfigureAwait(false);42 var browser = await Puppeteer.ConnectAsync(new ConnectOptions43 {44 BrowserWSEndpoint = ChromiumLauncher.EndPoint45 });46 browser.Disconnected += (_, _) =>47 {48 browserClosedTaskWrapper.SetResult(true);49 };50 KillProcess(ChromiumLauncher.Process.Id);51 await browserClosedTaskWrapper.Task;52 Assert.True(browser.IsClosed);53 }54 [PuppeteerTest("fixtures.spec.ts", "Fixtures", "should close the browser when the node process closes")]55 [SkipBrowserFact(skipFirefox: true)]56 public async Task ShouldCloseTheBrowserWhenTheLaunchedProcessCloses()...
Puppeteer.cs
Source:Puppeteer.cs
...44 /// </summary>45 /// <param name="options">Options for connecting.</param>46 /// <param name="loggerFactory">The logger factory</param>47 /// <returns>A connected browser.</returns>48 public static Task<Browser> ConnectAsync(ConnectOptions options, ILoggerFactory loggerFactory = null)49 => new Launcher(loggerFactory).ConnectAsync(options);50 }51}...
BrowserDisconnectTests.cs
Source:BrowserDisconnectTests.cs
...17 {18 Server.SetRoute("/one-style.css", _ => Task.Delay(10000));19 await using (var browser = await Puppeteer.LaunchAsync(TestConstants.DefaultBrowserOptions()))20 {21 var remote = await Puppeteer.ConnectAsync(new ConnectOptions22 {23 BrowserWSEndpoint = browser.WebSocketEndpoint24 });25 var page = await remote.NewPageAsync();26 var navigationTask = page.GoToAsync(TestConstants.ServerUrl + "/one-style.html", new NavigationOptions27 {28 Timeout = 6000029 });30 await Server.WaitForRequest("/one-style.css");31 remote.Disconnect();32 var exception = await Assert.ThrowsAsync<NavigationException>(() => navigationTask);33 Assert.Contains("Navigation failed because browser has disconnected!", exception.Message);34 }35 }36 [PuppeteerTest("launcher.spec.ts", "Browser.disconnect", "should reject waitForSelector when browser closes")]37 [PuppeteerFact]38 public async Task ShouldRejectWaitForSelectorWhenBrowserCloses()39 {40 Server.SetRoute("/empty.html", _ => Task.Delay(10000));41 await using (var browser = await Puppeteer.LaunchAsync(TestConstants.DefaultBrowserOptions()))42 {43 var remote = await Puppeteer.ConnectAsync(new ConnectOptions44 {45 BrowserWSEndpoint = browser.WebSocketEndpoint46 });47 var page = await remote.NewPageAsync();48 var watchdog = page.WaitForSelectorAsync("div", new WaitForSelectorOptions { Timeout = 60000 });49 remote.Disconnect();50 var exception = await Assert.ThrowsAsync<TargetClosedException>(() => watchdog);51 Assert.Equal("Connection disposed", exception.CloseReason);52 }53 }54 }55}...
BrowserEventsDisconnectedTests.cs
Source:BrowserEventsDisconnectedTests.cs
...16 public async Task ShouldEmittedWhenBrowserGetsClosedDisconnectedOrUnderlyingWebsocketGetsClosed()17 {18 var originalBrowser = await Puppeteer.LaunchAsync(TestConstants.DefaultBrowserOptions(), TestConstants.LoggerFactory);19 var connectOptions = new ConnectOptions { BrowserWSEndpoint = originalBrowser.WebSocketEndpoint };20 var remoteBrowser1 = await Puppeteer.ConnectAsync(connectOptions, TestConstants.LoggerFactory);21 var remoteBrowser2 = await Puppeteer.ConnectAsync(connectOptions, TestConstants.LoggerFactory);22 var disconnectedOriginal = 0;23 var disconnectedRemote1 = 0;24 var disconnectedRemote2 = 0;25 originalBrowser.Disconnected += (_, _) => ++disconnectedOriginal;26 remoteBrowser1.Disconnected += (_, _) => ++disconnectedRemote1;27 remoteBrowser2.Disconnected += (_, _) => ++disconnectedRemote2;28 var remoteBrowser2Disconnected = WaitForBrowserDisconnect(remoteBrowser2);29 remoteBrowser2.Disconnect();30 await remoteBrowser2Disconnected;31 Assert.Equal(0, disconnectedOriginal);32 Assert.Equal(0, disconnectedRemote1);33 Assert.Equal(1, disconnectedRemote2);34 var remoteBrowser1Disconnected = WaitForBrowserDisconnect(remoteBrowser1);35 var originalBrowserDisconnected = WaitForBrowserDisconnect(originalBrowser);...
BrowserCloseTests.cs
Source:BrowserCloseTests.cs
...15 [PuppeteerFact]16 public async Task ShouldTerminateNetworkWaiters()17 {18 await using (var browser = await Puppeteer.LaunchAsync(TestConstants.DefaultBrowserOptions()))19 await using (var remote = await Puppeteer.ConnectAsync(new ConnectOptions { BrowserWSEndpoint = browser.WebSocketEndpoint }))20 {21 var newPage = await remote.NewPageAsync();22 var requestTask = newPage.WaitForRequestAsync(TestConstants.EmptyPage);23 var responseTask = newPage.WaitForResponseAsync(TestConstants.EmptyPage);24 await browser.CloseAsync();25 var exception = await Assert.ThrowsAsync<TargetClosedException>(() => requestTask);26 Assert.Contains("Target closed", exception.Message);27 Assert.DoesNotContain("Timeout", exception.Message);28 exception = await Assert.ThrowsAsync<TargetClosedException>(() => responseTask);29 Assert.Contains("Target closed", exception.Message);30 Assert.DoesNotContain("Timeout", exception.Message);31 }32 }33 }...
ConnectAsync
Using AI Code Generation
1using System;2using System.Threading.Tasks;3using PuppeteerSharp;4{5 {6 static async Task Main(string[] args)7 {8 {9 };10 var browser = await Puppeteer.ConnectAsync(options);11 var page = await browser.NewPageAsync();12 await page.ScreenshotAsync("google.png");13 }14 }15}16using System;17using System.Threading.Tasks;18using PuppeteerSharp;19{20 {21 static async Task Main(string[] args)22 {23 var browser = await Puppeteer.LaunchAsync();24 var page = await browser.NewPageAsync();25 await page.ScreenshotAsync("google.png");26 }27 }28}29using System;30using System.Threading.Tasks;31using PuppeteerSharp;32{33 {34 static async Task Main(string[] args)35 {36 {37 ExecutablePath = @"C:\Program Files (x86)\Google\Chrome\Application\chrome.exe"38 };39 var browser = await Puppeteer.LaunchAsync(options);40 var page = await browser.NewPageAsync();41 await page.ScreenshotAsync("google.png");42 }43 }44}
ConnectAsync
Using AI Code Generation
1using (var browser = await Puppeteer.LaunchAsync(new LaunchOptions2{3 ExecutablePath = @"C:\Program Files (x86)\Google\Chrome\Application\chrome.exe",4}))5{6 var page = await browser.NewPageAsync();7 Console.WriteLine("done");8 Console.ReadKey();9}10using (var browser = await Puppeteer.LaunchAsync(new LaunchOptions11{12 ExecutablePath = @"C:\Program Files (x86)\Google\Chrome\Application\chrome.exe",13}))14{15 var page = await browser.NewPageAsync();16 Console.WriteLine("done");17 Console.ReadKey();18}191. LaunchAsync(LaunchOptions options = null)202. LaunchAsync(LaunchOptions options = null, BrowserContextOptions contextOptions = null)211. LaunchAsync(LaunchOptions options = null)222. LaunchAsync(LaunchOptions options = null,
ConnectAsync
Using AI Code Generation
1using System;2using System.Threading.Tasks;3using PuppeteerSharp;4{5 {6 static async Task Main(string[] args)7 {
ConnectAsync
Using AI Code Generation
1using System;2using System.Threading.Tasks;3using PuppeteerSharp;4{5 {6 static async Task Main(string[] args)7 {8 var browser = await Puppeteer.ConnectAsync(options);9 var page = await browser.NewPageAsync();10 await page.ScreenshotAsync("google.png");11 await browser.CloseAsync();12 }13 }14}
ConnectAsync
Using AI Code Generation
1using System;2using System.Threading.Tasks;3using PuppeteerSharp;4{5 {6 static async Task Main(string[] args)7 {8 {9 };10 var browser = await Puppeteer.ConnectAsync(options);11 var page = await browser.NewPageAsync();12 await page.ScreenshotAsync("google.png");13 await browser.CloseAsync();14 }15 }16}17using System;18using System.Threading.Tasks;19using PuppeteerSharp;20{21 {22 static async Task Main(string[] args)23 {24 {25 };26 var browser = await Puppeteer.ConnectAsync(options);27 var page = await browser.NewPageAsync();28 await page.ScreenshotAsync("google.png");29 await browser.CloseAsync();30 }31 }32}33using System;34using System.Threading.Tasks;35using PuppeteerSharp;36{37 {38 static async Task Main(string[] args)39 {40 {41 };42 var browser = await Puppeteer.ConnectAsync(options);43 var page = await browser.NewPageAsync();
ConnectAsync
Using AI Code Generation
1using System;2using System.Threading.Tasks;3using PuppeteerSharp;4{5 {6 public static async Task Main(string[] args)7 {8 var browser = await Puppeteer.ConnectAsync(new ConnectOptions9 {
ConnectAsync
Using AI Code Generation
1using System;2using System.Threading.Tasks;3using PuppeteerSharp;4{5 {6 static async Task Main(string[] args)7 {8 {9 };10 var browser = await Puppeteer.ConnectAsync(options);11 var page = await browser.NewPageAsync();12 await page.ScreenshotAsync("google.png");13 await browser.CloseAsync();14 }15 }16}
ConnectAsync
Using AI Code Generation
1using System;2using System.Threading.Tasks;3using PuppeteerSharp;4{5 {6 private static async Task Main(string[] args)7 {8 {9 };10 var browserFetcher = new BrowserFetcher(browserFetcherOptions);11 await browserFetcher.DownloadAsync(BrowserFetcher.DefaultRevision);12 var browser = await Puppeteer.LaunchAsync(new LaunchOptions13 {14 ExecutablePath = browserFetcher.GetExecutablePath(BrowserFetcher.DefaultRevision)15 });16 var page = await browser.NewPageAsync();17 await page.ScreenshotAsync("google.png");18 await browser.CloseAsync();19 }20 }21}22using System;23using System.Threading.Tasks;24using PuppeteerSharp;25{26 {27 private static async Task Main(string[] args)28 {29 {30 };31 var browserFetcher = new BrowserFetcher(browserFetcherOptions);32 await browserFetcher.DownloadAsync(BrowserFetcher.DefaultRevision);33 var browser = await Puppeteer.LaunchAsync(new LaunchOptions34 {35 ExecutablePath = browserFetcher.GetExecutablePath(BrowserFetcher.DefaultRevision)36 });37 var page = await browser.NewPageAsync();38 await page.ScreenshotAsync("google.png");39 await browser.CloseAsync();40 }41 }42}43using System;44using System.Threading.Tasks;45using PuppeteerSharp;46{47 {48 private static async Task Main(string[] args)49 {50 {51 };52 var browserFetcher = new BrowserFetcher(browserFetcherOptions);53 await browserFetcher.DownloadAsync(BrowserFetcher.DefaultRevision);54 var browser = await Puppeteer.LaunchAsync(new
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!