protected override async Task BeforeExecutionAsync(IExecutionContext context) { var builder = WebApplication.CreateBuilder(); builder.Logging.ClearProviders(); builder.Services .AddRazorPages() .WithRazorPagesRoot("/src/SocialCards/"); _app = builder.Build(); _app.MapRazorPages(); _app.UseStaticFiles(new StaticFileOptions { FileProvider = new PhysicalFileProvider( Path.Combine(builder.Environment.ContentRootPath, "src/SocialCards")), RequestPath = "/static" }); await _app.StartAsync().ConfigureAwait(false); _playwright = await Playwright.CreateAsync().ConfigureAwait(false); _browser = await _playwright.Chromium.LaunchAsync().ConfigureAwait(false); _context = await _browser.NewContextAsync(new BrowserNewContextOptions { ViewportSize = new ViewportSize { Width = 1200, Height = 618 }, }).ConfigureAwait(false); }
public static Task <Result <IPage, Error> > NewPage(this IBrowserContext context) => context.NewPageAsync() .Map2( faulted => Error <IPage, Error>($"Could not open a new page in the browser context because of {faulted.InnerException}"), succeeded => Ok <IPage, Error>(succeeded));
private static async Task <IPage> NavigateToPage(IBrowserContext browser, string listeningUri) { var page = await browser.NewPageAsync(); await page.GotoAsync(listeningUri, new() { WaitUntil = WaitUntilState.NetworkIdle }); return(page); }
/// <inheritdoc cref="IPage"/> internal Page(IPageDelegate pageDelegate, IBrowserContext browserContext) { FrameManager = new FrameManager(this); Delegate = pageDelegate; BrowserContext = browserContext; Keyboard = new Keyboard(Delegate.RawKeyboard); Mouse = new Mouse(Delegate.RawMouse, Keyboard); }
private async Task <IPage> NavigateToPage(IBrowserContext browser, string listeningUri) { var page = await browser.NewPageAsync(); await page.GoToAsync(listeningUri, LifecycleEvent.Networkidle); return(page); }
/// <inheritdoc cref="IAsyncLifetime.InitializeAsync"/> public override async Task InitializeAsync() { _harPath = Path.Combine(_tempDir.Path, "test.har"); _context = await Browser.NewContextAsync(recordHarPath : _harPath, ignoreHTTPSErrors : true); _page = await _context.NewPageAsync(); await base.InitializeAsync(); }
public ChromiumPage(ChromiumSession client, ChromiumBrowser browser, IBrowserContext browserContext) { Client = client; _browser = browser; _browserContext = browserContext; _networkManager = new ChromiumNetworkManager(Client, this); RawKeyboard = new ChromiumRawKeyboard(client); RawMouse = new ChromiumRawMouse(client); Page = new Page(this, browserContext); client.MessageReceived += Client_MessageReceived; }
public async Task <IPage> GetPage() { playwright = await Playwright.CreateAsync(); browser = await playwright.Chromium.LaunchAsync(new BrowserTypeLaunchOptions { //Headless = false, //SlowMo = 50, }); context = await browser.NewContextAsync(); return(await context.NewPageAsync()); }
/// <inheritdoc cref="IPage"/> internal Page(IPageDelegate pageDelegate, IBrowserContext browserContext) { FrameManager = new FrameManager(this); Delegate = pageDelegate; BrowserContext = browserContext; Keyboard = new Keyboard(Delegate.RawKeyboard); Mouse = new Mouse(Delegate.RawMouse, Keyboard); PageState = new PageState { Viewport = browserContext.Options.Viewport }; Screenshotter = new Screenshotter(this); }
public FirefoxPage(FirefoxSession session, IBrowserContext context, Func <Task <Page> > openerResolver) { _session = session; _context = context; _openerResolver = openerResolver; RawKeyboard = new FirefoxRawKeyboard(session); RawMouse = new FirefoxRawMouse(session); Page = new Page(this, _context); _networkManager = new FirefoxNetworkManager(session, Page); session.MessageReceived += OnMessageReceived; Page.FrameDetached += RemoveContextsForFrame; }
internal ChromiumTarget( TargetInfo targetInfo, ChromiumBrowser browser, Func <Task <ChromiumSession> > sessionFactory, IBrowserContext browserContext) { TargetInfo = targetInfo; _browser = browser; _sessionFactory = sessionFactory; BrowserContext = browserContext; PageTask = null; _ = _initializedTaskWrapper.Task.ContinueWith( async initializedTask => { bool success = initializedTask.Result; if (!success) { return; } var openerPageTask = Opener?.PageTask; if (openerPageTask == null || Type != TargetType.Page) { return; } var openerPage = await openerPageTask.ConfigureAwait(false); if (!openerPage.HasPopupEventListeners) { return; } var popupPage = await PageAsync().ConfigureAwait(false); openerPage.OnPopup(popupPage); }, CancellationToken.None, TaskContinuationOptions.RunContinuationsAsynchronously, TaskScheduler.Default); CloseTaskWrapper = new TaskCompletionSource <bool>(TaskCreationOptions.RunContinuationsAsynchronously); IsInitialized = Type != TargetType.Page || !string.IsNullOrEmpty(TargetInfo.Url); if (IsInitialized) { _initializedTaskWrapper.TrySetResult(true); } }
public async Task createBrowser() { playwright = await Playwright.CreateAsync(); BrowserTypeLaunchOptions typeLaunchOptions = new BrowserTypeLaunchOptions { Headless = false }; browser = await playwright.Chromium.LaunchAsync(typeLaunchOptions); context = await browser.NewContextAsync(); page = await context.NewPageAsync(); _objectContainer.RegisterInstanceAs(page); }
public FirefoxTarget(FirefoxConnection connection, FirefoxBrowser firefoxBrowser, IBrowserContext context, string targetId, TargetInfoType type, string url, string openerId) { _connection = connection; _browser = firefoxBrowser; _targetId = targetId; _openerId = openerId; BrowserContext = context; Type = type switch { TargetInfoType.Browser => TargetType.Browser, TargetInfoType.Page => TargetType.Page, _ => throw new ArgumentOutOfRangeException(nameof(type)) }; Url = url; }
private async Task <(IPage, IBrowserContext, System.Func <Task <dynamic> >)> PageWithHAR() { var tmp = new TempDirectory(); var harPath = Path.Combine(tmp.Path, "har.json"); IBrowserContext context = await Browser.NewContextAsync(new() { RecordHarPath = harPath, IgnoreHTTPSErrors = true }); IPage page = await context.NewPageAsync(); async Task <dynamic> getContent() { await context.CloseAsync(); var content = await File.ReadAllTextAsync(harPath); tmp.Dispose(); return(JsonSerializer.Deserialize <dynamic>(content)); }; return(page, context, getContent); }
/// <inheritsdoc/> public async Task InitializeAsync() { Server.SetRoute("/download", context => { context.Response.Headers["Content-Type"] = "application/octet-stream"; context.Response.Headers["Content-Disposition"] = "attachment; filename=file.txt"; return(context.Response.WriteAsync("Hello world")); }); _downloadsPath = new TempDirectory(); _userDataDir = new TempDirectory(); var options = TestConstants.GetDefaultBrowserOptions().ToPersistentOptions(); options.DownloadsPath = _downloadsPath.Path; options.AcceptDownloads = true; _context = await Playwright[TestConstants.Product].LaunchPersistentContextAsync(_userDataDir.Path, options); _page = _context.Pages[0]; await _page.SetContentAsync($"<a href=\"{TestConstants.ServerUrl}/download\">download</a>"); }
public async Task Setup() { // Arrange before every test var webAppUrl = TestContext.Parameters["webAppUrl"]; _enableVideo = TestContext.Parameters["enableVideo"] != null && bool.Parse(TestContext.Parameters["enableVideo"]); _enableScreenshots = TestContext.Parameters["enableScreenshot"] != null && bool.Parse(TestContext.Parameters["enableScreenshot"]); _testResults = new List <TestResult>(); var playwright = await Playwright.CreateAsync(); var chromium = playwright.Chromium; //set options _browser = await chromium.LaunchAsync(new BrowserTypeLaunchOptions { #if DEBUG Headless = false, Devtools = true, SlowMo = 1000 #endif }); _context = await _browser.NewContextAsync(new BrowserNewContextOptions { RecordVideoDir = "videos/", BaseURL = webAppUrl }); _page = await _context.NewPageAsync(); if (_enableVideo) { //a video (when enabled) is always made var videoPath = await _page.Video.PathAsync(); _testResults.Add(new TestResult { Description = "videorecording", Path = videoPath }); } }
/// <inheritdoc cref="IBrowser.GetTargets"/> public IEnumerable <ITarget> GetTargets(IBrowserContext context = null) => null;
public async Task ContextSetup() { Context = await NewContext(ContextOptions()).ConfigureAwait(false); }
/// <inheritdoc cref="IAsyncLifetime.InitializeAsync"/> public override async Task InitializeAsync() { await base.InitializeAsync(); Context = await Browser.NewContextAsync(); }
/// <inheritdoc cref="IBrowser.GetTargets(IBrowserContext)" /> public IEnumerable <ITarget> GetTargets(IBrowserContext context = null) { throw new NotImplementedException(); }
internal void Attach(IBrowserContext context) { context.Page += AttachToPage; }
public Crawler(SearchClient searchClient, IBrowser browser, IBrowserContext browserContext) { SearchClient = searchClient; Browser = browser; BrowserContext = browserContext; }
public LandingPageObject(IBrowserContext browser, IConfiguration configuration) : base(configuration) { Context = browser; }
/// <inheritdoc cref="IBrowser.GetTargets"/> public IEnumerable <ITarget> GetTargets(IBrowserContext context = null) => context == null?GetAllTargets() : GetAllTargets().Where(t => t.BrowserContext == context);
/// <inheritdoc cref="IAsyncLifetime.InitializeAsync"/> public virtual async Task InitializeAsync() { Context = await Browser.NewContextAsync(); Context.DefaultTimeout = TestConstants.DefaultPuppeteerTimeout; }
/// <inheritdoc cref="IAsyncLifetime.InitializeAsync"/> public virtual async Task InitializeAsync() { Context = await Browser.NewContextAsync(); }