public async Task PlaywrightSetup() { Playwright = await _playwrightTask.ConfigureAwait(false); BrowserType = Playwright[BrowserName]; Assert.IsNotNull(BrowserType, $"The requested browser ({BrowserName}) could not be found - make sure your BROWSER env variable is set correctly."); }
public static Task <BrowserService> Register(WorkerAwareTest test, IBrowserType browserType) { return(test.RegisterService("Browser", async() => new BrowserService { Browser = await browserType.LaunchAsync(new() { Headless = Environment.GetEnvironmentVariable("HEADED") != "1" }).ConfigureAwait(false) }));
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 )); }
internal PlaywrightSharpBaseTest(ITestOutputHelper output) { TestConstants.SetupLogging(output); BaseDirectory = Path.Combine(Directory.GetCurrentDirectory(), "workspace"); var dirInfo = new DirectoryInfo(BaseDirectory); if (!dirInfo.Exists) { dirInfo.Create(); } Playwright = TestConstants.GetNewBrowserType(); Initialize(); }
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 )); }
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(); }
public string GetBrowserUrl(IBrowserType browserType) { if (browserType.Process == null) { throw new ArgumentNullException("Browser process not found: " + nameof(browserType.BrowserAttributes.BrowserName)); } //Skip not active tabs if (browserType.Process.MainWindowHandle == IntPtr.Zero) { throw new ArgumentNullException("Browser is not active right now: " + nameof(browserType.BrowserAttributes.BrowserName)); } var element = AutomationElement.FromHandle(browserType.Process.MainWindowHandle); var controls = element?.FindAll(TreeScope.Subtree, new OrCondition(new PropertyCondition(AutomationElement.NameProperty, browserType.BrowserAttributes.SearchPattern, PropertyConditionFlags.IgnoreCase), new PropertyCondition(AutomationElement.NameProperty, browserType.BrowserAttributes.SearchClass))); if (controls != null && controls.Count > 0) { for (var i = 0; i < controls.Count; i++) { var edit = controls[i]; if ((edit.Current.Name.Equals(browserType.BrowserAttributes.SearchPattern, StringComparison.CurrentCultureIgnoreCase) || edit.Current.Name.Equals(browserType.BrowserAttributes.SearchClass, StringComparison.CurrentCultureIgnoreCase)) && (Equals(edit.Current.ControlType, ControlType.Edit) || Equals(edit.Current.ControlType, ControlType.Pane) || Equals(edit.Current.ControlType, ControlType.Text))) { object valuePattern; edit.TryGetCurrentPattern(ValuePattern.Pattern, out valuePattern); var value = ((ValuePattern)valuePattern)?.Current.Value; if (!string.IsNullOrEmpty(value)) { return(value); } } } } return(null); }