public BrowserFactory(IServiceProvider provider, TestSettings settings, IPlaywright playwright, DisposableServices disposableServices)
 {
     _provider           = provider;
     _settings           = settings;
     _playwright         = playwright;
     _disposableServices = disposableServices;
 }
Esempio n. 2
0
        public async Task OneTimeSetup()
        {
            Environment.SetEnvironmentVariable("ASPNETCORE_ENVIRONMENT", "ci");
            this.playwright = await PlaywrightSharp.Playwright.CreateAsync();

#if DEBUG
            this.browser = await playwright.Chromium.LaunchAsync(headless : false);
#else
            this.browser = await playwright.Chromium.LaunchAsync();
#endif

            var getEnvVarsBuilder = new ConfigurationBuilder().AddEnvironmentVariables().Build();
            var env = getEnvVarsBuilder["ASPNETCORE_ENVIRONMENT"] ?? "Development";

            var builder = new ConfigurationBuilder()
                          .SetBasePath(TestContext.CurrentContext.TestDirectory)
                          .AddEnvironmentVariables()
                          .AddJsonFile("appsettings.json")
                          .AddJsonFile($"appsettings.{env}.json", optional: true);

            var f = builder.Build();

            baseUrl = f["BaseUrl"];
            Console.WriteLine("Base URL: " + baseUrl);
        }
        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);
        }
Esempio n. 4
0
        public async virtual Task InitializeAsync()
        {
            _host = CreateHost();
            await _host.StartAsync();

            _playright = await Playwright.CreateAsync();

            Browser = await _playright.Chromium.LaunchAsync(new BrowserTypeLaunchOptions() /*Headless = false*/ }
Esempio n. 5
0
 public void Dispose()
 {
     page = null;
     browser?.CloseAsync();
     browser = null;
     playwright?.Dispose();
     playwright = null;
 }
Esempio n. 6
0
 internal static async Task RegisterEngineWithPathAsync(IPlaywright playwright, string name, string path)
 {
     try
     {
         await playwright.Selectors.RegisterAsync(name, path : path);
     }
     catch (PlaywrightSharpException ex) when(ex.Message.Contains("has been already registered"))
     {
     }
 }
Esempio n. 7
0
 internal static async Task RegisterEngineAsync(IPlaywright playwright, string name, string script, bool?contentScript = null)
 {
     try
     {
         await playwright.Selectors.RegisterAsync(name, script, contentScript : contentScript);
     }
     catch (PlaywrightSharpException ex) when(ex.Message.Contains("has been already registered"))
     {
     }
 }
Esempio n. 8
0
        public async Task <IBrowser> GetBrowserAsync()
        {
            IPlaywright playwright = await _playwright.Value;

            Console.WriteLine("Launching chromium...");
            var browser = await playwright.Chromium.LaunchAsync(executablePath : RuntimeInformation.IsOSPlatform(OSPlatform.Linux)? "browsers/chromium-844399/chrome-linux/chrome" : null);

            Console.WriteLine("Launched");
            return(browser);
        }
Esempio n. 9
0
        public WebDriverFixture()
        {
            playwright = Playwright.CreateAsync().Result;

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

            browser = playwright.Chromium.LaunchAsync(options);
        }
Esempio n. 10
0
        public static async Task TestPlaywright(IPlaywright playwright)
        {
            await using var browser = await playwright.Chromium.LaunchAsync();

            var page = await browser.NewPageAsync();

            await page.GotoAsync("https://playwright.dev/dotnet");

            var name = await page.QuerySelectorAsync("h1");

            returnName = name.InnerTextAsync().ToString();
        }
Esempio n. 11
0
        public Tests(ITestOutputHelper outputHelper)
        {
            outputHelper.WriteLine("Setting up browser drivers. This might take awhile");
            Playwright.InstallAsync().GetAwaiter().GetResult();
            Environment.SetEnvironmentVariable("PWDEBUG", "1");
            Environment.SetEnvironmentVariable("DEBUG", "pw:api");

            playwright = Playwright.CreateAsync().GetAwaiter().GetResult();

            outputHelper.WriteLine("Finished setting up browser drivers");
            this.outputHelper = outputHelper;
        }
Esempio n. 12
0
        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());
        }
Esempio n. 13
0
        public static async Task Main(string[] args)
        {
            using IPlaywright playwright = await Playwright.CreateAsync();

            await using IBrowser browser = await playwright.Chromium.LaunchAsync
                                           (
                            new BrowserTypeLaunchOptions { Headless = false, SlowMo = 50, }
                                           );

            IPage page = await browser.NewPageAsync();

            await page.GotoAsync("https://playwright.dev/dotnet");

            await page.ScreenshotAsync(new PageScreenshotOptions { Path = "screenshot.png" });
        }
Esempio n. 14
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);
        }
Esempio n. 15
0
        internal PlaywrightSharpBaseTest(ITestOutputHelper output)
        {
            TestConstants.SetupLogging(output);

            BaseDirectory = Path.Combine(Directory.GetCurrentDirectory(), "workspace");
            var dirInfo = new DirectoryInfo(BaseDirectory);

            if (!dirInfo.Exists)
            {
                dirInfo.Create();
            }

            _playwright = PlaywrightSharp.Playwright.CreateAsync().GetAwaiter().GetResult();
            BrowserType = _playwright[TestConstants.Product];
            Initialize();
        }
        protected override async Task BeforeExecutionAsync(IExecutionContext context)
        {
            var builder = WebApplication.CreateBuilder();

            builder.Logging.ClearProviders();
            builder.Services
            .AddRazorPages()
            .WithRazorPagesRoot("/Statiq.Helpers");

            _app = builder.Build();
            _app.MapRazorPages();
            await _app.StartAsync();

            _playwright = await Playwright.CreateAsync();

            _browser = await _playwright.Chromium.LaunchAsync();

            await base.BeforeExecutionAsync(context);
        }
Esempio n. 17
0
 public BotData(QuickBulletSettings quickBulletSettings, BotInput input, HttpClient httpClient, HttpClient proxyHttpClient, IPlaywright playwright)
 {
     QuickBulletSettings = quickBulletSettings;
     Input           = input;
     HttpClient      = httpClient;
     ProxyHttpClient = proxyHttpClient;
     Playwright      = playwright;
     Headers         = Array.Empty <KeyValuePair <string, string> >();
     CookieContainer = new CookieContainer();
     Variables       = new Dictionary <string, string>(StringComparer.OrdinalIgnoreCase)
     {
         { "botStatus", "none" },
         { "input", input.ToString() },
         { "input.user", input.Combo.Username },
         { "input.pass", input.Combo.Password },
         { "input.username", input.Combo.Username },
         { "input.password", input.Combo.Password }
     };
     Captures = new Dictionary <string, string>(StringComparer.OrdinalIgnoreCase);
     _objects = new Dictionary <string, object>();
 }
Esempio n. 18
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));
    }
 private async Task SetupBrowserAsync()
 {
     Playwright = await PlaywrightSharp.Playwright.CreateAsync();
 }
 /// <inheritdoc />
 public virtual void Dispose()
 {
     Playwright.Dispose();
     Playwright = null;
 }