public async Task ShouldUseContextOptions() { var options = new BrowserNewContextOptions { Geolocation = new Geolocation { Latitude = 10, Longitude = 10 }, Permissions = new[] { "geolocation" }, }; await using var context = await Browser.NewContextAsync(options); var page = await context.NewPageAsync(); await page.GotoAsync(TestConstants.EmptyPage); var geolocation = await page.EvaluateAsync <Geolocation>(@"() => new Promise(resolve => navigator.geolocation.getCurrentPosition(position => { resolve({latitude: position.coords.latitude, longitude: position.coords.longitude}); }))"); Assert.Equal(options.Geolocation.Latitude, geolocation.Latitude); Assert.Equal(options.Geolocation.Longitude, geolocation.Longitude); }
protected virtual BrowserNewContextOptions CreateContextOptions() { var options = new BrowserNewContextOptions() { IgnoreHTTPSErrors = true, Locale = "en-GB", TimezoneId = "Europe/London", }; if (IsRunningInGitHubActions) { options.RecordVideoDir = VideosDirectory; } return(options); }
public async Task ShouldMakeACopyOfDefaultOptions() { var options = new BrowserNewContextOptions { UserAgent = "foobar" }; await using var context = await Browser.NewContextAsync(options); options.UserAgent = "wrong"; var page = await context.NewPageAsync(); var(userAgent, _) = await TaskUtils.WhenAll( Server.WaitForRequest("/empty.html", request => request.Headers["User-Agent"].ToString()), page.GotoAsync(TestConstants.EmptyPage) ); Assert.Equal("foobar", userAgent); }
public async Task ShouldUnroutePageWithBaseUrl() { var options = new BrowserNewContextOptions(); options.BaseURL = Server.Prefix; await using var context = await Browser.NewContextAsync(options); var page = await context.NewPageAsync(); var intercepted = new List <int>(); await page.RouteAsync("/empty.html", (route) => { intercepted.Add(1); route.ContinueAsync(); }); Action <IRoute> handler2 = (route) => { intercepted.Add(2); route.ContinueAsync(); }; await page.RouteAsync("/empty.html", handler2); await page.GotoAsync(Server.EmptyPage); Assert.AreEqual(new List <int>() { 2 }, intercepted); intercepted.Clear(); await page.UnrouteAsync("/empty.html", handler2); await page.GotoAsync(Server.EmptyPage); Assert.AreEqual(new List <int>() { 1 }, intercepted); }
public async Task ShouldNotModifyPassedDefaultOptionsObject() { var geolocation = new Geolocation { Latitude = 10, Longitude = 10 }; BrowserNewContextOptions options = new BrowserNewContextOptions { Geolocation = geolocation }; await using var context = await Browser.NewContextAsync(options); await Page.GotoAsync(TestConstants.EmptyPage); await Context.SetGeolocationAsync(new Geolocation { Longitude = 20, Latitude = 20 }); Assert.Equal(options.Geolocation.Latitude, geolocation.Latitude); Assert.Equal(options.Geolocation.Longitude, geolocation.Longitude); }
internal BrowserNewContextOptions ConfigureUniqueHarPath(BrowserNewContextOptions browserContextOptions) { var uploadDir = Environment.GetEnvironmentVariable("HELIX_WORKITEM_UPLOAD_ROOT"); if (browserContextOptions?.RecordHarPath != null) { var identifier = Guid.NewGuid().ToString("N"); browserContextOptions.RecordHarPath = Path.Combine( string.IsNullOrEmpty(uploadDir) ? browserContextOptions.RecordHarPath : uploadDir, $"{identifier}.har"); _harPath = browserContextOptions.RecordHarPath; } if (browserContextOptions?.RecordVideoDir != null) { if (!string.IsNullOrEmpty(uploadDir)) { browserContextOptions.RecordVideoDir = uploadDir; } } return(browserContextOptions); }
public static Task <Result <IBrowserContext, Error> > NewContext(this IBrowser browser, BrowserNewContextOptions browserNewContextOptions) => browser.NewContextAsync(browserNewContextOptions) .Map2( faulted => Error <IBrowserContext, Error>($"Could not open new browser context because of {faulted.InnerException}"), succeeded => Ok <IBrowserContext, Error>(succeeded));
public BrowserNewContextOptions GetContextOptions(string browser, string contextName, BrowserNewContextOptions options) => Combine(GetContextOptions(browser, contextName), options);