public async Task ShouldSupportContextOptions() { BrowserContextOptions contextOptions = Playwright.Devices["iPhone 6"]; contextOptions.TimezoneId = "America/Jamaica"; contextOptions.Locale = "fr-CH"; contextOptions.UserAgent = "UA"; await using var context = await _browser.NewContextAsync(contextOptions); var page = await context.NewPageAsync(); var(userAgent, _) = await TaskUtils.WhenAll( Server.WaitForRequest("/grid.html", r => r.Headers["user-agent"]), page.GoToAsync(TestConstants.ServerIpUrl + "/dynamic-oopif.html")); Assert.Equal(2, page.Frames.Count()); Assert.Equal(1, await CountOOPIFsASync(_browser)); var oopif = page.Frames[1]; Assert.True(await oopif.EvaluateAsync <bool?>("() => 'ontouchstart' in window")); Assert.Equal( "Sat Nov 19 2016 13:12:34 GMT-0500 (heure normale de l’Est nord-américain)", await oopif.EvaluateAsync <string>("() => new Date(1479579154987).toString()")); Assert.Equal("fr-CH", await oopif.EvaluateAsync <string>("() => navigator.language")); Assert.Equal("UA", await oopif.EvaluateAsync <string>("() => navigator.userAgent")); Assert.Equal("UA", userAgent); }
internal async Task <IBrowserContext> NewContextAsync(BrowserContextOptions options = null) { var context = await Browser.NewContextAsync(options); _contexts.Add(context); return(context); }
internal BrowserContextOptions ConfigureUniqueHarPath(BrowserContextOptions browserContextOptions) { if (browserContextOptions?.RecordHar?.Path != null) { var identifier = Guid.NewGuid().ToString("N"); var harDirectory = Environment.GetEnvironmentVariable("HELIX_WORKITEM_UPLOAD_ROOT"); if (string.IsNullOrEmpty(harDirectory)) { harDirectory = browserContextOptions.RecordHar.Path; } browserContextOptions.RecordHar.Path = Path.Combine(harDirectory, $"{identifier}.har"); _harPath = browserContextOptions.RecordHar.Path; } if (browserContextOptions?.RecordVideo?.Dir != null) { var uploadDir = Environment.GetEnvironmentVariable("HELIX_WORKITEM_UPLOAD_ROOT"); if (!string.IsNullOrEmpty(uploadDir)) { browserContextOptions.RecordVideo.Dir = uploadDir; } } return(browserContextOptions); }
public async Task ShouldUseContextOptions() { var options = new BrowserContextOptions { Geolocation = new GeolocationOption { Latitude = 10, Longitude = 10 }, Permissions = new Dictionary <string, ContextPermission[]> { [TestConstants.ServerUrl] = new[] { ContextPermission.Geolocation } } }; var context = await NewContextAsync(options); var page = await context.NewPageAsync(); await page.GoToAsync(TestConstants.EmptyPage); var geolocation = await page.EvaluateAsync <GeolocationOption>(@"() => new Promise(resolve => navigator.geolocation.getCurrentPosition(position => { resolve({latitude: position.coords.latitude, longitude: position.coords.longitude}); }))"); Assert.Equal(options.Geolocation, geolocation); }
internal FirefoxBrowserContext(string browserContextId, FirefoxConnection connection, BrowserContextOptions browserContextOptions, FirefoxBrowser browser) { _browserContextId = browserContextId; _connection = connection; _browserContextOptions = browserContextOptions; _browser = browser; }
internal Task <BrowserContextChannel> NewContextAsync(BrowserContextOptions options) => Scope.SendMessageToServer <BrowserContextChannel>( Guid, "newContext", new Dictionary <string, object> { ["options"] = options ?? new BrowserContextOptions(), });
/// <inheritdoc cref="IBrowser.NewContextAsync"/> public async Task <IBrowserContext> NewContextAsync(BrowserContextOptions options = null) { string browserContextId = (await _session.SendAsync(new TargetCreateBrowserContextRequest()).ConfigureAwait(false)).BrowserContextId; var context = CreateBrowserContext(browserContextId, options); await context.InitializeAsync().ConfigureAwait(false); _contexts.Add(browserContextId, context); return(context); }
internal BrowserContextOptions ConfigureUniqueHarPath(BrowserContextOptions browserContextOptions) { if (browserContextOptions?.RecordHar?.Path != null) { var identifier = Guid.NewGuid().ToString("N"); browserContextOptions.RecordHar.Path = Path.Combine(browserContextOptions.RecordHar.Path, $"{identifier}.har"); _harPath = browserContextOptions.RecordHar.Path; } return(browserContextOptions); }
internal ChromiumBrowserContext( ChromiumSession client, ChromiumBrowser chromiumBrowser, string contextId, BrowserContextOptions options) { _client = client; _browser = chromiumBrowser; _contextId = contextId; Options = options; }
internal static Task <IBrowser> LaunchDefaultHeadful( this IBrowserType browserType, BrowserContextOptions options = null, string downloadsPath = null) { options ??= new BrowserContextOptions(); return(browserType.LaunchAsync( downloadsPath: downloadsPath, slowMo: Convert.ToInt32(Environment.GetEnvironmentVariable("SLOW_MO")), headless: false, timeout: 0 )); }
internal static Task <IBrowser> LaunchDefaultAsync( this IBrowserType browserType, BrowserContextOptions options = null, string downloadsPath = null, string[] args = null) { options ??= new BrowserContextOptions(); return(browserType.LaunchAsync( args: args, downloadsPath: downloadsPath, slowMo: Convert.ToInt32(Environment.GetEnvironmentVariable("SLOW_MO")), headless: Convert.ToBoolean(Environment.GetEnvironmentVariable("HEADLESS") ?? "true"), timeout: 0 )); }
/// <inheritdoc cref="IBrowser.NewContextAsync(BrowserContextOptions)"/> public async Task <IBrowserContext> NewContextAsync(BrowserContextOptions options = null) { string browserContextId = (await _connection.SendAsync(new TargetCreateBrowserContextRequest()).ConfigureAwait(false)).BrowserContextId; if (options?.IgnoreHTTPSErrors == true) { await _connection.SendAsync(new BrowserSetIgnoreHTTPSErrorsRequest { Enabled = true }).ConfigureAwait(false); } var context = CreateBrowserContext(browserContextId, options); await context.InitializeAsync().ConfigureAwait(false); Contexts[browserContextId] = context; return(context); }
internal static Task <IBrowserContext> LaunchDefaultPersistentContext( this IBrowserType browserType, string userDataDir, string[] args = null, BrowserContextOptions options = null, bool?headless = null) { options ??= new BrowserContextOptions(); return(browserType.LaunchPersistentContextAsync( userDataDir: userDataDir, acceptDownloads: options.AcceptDownloads, args: args, bypassCSP: options.BypassCSP, channel: BrowserChannel.Undefined, chromiumSandbox: null, colorScheme: options.ColorScheme, deviceScaleFactor: options.DeviceScaleFactor, devtools: null, downloadsPath: null, env: null, executablePath: null, extraHTTPHeaders: options.ExtraHTTPHeaders, geolocation: options.Geolocation, handleSIGHUP: null, handleSIGINT: null, handleSIGTERM: null, hasTouch: options.HasTouch, headless: headless, httpCredentials: options.HttpCredentials, ignoreAllDefaultArgs: null, ignoreHTTPSErrors: options.IgnoreHTTPSErrors, isMobile: options.IsMobile, javaScriptEnabled: options.JavaScriptEnabled, locale: options.Locale, offline: options.Offline, permissions: options.Permissions, proxy: options.Proxy, recordHarOmitContent: null, recordHarPath: null, recordVideoDir: null, recordVideoSize: null, slowMo: null, timeout: null, timezoneId: options.TimezoneId, userAgent: options.UserAgent, viewportSize: options.Viewport )); }
public async Task ShouldMakeACopyOfDefaultOptions() { var options = new BrowserContextOptions { 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 ShouldNotModifyPassedDefaultOptionsObject() { var geolocation = new GeolocationOption { Latitude = 10, Longitude = 10 }; BrowserContextOptions options = new BrowserContextOptions { Geolocation = geolocation }; var context = await NewContextAsync(options); await Page.GoToAsync(TestConstants.EmptyPage); await Context.SetGeolocationAsync(new GeolocationOption { Longitude = 20, Latitude = 20 }); Assert.Equal(options.Geolocation, geolocation); }
private async Task <(TempDirectory tmp, IBrowserContext context, IPage page)> LaunchAsync(BrowserContextOptions options = null) { var tmp = new TempDirectory(); var context = await BrowserType.LaunchDefaultPersistentContext( tmp.Path, options : options); var page = context.Pages.First(); return(tmp, context, page); }
internal Task <IBrowserContext> NewContextAsync(BrowserContextOptions options = null) => Browser.NewContextAsync(options);
/// <inheritdoc/> public PageEmulateTests(ITestOutputHelper output) : base(output) { _iPhone = Playwright.Devices["iPhone 6"]; }
internal BrowserContext(IBrowserContextDelegate browserContextDelegate, BrowserContextOptions options) { _delegate = browserContextDelegate; _delegate.BrowserContext = this; Options = options ?? new BrowserContextOptions(); }
private async Task <(TempDirectory tmp, IBrowserContext context, IPage page)> LaunchAsync(BrowserContextOptions options = null) { var tmp = new TempDirectory(); var context = await BrowserType.LaunchPersistentContextAsync( tmp.Path, TestConstants.GetDefaultBrowserOptions().ToPersistentOptions() + (options ?? new BrowserContextOptions())); var page = context.Pages.First(); return(tmp, context, page); }
internal async Task <IPage> NewPageAsync(BrowserContextOptions options = null) { var context = await NewContextAsync(options); return(await context.NewPageAsync()); }
/// <inheritdoc/> public BrowserContextDeviceTests(ITestOutputHelper output) : base(output) { _iPhone = Playwright.Devices["iPhone 6"]; }
internal Task <BrowserContextChannel> NewContextAsync(BrowserContextOptions options) => Connection.SendMessageToServerAsync <BrowserContextChannel>( Guid, "newContext", options.ToChannelDictionary(), true);
/// <inheritdoc/> public new async Task <IChromiumBrowserContext> NewContextAsync(BrowserContextOptions options) => await base.NewContextAsync(options).ConfigureAwait(false) as IChromiumBrowserContext;
public BrowserContextOptions GetContextOptions(string browser, string contextName, BrowserContextOptions options) => Combine(GetContextOptions(browser, contextName), options);
/// <inheritdoc/> public BrowserContextViewportMobileTests(ITestOutputHelper output) : base(output) { _iPhone = Playwright.Devices["iPhone 6"]; _iPhoneLandscape = Playwright.Devices["iPhone 6 landscape"]; }
private BrowserContext CreateBrowserContext(string contextId, BrowserContextOptions options = null) => new BrowserContext(new ChromiumBrowserContext(_session, this, contextId, options), options);
private BrowserContext CreateBrowserContext(string browserContextId, BrowserContextOptions options = null) => new BrowserContext(new FirefoxBrowserContext(browserContextId, _connection, options ?? new BrowserContextOptions(), this), options);
internal async Task <IPage> NewPageAsync(IBrowser browser, BrowserContextOptions options = null) { await using var context = await browser.NewContextAsync(options); return(await context.NewPageAsync()); }