public void CreateLocalWebDriver_ShouldCreateLocalBrowserBasedOnBrowserType() { // Arrange var sut = Substitute.ForPartsOf <BrowserHostFactory>(_configurationProvider); var browserHost = Substitute.For <IBrowserHost>(); var capabilities = Substitute.For <ICapabilities>(); var browserConfiguration = new BrowserConfiguration(); Func <RemoteWebDriver> remoteWebDriverFactory = () => new RemoteWebDriver(capabilities); const string remoteUrl = "http://some/remote/url"; var webServer = Substitute.For <IWebServer>(); var browserType = BrowserEnum.Chrome; _configurationProvider.RemoteUrl.Returns(remoteUrl); browserHost.Configuration.Returns(browserConfiguration); sut.When(x => x.CreateBrowserHost(browserConfiguration)).DoNotCallBase(); sut.CreateBrowserHost(browserConfiguration).Returns(browserHost); sut.LocalWebBrowser(browserType).Returns(remoteWebDriverFactory); sut.CreateInternetWebServer(Arg.Is(remoteUrl)).Returns(webServer); // Act var result = sut.CreateLocalWebDriver(browserType, browserConfiguration); // Assert browserConfiguration.IsLocalWebDriver.Should().BeTrue(); browserHost.Should().BeSameAs(result); browserHost.Received().Run(remoteWebDriverFactory, webServer); }
public void CreateWithCapabilities_ShouldCreateAndRunBrowserHostWithCapabilitiesAndWebServer() { // Arrange var sut = Substitute.ForPartsOf <BrowserHostFactory>(_configurationProvider); var browserHost = Substitute.For <IBrowserHost>(); var capabilities = Substitute.For <ICapabilities>(); var browserConfiguration = new BrowserConfiguration(); Func <RemoteWebDriver> remoteWebDriverFactory = () => new RemoteWebDriver(capabilities); var webServer = Substitute.For <IWebServer>(); const string remoteUrl = "http://some/remote/url"; _configurationProvider.RemoteUrl.Returns(remoteUrl); sut.When(x => x.CreateBrowserHost(browserConfiguration)).DoNotCallBase(); sut.CreateBrowserHost(browserConfiguration).Returns(browserHost); sut.CreateRemoteDriverWithCapabilities(Arg.Is(capabilities)).Returns(remoteWebDriverFactory); sut.CreateInternetWebServer(Arg.Is(remoteUrl)).Returns(webServer); // Act var result = sut.CreateWithCapabilities(capabilities, browserConfiguration); // Assert result.Should().BeSameAs(browserHost); browserHost.Received().Run(remoteWebDriverFactory, webServer); }
private BrowserConfiguration GetCurrentBrowserConfiguration(MemberInfo memberInfo, Type testClassType, ServicesCollection container) { var browserAttribute = GetBrowserAttribute(memberInfo, testClassType); if (browserAttribute != null) { BrowserType currentBrowserType = browserAttribute.Browser; Lifecycle currentBrowserBehavior = browserAttribute.Lifecycle; bool shouldCaptureHttpTraffic = browserAttribute.ShouldCaptureHttpTraffic; Size currentBrowserSize = browserAttribute.Size; string classFullName = testClassType.FullName; ExecutionType executionType = browserAttribute.ExecutionType; bool shouldAutomaticallyScrollToVisible = browserAttribute.ShouldAutomaticallyScrollToVisible; var options = (browserAttribute as IDriverOptionsAttribute)?.CreateOptions(memberInfo, testClassType); var browserConfiguration = new BrowserConfiguration(executionType, currentBrowserBehavior, currentBrowserType, currentBrowserSize, classFullName, shouldCaptureHttpTraffic, shouldAutomaticallyScrollToVisible, options); container.RegisterInstance(browserConfiguration, "_currentBrowserConfiguration"); return(browserConfiguration); } else { container.RegisterInstance(default(BrowserConfiguration), "_currentBrowserConfiguration"); return(null); } }
private BrowserConfiguration GetBrowserConfiguration(MemberInfo memberInfo) { var classBrowser = GetExecutionBrowserClassLevel(memberInfo.DeclaringType); var methodBrowser = GetExecutionBrowserMethodLevel(memberInfo); BrowserConfiguration browserConfiguration = methodBrowser != null ? methodBrowser : classBrowser; return(browserConfiguration); }
public void IsMobileDevice_ShouldReturnTrueWhenDeviceNotIsNullOrEmptyOrWhiteSpace(string device) { // Arrange const string anyBrowserName = "chrome"; var sut = new BrowserConfiguration(anyBrowserName, device); // Act && Assert sut.IsMobileDevice.Should().BeTrue(); }
public BrowserWorkflowPlugin() { _currentBrowserConfiguration = new BrowserConfiguration(); _sauceLabsBrowserConfiguration = new SauceLabsBrowserConfiguration(); _gridBrowserConfiguration = new GridBrowserConfiguration(); _crossBrowserTestingBrowserConfiguration = new CrossBrowserTestingBrowserConfiguration(); _browserStackBrowserConfiguration = new BrowserStackBrowserConfiguration(); _currentPlatform = DetermineOS(); }
private void ResolvePreviousBrowserType() { var browserConfiguration = new BrowserConfiguration(BrowserType.NotSet, false, false); if (ServicesCollection.Current.IsRegistered <BrowserConfiguration>()) { browserConfiguration = ServicesCollection.Current.Resolve <BrowserConfiguration>(); } _previousBrowserConfiguration = browserConfiguration; }
public void ConfigurationChanged(BrowserConfiguration conf) { Configuration = conf; SizeAdjuster.AutoScroll = Configuration.IsScrollable; ToolMenu_Other_Zoom_Fit.Checked = Configuration.ZoomFit; ApplyZoom(); ToolMenu_Other_AppliesStyleSheet.Checked = Configuration.AppliesStyleSheet; ToolMenu.Dock = (DockStyle)Configuration.ToolMenuDockStyle; ToolMenu.Visible = Configuration.IsToolMenuVisible; }
private void ResolvePreviousBrowserType(ServicesCollection container) { bool shouldScrollToVisible = ConfigurationService.GetSection <WebSettings>().ShouldAutomaticallyScrollToVisible; var browserConfiguration = new BrowserConfiguration(BrowserType.NotSet, false, shouldScrollToVisible); if (container.IsRegistered <BrowserConfiguration>()) { browserConfiguration = container.Resolve <BrowserConfiguration>(); } container.RegisterInstance(browserConfiguration, "_previousBrowserConfiguration"); }
public override void PreTestInit(MemberInfo memberInfo) { _currentBrowserConfiguration = GetBrowserConfiguration(memberInfo); bool shouldRestartBrowser = ShouldRestartBrowser(_currentBrowserConfiguration); if (shouldRestartBrowser) { RestartBrowser(); } _previousBrowserConfiguration = _currentBrowserConfiguration; }
private void ShutdownBrowser(ServicesCollection container) { // Disposing existing engine call only dispose if in parallel. var previousTestExecutionEngine = container.Resolve <TestExecutionEngine>(); previousTestExecutionEngine?.DisposeAll(); bool shouldScrollToVisible = ConfigurationService.GetSection <WebSettings>().ShouldAutomaticallyScrollToVisible; var browserConfiguration = new BrowserConfiguration(BrowserType.NotSet, false, shouldScrollToVisible); container.RegisterInstance(browserConfiguration, "_previousBrowserConfiguration"); container.UnregisterSingleInstance <TestExecutionEngine>(); }
private bool ShouldRestartBrowser(BrowserConfiguration browserConfiguration) { if (_previousBrowserConfiguration == null) { return(true); } bool shouldRestartBrowser = browserConfiguration.BrowserBehavior == BrowserBehavior.RestartEveryTime || browserConfiguration.BrowserBehavior == BrowserBehavior.RestartOnFail; return(shouldRestartBrowser); }
private void StartBrowserRegularMode(BrowserConfiguration browserConfiguration) { IWebDriver driver = default; switch (browserConfiguration.Browser) { case Browser.Chrome: driver = new ChromeDriver(Environment.CurrentDirectory); driver.Manage().Timeouts().PageLoad = TimeSpan.FromSeconds(ConfigurationService.GetSection <WebSettings>().Chrome.PageLoadTimeout); driver.Manage().Timeouts().AsynchronousJavaScript = TimeSpan.FromSeconds(ConfigurationService.GetSection <WebSettings>().Chrome.ScriptTimeout); driver.Manage().Window.Maximize(); break; case Browser.ChromeHeadless: var options = ServiceContainer.Resolve <ChromeOptions>("testClassFullName"); options.AddArgument("--headless"); options.AddArgument("--log-level=3"); driver = new ChromeDriver(Environment.CurrentDirectory, options); ////driver = new ChromeDriver(Environment.CurrentDirectory); driver.Manage().Timeouts().PageLoad = TimeSpan.FromSeconds(ConfigurationService.GetSection <WebSettings>().Chrome.PageLoadTimeout); driver.Manage().Timeouts().AsynchronousJavaScript = TimeSpan.FromSeconds(ConfigurationService.GetSection <WebSettings>().Chrome.ScriptTimeout); driver.Manage().Window.Maximize(); break; case Browser.Firefox: driver = new FirefoxDriver(Environment.CurrentDirectory); driver.Manage().Timeouts().PageLoad = TimeSpan.FromSeconds(ConfigurationService.GetSection <WebSettings>().FireFox.PageLoadTimeout); driver.Manage().Timeouts().AsynchronousJavaScript = TimeSpan.FromSeconds(ConfigurationService.GetSection <WebSettings>().FireFox.ScriptTimeout); driver.Manage().Window.Maximize(); break; case Browser.Edge: driver = new EdgeDriver(Environment.CurrentDirectory); driver.Manage().Timeouts().PageLoad = TimeSpan.FromSeconds(ConfigurationService.GetSection <WebSettings>().Edge.PageLoadTimeout); driver.Manage().Timeouts().AsynchronousJavaScript = TimeSpan.FromSeconds(ConfigurationService.GetSection <WebSettings>().Edge.ScriptTimeout); driver.Manage().Window.Maximize(); break; case Browser.Safari: driver = new SafariDriver(Environment.CurrentDirectory); driver.Manage().Timeouts().PageLoad = TimeSpan.FromSeconds(ConfigurationService.GetSection <WebSettings>().Safari.PageLoadTimeout); driver.Manage().Timeouts().AsynchronousJavaScript = TimeSpan.FromSeconds(ConfigurationService.GetSection <WebSettings>().Safari.ScriptTimeout); driver.Manage().Window.Maximize(); break; default: throw new ArgumentOutOfRangeException(nameof(browserConfiguration.Browser), browserConfiguration.BrowserBehavior.ToString()); } ServiceContainer.RegisterInstance(driver); }
public bool IsNotSupported(BrowserConfiguration browserConfiguration) { using (var client = _clientFactory.Create(_configurationProvider.BrowserStackApiUrl)) { var response = client.GetAsync("browsers.json").Result; if (response.IsSuccessStatusCode) { var supportedBrowsers = response .Content .ReadAsAsync <List <BrowserConfiguration> >(client.GetFormatters()).Result; return(!supportedBrowsers.Exists(b => Equals(b, browserConfiguration))); } } return(true); }
public void Parse_ShouldThrowUnsupportedBrowserConfigurationExceptionWhenBrowserStackServiceIsSupportedReturnsFalse() { // Arrange BrowserConfiguration browserConfiguration = null; _browserStackService.IsNotSupported(Arg.Do <BrowserConfiguration>(x => browserConfiguration = x)).Returns(true); Action attemptToParseUnSupportedBrowserConfiguration = () => _sut.Parse("unknown,some device"); //Assert var exception = attemptToParseUnSupportedBrowserConfiguration .ShouldThrow <UnsupportedBrowserException>() .WithMessage("some device is not supported").Which; exception.Browser.Should().BeSameAs(browserConfiguration); }
public void IsNotSupported_ShouldReturnTrueWhenServiceResponseIsNotOk(HttpStatusCode httpStatusCode) { // Arrange const string baseAddress = "http://some/address"; var client = Substitute.For <IHttpClient>(); var anyBrowserConfiguration = new BrowserConfiguration(); _clientFactory.Create(baseAddress).Returns(client); _configurationProvider.BrowserStackApiUrl.Returns(baseAddress); client .GetAsync("browsers.json") .Returns(Task.FromResult(new HttpResponseMessage(httpStatusCode))); // Act var result = _sut.IsNotSupported(anyBrowserConfiguration); // Assert result.Should().BeTrue(); }
public ConsultaVeiculoDFService(IConfiguration configuration, Browser browser, bool remote = true) { _configuration = configuration; var browserConfiguration = new BrowserConfiguration(_configuration, browser); if (!remote) { var driverBrowser = browserConfiguration.DriverBrowser(); _webDriver = WebDriverFactory.CreateWebDriver(browser, driverBrowser); } else { var remoteBrowser = browserConfiguration.RemoteBrowser(); remoteBrowser.SetCapability("acceptSslCerts", true); _webDriver = new RemoteWebDriver(new Uri("http://localhost:4444/wd/hub"), remoteBrowser); } }
public void Start(BrowserConfiguration browserConfiguration) { _disposed = false; switch (browserConfiguration.ExecutionType) { case ExecutionType.Regular: StartBrowserRegularMode(browserConfiguration); break; case ExecutionType.Grid: break; case ExecutionType.SauceLabs: break; case ExecutionType.BrowserStack: break; case ExecutionType.CrossBrowserTesting: break; } }
public DashmanBrowser(BrowserConfiguration configuration) { _configuration = configuration; InitializeComponent(); }
private BrowserConfiguration GetCurrentBrowserConfiguration(MemberInfo memberInfo, Type testClassType, ServicesCollection container, List <object> arguments) { var browserAttribute = GetBrowserAttribute(memberInfo, testClassType); string fullClassName = testClassType.FullName; if (browserAttribute != null) { BrowserType currentBrowserType = browserAttribute.Browser; Lifecycle currentLifecycle = browserAttribute.Lifecycle; bool shouldCaptureHttpTraffic = browserAttribute.ShouldCaptureHttpTraffic; bool shouldAutomaticallyScrollToVisible = browserAttribute.ShouldAutomaticallyScrollToVisible; Size currentBrowserSize = browserAttribute.Size; ExecutionType executionType = browserAttribute.ExecutionType; var options = (browserAttribute as IDriverOptionsAttribute)?.CreateOptions(memberInfo, testClassType) ?? GetDriverOptionsBasedOnBrowser(currentBrowserType, testClassType); InitializeCustomCodeOptions(options, testClassType); var browserConfiguration = new BrowserConfiguration(executionType, currentLifecycle, currentBrowserType, currentBrowserSize, fullClassName, shouldCaptureHttpTraffic, shouldAutomaticallyScrollToVisible, options); container.RegisterInstance(browserConfiguration, "_currentBrowserConfiguration"); return(browserConfiguration); } else { BrowserType currentBrowserType = Parse <BrowserType>(ConfigurationService.GetSection <WebSettings>().ExecutionSettings.DefaultBrowser); if (arguments != null & arguments.Any()) { if (arguments[0] is BrowserType) { currentBrowserType = (BrowserType)arguments[0]; } } Lifecycle currentLifecycle = Parse <Lifecycle>(ConfigurationService.GetSection <WebSettings>().ExecutionSettings.DefaultLifeCycle); Size currentBrowserSize = default; if (!string.IsNullOrEmpty(ConfigurationService.GetSection <WebSettings>().ExecutionSettings.Resolution)) { currentBrowserSize = WindowsSizeResolver.GetWindowSize(ConfigurationService.GetSection <WebSettings>().ExecutionSettings.Resolution); } ExecutionType executionType = ConfigurationService.GetSection <WebSettings>().ExecutionSettings.ExecutionType.ToLower() == "regular" ? ExecutionType.Regular : ExecutionType.Grid; bool shouldCaptureHttpTraffic = ConfigurationService.GetSection <WebSettings>().ShouldCaptureHttpTraffic; bool shouldAutomaticallyScrollToVisible = ConfigurationService.GetSection <WebSettings>().ShouldAutomaticallyScrollToVisible; var options = GetDriverOptionsBasedOnBrowser(currentBrowserType, testClassType); if (!string.IsNullOrEmpty(ConfigurationService.GetSection <WebSettings>().ExecutionSettings.BrowserVersion)) { options.BrowserVersion = ConfigurationService.GetSection <WebSettings>().ExecutionSettings.BrowserVersion; } if (arguments != null & arguments.Count >= 2) { if (arguments[0] is BrowserType && arguments[1] is int) { options.BrowserVersion = arguments[1].ToString(); } } InitializeGridOptionsFromConfiguration(options, testClassType); InitializeCustomCodeOptions(options, testClassType); var browserConfiguration = new BrowserConfiguration(executionType, currentLifecycle, currentBrowserType, currentBrowserSize, fullClassName, shouldCaptureHttpTraffic, shouldAutomaticallyScrollToVisible, options); container.RegisterInstance(browserConfiguration, "_currentBrowserConfiguration"); return(browserConfiguration); } }
private BrowserConfiguration GetCurrentBrowserConfiguration(Bellatrix.Plugins.PluginEventArgs e) { var browserAttribute = GetBrowserAttribute(e.TestMethodMemberInfo, e.TestClassType); string fullClassName = e.TestClassType.FullName; if (browserAttribute != null) { BrowserType currentBrowserType = browserAttribute.Browser; Lifecycle currentLifecycle = browserAttribute.Lifecycle; bool shouldCaptureHttpTraffic = browserAttribute.ShouldCaptureHttpTraffic; bool shouldAutomaticallyScrollToVisible = browserAttribute.ShouldAutomaticallyScrollToVisible; Size currentBrowserSize = browserAttribute.Size; ExecutionType executionType = browserAttribute.ExecutionType; var options = (browserAttribute as IDriverOptionsAttribute)?.CreateOptions(e.TestMethodMemberInfo, e.TestClassType) ?? GetDriverOptionsBasedOnBrowser(currentBrowserType, e.TestClassType); InitializeCustomCodeOptions(options, e.TestClassType); var browserConfiguration = new BrowserConfiguration(executionType, currentLifecycle, currentBrowserType, currentBrowserSize, fullClassName, shouldCaptureHttpTraffic, shouldAutomaticallyScrollToVisible, options); e.Container.RegisterInstance(browserConfiguration, "_currentBrowserConfiguration"); return(browserConfiguration); } else { BrowserType currentBrowserType = Parse <BrowserType>(ConfigurationService.GetSection <WebSettings>().ExecutionSettings.DefaultBrowser); if (e.Arguments != null & e.Arguments.Any()) { if (e.Arguments[0] is BrowserType) { currentBrowserType = (BrowserType)e.Arguments[0]; } } Lifecycle currentLifecycle = Parse <Lifecycle>(ConfigurationService.GetSection <WebSettings>().ExecutionSettings.DefaultLifeCycle); Size currentBrowserSize = default; if (!string.IsNullOrEmpty(ConfigurationService.GetSection <WebSettings>().ExecutionSettings.Resolution)) { currentBrowserSize = WindowsSizeResolver.GetWindowSize(ConfigurationService.GetSection <WebSettings>().ExecutionSettings.Resolution); } ExecutionType executionType = ConfigurationService.GetSection <WebSettings>().ExecutionSettings.ExecutionType.ToLower() == "regular" ? ExecutionType.Regular : ExecutionType.Grid; bool shouldCaptureHttpTraffic = ConfigurationService.GetSection <WebSettings>().ShouldCaptureHttpTraffic; bool shouldAutomaticallyScrollToVisible = ConfigurationService.GetSection <WebSettings>().ShouldAutomaticallyScrollToVisible; var options = GetDriverOptionsBasedOnBrowser(currentBrowserType, e.TestClassType); if (!string.IsNullOrEmpty(ConfigurationService.GetSection <WebSettings>().ExecutionSettings.BrowserVersion)) { options.BrowserVersion = ConfigurationService.GetSection <WebSettings>().ExecutionSettings.BrowserVersion; } if (e.Arguments != null & e.Arguments.Count >= 2) { if (e.Arguments[0] is BrowserType && e.Arguments[1] is int) { options.BrowserVersion = e.Arguments[1].ToString(); } } string testName = e.TestFullName != null?e.TestFullName.Replace(" ", string.Empty).Replace("(", string.Empty).Replace(")", string.Empty).Replace(",", string.Empty).Replace("\"", string.Empty) : e.TestClassType.FullName; InitializeGridOptionsFromConfiguration(options, e.TestClassType, testName); InitializeCustomCodeOptions(options, e.TestClassType); var browserConfiguration = new BrowserConfiguration(executionType, currentLifecycle, currentBrowserType, currentBrowserSize, fullClassName, shouldCaptureHttpTraffic, shouldAutomaticallyScrollToVisible, options); e.Container.RegisterInstance(browserConfiguration, "_currentBrowserConfiguration"); return(browserConfiguration); } }
public ExecutionBrowserAttribute(BrowserConfiguration browserConfiguration) { BrowserConfiguration = browserConfiguration; }
public ICapabilitiesBuilder WithBrowserConfiguration(BrowserConfiguration browserConfiguration) { _browserConfiguration = browserConfiguration; return(this); }
public ExecutionBrowserAttribute(Web.Browser browser, BrowserBehavior browserBehavior) { BrowserConfiguration = new BrowserConfiguration(browser, browserBehavior); ////BrowserConfiguration.Browser = browser; ////BrowserConfiguration.BrowserBehavior = browserBehavior; }
public UnsupportedBrowserException(BrowserConfiguration browser) : base(string.Format("{0} is not supported", browser)) { Browser = browser; }
public void SetUp() { _selenoHost = new SelenoHost(); _browserConfiguration = new BrowserConfiguration(); _sut = Substitute.ForPartsOf <BrowserHost>(_selenoHost, _browserConfiguration); }
public void ConfigurationChanged(BrowserConfiguration conf) { throw new NotImplementedException(); }
public void IsNotSupported_ShouldReturnTrueWhenBrowserConfigurationCouldNotBeFound(BrowserConfiguration unsupportedBrowserConfiguration) { // Arrange const string baseAddress = "http://some/address"; var client = Substitute.For <IHttpClient>(); _clientFactory.Create(baseAddress).Returns(client); _configurationProvider.BrowserStackApiUrl.Returns(baseAddress); client .GetAsync("browsers.json") .Returns(Task.FromResult(new HttpResponseMessage(HttpStatusCode.OK) { Content = SupportedBrowsersContent })); // Act var result = _sut.IsNotSupported(unsupportedBrowserConfiguration); // Assert result.Should().BeTrue(); }