public async Task <IBrowser> LaunchAsync(BrowserTypeLaunchOptions options = default)
        {
            options ??= new BrowserTypeLaunchOptions();
            Browser browser = (await _channel.LaunchAsync(
                                   headless: options.Headless,
                                   channel: options.Channel,
                                   executablePath: options.ExecutablePath,
                                   passedArguments: options.Args,
                                   proxy: options.Proxy,
                                   downloadsPath: options.DownloadsPath,
                                   tracesDir: options.TracesDir,
                                   chromiumSandbox: options.ChromiumSandbox,
                                   firefoxUserPrefs: options.FirefoxUserPrefs,
                                   handleSIGINT: options.HandleSIGINT,
                                   handleSIGTERM: options.HandleSIGTERM,
                                   handleSIGHUP: options.HandleSIGHUP,
                                   timeout: options.Timeout,
                                   env: options.Env,
                                   devtools: options.Devtools,
                                   slowMo: options.SlowMo,
                                   ignoreDefaultArgs: options.IgnoreDefaultArgs,
                                   ignoreAllDefaultArgs: options.IgnoreAllDefaultArgs).ConfigureAwait(false)).Object;

            browser.LocalUtils = Playwright.Utils;
            return(browser);
        }
 protected CocoonFunctionalityBase(bool headless)
 {
     BrowserTypeLaunchOptions = new BrowserTypeLaunchOptions
     {
         Headless = headless
     };
 }
Exemple #3
0
    public async Task InitializeAsync()
    {
        var browserOptions = new BrowserTypeLaunchOptions
        {
            Headless = false,
            SlowMo   = SlowMo
        };

        // Add support to modify BaseUrl from outside.
        string?isGitHubActions = Environment.GetEnvironmentVariable("IsGitHubActions");
        string?baseUrl         = Environment.GetEnvironmentVariable("BaseUrl");

        if (isGitHubActions == "true")
        {
            // Assume it's in GitHub actions and we want to run it fast.
            browserOptions.Headless = true;
            browserOptions.SlowMo   = null;
            baseUrl ??= "https://autoscrum.jkdev.me";
        }

        if (!string.IsNullOrWhiteSpace(baseUrl))
        {
            BaseUrl = baseUrl;
        }

        PlaywrightInstance = await Playwright.CreateAsync();

        Browser = await PlaywrightInstance.Chromium.LaunchAsync(browserOptions);

        BrowserContext = await Browser.NewContextAsync();

        Page = await BrowserContext.NewPageAsync();

        await Page.GotoAsync(BaseUrl);
    }
Exemple #4
0
        public WebDriverFixture()
        {
            playwright = Playwright.CreateAsync().Result;

            var options = new BrowserTypeLaunchOptions()
            {
                Headless = Headless,
            };

            browser = playwright.Chromium.LaunchAsync(options);
        }
Exemple #5
0
 public BrowserTypeLaunchOptions GetBrowserTypeLaunchOptions(BrowserTypeLaunchOptions browserLaunchOptions)
 {
     if (browserLaunchOptions == null)
     {
         return(GlobalBrowserOptions);
     }
     else
     {
         return(Combine(GlobalBrowserOptions, browserLaunchOptions));
     }
 }
Exemple #6
0
        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);
        }
Exemple #7
0
        private static async Task <IBrowser> BuildBrowserAsync(BotData botData)
        {
            var launchOptions = new BrowserTypeLaunchOptions()
            {
                Headless = botData.QuickBulletSettings.Browser.Headless,
                Proxy    = botData.UseProxy ? BuilPlaywrightdProxy(botData.TryGetObject <Models.Proxy>("proxy")) : null,
                SlowMo   = botData.QuickBulletSettings.Browser.SlowMo,
                Timeout  = botData.QuickBulletSettings.Browser.Timeout
            };

            return(botData.QuickBulletSettings.Browser.BrowserType switch
            {
                string value when value.Equals("chromium", StringComparison.OrdinalIgnoreCase) => await botData.Playwright.Chromium.LaunchAsync(launchOptions),
                string value when value.Equals("firefox", StringComparison.OrdinalIgnoreCase) => await botData.Playwright.Firefox.LaunchAsync(launchOptions),
                string value when value.Equals("webkit", StringComparison.OrdinalIgnoreCase) => await botData.Playwright.Webkit.LaunchAsync(launchOptions),
                _ => await botData.Playwright.Chromium.LaunchAsync(launchOptions)
            });
    public static async Task BeforeLoginScenario(IObjectContainer container)
    {
        var playwright = await Playwright.CreateAsync();

        var options = new BrowserTypeLaunchOptions();

#if DEBUG
        options.Headless = false;
        options.SlowMo   = 500;
#endif

        var browser = await playwright.Chromium.LaunchAsync(options);

        var page = await browser.NewPageAsync();

        var loginPage = new LoginPage(browser, page);

        container.RegisterInstanceAs(playwright);
        container.RegisterInstanceAs(browser);
        container.RegisterInstanceAs(loginPage);
    }
Exemple #9
0
    private static async Task <IBrowser> CreateBrowserAsync(IPlaywright playwright, string browserType)
    {
        var options = new BrowserTypeLaunchOptions();

        if (System.Diagnostics.Debugger.IsAttached)
        {
            options.Devtools = true;
            options.Headless = false;
            options.SlowMo   = 100;
        }

        string[] split = browserType.Split(':');

        browserType = split[0];

        if (split.Length > 1)
        {
            options.Channel = split[1];
        }

        return(await playwright[browserType].LaunchAsync(options));
    }
Exemple #10
0
        public async Task TestGooglePlaywright()
        {
            using var playwright = await Playwright.CreateAsync();

            bool isDebuggerAttached = System.Diagnostics.Debugger.IsAttached;
            BrowserTypeLaunchOptions launchOptions = new BrowserTypeLaunchOptions {
                Headless = !isDebuggerAttached
            };

            await using var browser = await playwright.Chromium.LaunchAsync(launchOptions);

            await using var context = await browser.NewContextAsync();

            page = await context.NewPageAsync();

            await page.GotoAsync("https://www.google.com/?gl=us&hl=en");

            var searchButtonText = await page.GetAttributeAsync("input[name='btnK']", "value");

            Assert.AreEqual("Google Search", searchButtonText);
            await TakeScreenShootAsync("google.png");
        }