private bool ShouldRestartApp(ServicesCollection container) { bool shouldRestartApp = false; var previousTestExecutionEngine = container.Resolve <TestExecutionEngine>(); var previousAppConfiguration = container.Resolve <AppConfiguration>("_previousAppConfiguration"); var currentAppConfiguration = container.Resolve <AppConfiguration>("_currentAppConfiguration"); if (previousTestExecutionEngine == null || !previousTestExecutionEngine.IsAppStartedCorrectly || !currentAppConfiguration.Equals(previousAppConfiguration)) { shouldRestartApp = true; } return(shouldRestartApp); }
public static void CloseAndroidApp(ServicesCollection childContainer) { var androidDriver = childContainer.Resolve <AndroidDriver <AndroidElement> >(); androidDriver?.ResetApp(); androidDriver?.CloseApp(); }
public string TakeScreenshotVanillaWebDriver(ServicesCollection serviceContainer) { var driver = serviceContainer.Resolve <WindowsDriver <WindowsElement> >(); Screenshot screenshot = ((ITakesScreenshot)driver).GetScreenshot(); return(screenshot.AsBase64EncodedString); }
public string TakeScreenshotIOSDriver(ServicesCollection serviceContainer) { var driver = serviceContainer.Resolve <IOSDriver <IOSElement> >(); var screenshot = ((ITakesScreenshot)driver).GetScreenshot(); return(screenshot.AsBase64EncodedString); }
public string TakeScreenshotHtml2Canvas(ServicesCollection serviceContainer) { var html2CanvasContent = GetEmbeddedResource("html2canvas.js", Assembly.GetExecutingAssembly()); var javaScriptService = serviceContainer.Resolve <JavaScriptService>(); var wait = new WebDriverWait(javaScriptService.WrappedDriver, TimeSpan.FromSeconds(60)); wait.IgnoreExceptionTypes(typeof(InvalidOperationException)); wait.IgnoreExceptionTypes(typeof(ArgumentNullException)); javaScriptService.Execute(html2CanvasContent); javaScriptService.Execute(GenerateScreenshotJavaScript); wait.Until( wd => { string response = (string)javaScriptService.Execute("return (typeof canvasImgContentDecoded === 'undefined' || canvasImgContentDecoded === null)"); if (string.IsNullOrEmpty(response)) { return(false); } return(bool.Parse(response)); }); wait.Until(wd => !string.IsNullOrEmpty((string)javaScriptService.Execute("return canvasImgContentDecoded;"))); var pngContent = (string)javaScriptService.Execute("return canvasImgContentDecoded;"); pngContent = pngContent.Replace("data:image/png;base64,", string.Empty); return(pngContent); }
public string TakeScreenshotAndroidDriver(ServicesCollection container) { var driver = container.Resolve <AndroidDriver <AndroidElement> >(); Screenshot screenshot = ((ITakesScreenshot)driver).GetScreenshot(); return(screenshot.AsBase64EncodedString); }
public static void DisposeIOS(ServicesCollection childContainer) { var iosDriver = childContainer.Resolve <IOSDriver <IOSElement> >(); iosDriver?.CloseApp(); iosDriver?.Quit(); childContainer.UnregisterSingleInstance <IOSDriver <IOSElement> >(); }
private void ShutdownBrowser(ServicesCollection container) { // Disposing existing engine call only dispose if in parallel. var previousTestExecutionEngine = container.Resolve <TestExecutionEngine>(); previousTestExecutionEngine?.Dispose(container); container.UnregisterSingleInstance <TestExecutionEngine>(); }
public static void DisposeAndroid(ServicesCollection childContainer) { var androidDriver = childContainer.Resolve <AndroidDriver <AndroidElement> >(); androidDriver?.CloseApp(); androidDriver?.Quit(); androidDriver?.Dispose(); childContainer.UnregisterSingleInstance <AndroidDriver <AndroidElement> >(); }
public static void Dispose(ServicesCollection childContainer) { var webDriver = childContainer.Resolve <WindowsDriver <WindowsElement> >(); webDriver?.Quit(); webDriver?.Dispose(); childContainer.UnregisterSingleInstance <WindowsDriver <WindowsElement> >(); ServicesCollection.Main.UnregisterSingleInstance <WindowsDriver <WindowsElement> >(); }
private void ShutdownApp(ServicesCollection container) { DisposeDriverService.DisposeAndroid(container); DisposeDriverService.DisposeIOS(container); var currentAppConfiguration = container.Resolve <AppConfiguration>("_currentAppConfiguration"); container.RegisterInstance(currentAppConfiguration, "_previousAppConfiguration"); }
private bool ShouldRestartBrowser(ServicesCollection container) { if (ConfigurationService.GetSection <WebSettings>().ExecutionSettings.IsCloudRun) { return(true); } bool shouldRestartBrowser = false; var previousTestExecutionEngine = container.Resolve <TestExecutionEngine>(); var previousBrowserConfiguration = container.Resolve <BrowserConfiguration>("_previousBrowserConfiguration"); var currentBrowserConfiguration = container.Resolve <BrowserConfiguration>("_currentBrowserConfiguration"); if (previousTestExecutionEngine == null || !previousTestExecutionEngine.IsBrowserStartedCorrectly || !currentBrowserConfiguration.Equals(previousBrowserConfiguration)) { shouldRestartBrowser = true; } return(shouldRestartBrowser); }
public static AndroidDriver <AndroidElement> CreateAndroidDriver(AppConfiguration appConfiguration, ServicesCollection childContainer) { var driverOptions = childContainer.Resolve <AppiumOptions>(appConfiguration.ClassFullName) ?? appConfiguration.AppiumOptions; driverOptions = driverOptions ?? new AppiumOptions(); AddAdditionalOptions(driverOptions, MobileCapabilityType.App, appConfiguration.AppPath); AddAdditionalOptions(driverOptions, MobileCapabilityType.DeviceName, appConfiguration.DeviceName); AddAdditionalOptions(driverOptions, MobileCapabilityType.PlatformName, appConfiguration.PlatformName); AddAdditionalOptions(driverOptions, MobileCapabilityType.PlatformVersion, appConfiguration.PlatformVersion); if (string.IsNullOrEmpty(appConfiguration.BrowserName)) { AddAdditionalOptions(driverOptions, AndroidMobileCapabilityType.AppPackage, appConfiguration.AppPackage); AddAdditionalOptions(driverOptions, AndroidMobileCapabilityType.AppActivity, appConfiguration.AppActivity); } else { AddAdditionalOptions(driverOptions, MobileCapabilityType.BrowserName, appConfiguration.BrowserName); } var wrappedWebDriver = default(AndroidDriver <AndroidElement>); if (_shouldStartAppiumLocalService) { if (AppiumLocalService == null) { throw new ArgumentException("The Appium local service is not started. You need to call App?.StartAppiumLocalService() in AssemblyInitialize method."); } wrappedWebDriver = new AndroidDriver <AndroidElement>(AppiumLocalService, driverOptions); } else { wrappedWebDriver = new AndroidDriver <AndroidElement>(new Uri(_appiumServiceUrl), driverOptions); } wrappedWebDriver.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(ConfigurationService.GetSection <MobileSettings>().TimeoutSettings.ImplicitWaitTimeout); childContainer.RegisterInstance <IWebDriver>(wrappedWebDriver); childContainer.RegisterInstance(childContainer.Resolve <BrowserService>()); childContainer.RegisterInstance(childContainer.Resolve <CookiesService>()); childContainer.RegisterInstance(childContainer.Resolve <DialogService>()); childContainer.RegisterInstance(childContainer.Resolve <JavaScriptService>()); childContainer.RegisterInstance(childContainer.Resolve <NavigationService>()); childContainer.RegisterInstance(childContainer.Resolve <ComponentCreateService>()); var webDriver = childContainer.Resolve <IWebDriver>(); childContainer.RegisterInstance <IWebDriverElementFinderService>(new NativeElementFinderService(webDriver)); childContainer.RegisterNull <int?>(); childContainer.RegisterNull <IWebElement>(); return(wrappedWebDriver); }
private bool ShouldRestartApp(ServicesCollection container) { if (ConfigurationService.GetSection <MobileSettings>().ExecutionSettings.IsCloudRun) { return(true); } bool shouldRestartApp = false; var previousTestExecutionEngine = container.Resolve <TestExecutionEngine>(); var previousAppConfiguration = container.Resolve <AppConfiguration>("_previousAppConfiguration"); var currentAppConfiguration = container.Resolve <AppConfiguration>("_currentAppConfiguration"); if (currentAppConfiguration?.Lifecycle == Lifecycle.RestartEveryTime || previousTestExecutionEngine == null || !previousTestExecutionEngine.IsAppStartedCorrectly || !currentAppConfiguration.Equals(previousAppConfiguration)) { shouldRestartApp = true; } return(shouldRestartApp); }
private void ResolvePreviousAppConfiguration(ServicesCollection childContainer) { var appConfiguration = new AppConfiguration(); if (childContainer.IsRegistered <AppConfiguration>()) { appConfiguration = childContainer.Resolve <AppConfiguration>(); } childContainer.RegisterInstance(appConfiguration, "_previousAppConfiguration"); }
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 static AndroidDriver <AndroidElement> CreateAndroidDriver(AppConfiguration appConfiguration, ServicesCollection childContainer) { var driverOptions = childContainer.Resolve <AppiumOptions>(appConfiguration.ClassFullName) ?? appConfiguration.AppiumOptions; driverOptions = driverOptions ?? new AppiumOptions(); driverOptions.AddAdditionalCapability(MobileCapabilityType.App, appConfiguration.AppPath); driverOptions.AddAdditionalCapability(MobileCapabilityType.DeviceName, appConfiguration.DeviceName); driverOptions.AddAdditionalCapability(MobileCapabilityType.PlatformName, appConfiguration.PlatformName); driverOptions.AddAdditionalCapability(MobileCapabilityType.PlatformVersion, appConfiguration.PlatformVersion); if (string.IsNullOrEmpty(appConfiguration.BrowserName)) { driverOptions.AddAdditionalCapability(AndroidMobileCapabilityType.AppPackage, appConfiguration.AppPackage); driverOptions.AddAdditionalCapability(AndroidMobileCapabilityType.AppActivity, appConfiguration.AppActivity); } else { driverOptions.AddAdditionalCapability(MobileCapabilityType.BrowserName, appConfiguration.BrowserName); } var wrappedWebDriver = default(AndroidDriver <AndroidElement>); if (appConfiguration.ExecutionType == Enums.ExecutionType.Regular) { if (_shouldStartAppiumLocalService) { if (AppiumLocalService == null) { throw new ArgumentException("The Appium local service is not started. You need to call App?.StartAppiumLocalService() in AssemblyInitialize method."); } wrappedWebDriver = new AndroidDriver <AndroidElement>(AppiumLocalService, driverOptions); } else { wrappedWebDriver = new AndroidDriver <AndroidElement>(new Uri(_appiumServiceUrl), driverOptions); } } else if (appConfiguration.ExecutionType == Enums.ExecutionType.SauceLabs) { wrappedWebDriver = new AndroidDriver <AndroidElement>(ConfigurationService.GetSection <MobileSettings>().SauceLabs.GridUri, appConfiguration.AppiumOptions, TimeSpan.FromSeconds(240)); } else if (appConfiguration.ExecutionType == Enums.ExecutionType.BrowserStack) { wrappedWebDriver = new AndroidDriver <AndroidElement>(ConfigurationService.GetSection <MobileSettings>().BrowserStack.GridUri, appConfiguration.AppiumOptions); } else if (appConfiguration.ExecutionType == Enums.ExecutionType.CrossBrowserTesting) { wrappedWebDriver = new AndroidDriver <AndroidElement>(ConfigurationService.GetSection <MobileSettings>().CrossBrowserTesting.GridUri, appConfiguration.AppiumOptions); } return(wrappedWebDriver); }
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 void ShutdownApp(ServicesCollection container) { var currentAppConfiguration = container.Resolve <AppConfiguration>("_currentAppConfiguration"); ShutdownApp(container); // Register the ExecutionEngine that should be used for the current run. Will be used in the next test as PreviousEngineType. var testExecutionEngine = new TestExecutionEngine(); // Register the app that should be used for the current run. Will be used in the next test as PreviousappType. container.RegisterInstance(currentAppConfiguration); // Start the current engine testExecutionEngine.StartApp(currentAppConfiguration, container); }
public static IOSDriver <IOSElement> CreateIOSDriver(AppConfiguration appConfiguration, ServicesCollection childContainer) { var driverOptions = childContainer.Resolve <AppiumOptions>(appConfiguration.ClassFullName) ?? appConfiguration.AppiumOptions; driverOptions.AddAdditionalCapability(MobileCapabilityType.App, appConfiguration.AppPath); driverOptions.AddAdditionalCapability(MobileCapabilityType.DeviceName, appConfiguration.DeviceName); driverOptions.AddAdditionalCapability(MobileCapabilityType.PlatformName, appConfiguration.PlatformName); driverOptions.AddAdditionalCapability(MobileCapabilityType.PlatformVersion, appConfiguration.PlatformVersion); driverOptions.AddAdditionalCapability(MobileCapabilityType.AutomationName, "XCUITest"); IOSDriver <IOSElement> wrappedWebDriver; if (_shouldStartAppiumLocalService) { if (AppiumLocalService == null) { throw new ArgumentException("The Appium local service is not started. You need to call App?.StartAppiumLocalService() in AssemblyInitialize method."); } wrappedWebDriver = new IOSDriver <IOSElement>(AppiumLocalService, driverOptions); } else { wrappedWebDriver = new IOSDriver <IOSElement>(new Uri(_appiumServiceUrl), driverOptions); } wrappedWebDriver.Manage().Timeouts().PageLoad = TimeSpan.FromSeconds(180); childContainer.RegisterInstance(wrappedWebDriver); childContainer.RegisterInstance <IWebDriver>(wrappedWebDriver); childContainer.RegisterInstance(childContainer.Resolve <BrowserService>()); childContainer.RegisterInstance(childContainer.Resolve <CookiesService>()); childContainer.RegisterInstance(childContainer.Resolve <DialogService>()); childContainer.RegisterInstance(childContainer.Resolve <JavaScriptService>()); childContainer.RegisterInstance(childContainer.Resolve <NavigationService>()); childContainer.RegisterInstance(childContainer.Resolve <ElementCreateService>()); var webDriver = childContainer.Resolve <IWebDriver>(); childContainer.RegisterInstance <IWebDriverElementFinderService>(new NativeElementFinderService(webDriver)); childContainer.RegisterNull <int?>(); childContainer.RegisterNull <IWebElement>(); return(wrappedWebDriver); }
private void RestartBrowser(ServicesCollection container) { var currentBrowserConfiguration = container.Resolve <BrowserConfiguration>("_currentBrowserConfiguration"); ShutdownBrowser(container); // Register the ExecutionEngine that should be used for the current run. Will be used in the next test as PreviousEngineType. var testExecutionEngine = new TestExecutionEngine(); container.RegisterInstance(testExecutionEngine); // Register the Browser type that should be used for the current run. Will be used in the next test as PreviousBrowserType. container.RegisterInstance(currentBrowserConfiguration); // Start the current engine with current browser type. testExecutionEngine.StartBrowser(currentBrowserConfiguration, container); }
public bool IsApplicable(Exception ex = null, ServicesCollection container = null, params object[] context) { if (container == null) { container = ServicesCollection.Current; } BrowserService browserService = container.Resolve <BrowserService>(); if (browserService == null) { throw new ArgumentNullException(nameof(BrowserService)); } var result = browserService.HtmlSource.Contains(TextToSearchInSource); return(result); }
public static WindowsDriver <WindowsElement> Create(AppInitializationInfo appConfiguration, ServicesCollection childContainer) { var driverOptions = childContainer.Resolve <DesiredCapabilities>(appConfiguration.ClassFullName) ?? childContainer.Resolve <DesiredCapabilities>() ?? appConfiguration.AppiumOptions; driverOptions.SetCapability("app", appConfiguration.AppPath); driverOptions.SetCapability("deviceName", "WindowsPC"); driverOptions.SetCapability("platformName", "Windows"); string workingDir = Path.GetDirectoryName(appConfiguration.AppPath); driverOptions.SetCapability("appWorkingDir", workingDir); driverOptions.SetCapability("createSessionTimeout", ConfigurationService.GetSection <DesktopSettings>().TimeoutSettings.CreateSessionTimeout); driverOptions.SetCapability("ms:waitForAppLaunch", ConfigurationService.GetSection <DesktopSettings>().TimeoutSettings.WaitForAppLaunchTimeout); var additionalCapabilities = ServicesCollection.Main.Resolve <Dictionary <string, object> >($"caps-{appConfiguration.ClassFullName}") ?? new Dictionary <string, object>(); foreach (var additionalCapability in additionalCapabilities) { driverOptions.SetCapability(additionalCapability.Key, additionalCapability.Value); } var wrappedWebDriver = new WindowsDriver <WindowsElement>(new Uri(_serviceUrl), driverOptions); wrappedWebDriver.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(ConfigurationService.GetSection <DesktopSettings>().TimeoutSettings.ImplicitWaitTimeout); ChangeWindowSize(appConfiguration.Size, wrappedWebDriver); wrappedWebDriver.SwitchTo().Window(wrappedWebDriver.CurrentWindowHandle); try { var closeButton = wrappedWebDriver.FindElementByAccessibilityId("Close"); wrappedWebDriver.Mouse.MouseMove(closeButton.Coordinates); } catch (Exception e) { e.PrintStackTrace(); } return(wrappedWebDriver); }
public void StartApp(AppConfiguration appConfiguration, ServicesCollection childContainer) { try { if (appConfiguration.MobileOSType.Equals(MobileOSType.Android)) { var wrappedWebDriver = WrappedAppiumCreateService.CreateAndroidDriver(appConfiguration, childContainer); childContainer.RegisterInstance(wrappedWebDriver); try { wrappedWebDriver.HideKeyboard(); } catch { // ignore } } else { WrappedAppiumCreateService.CreateIOSDriver(appConfiguration, childContainer); } childContainer.RegisterInstance(childContainer.Resolve <ElementCreateService>()); childContainer.RegisterNull <int?>(); childContainer.RegisterNull <IWebElement>(); childContainer.RegisterNull <AndroidElement>(); childContainer.RegisterNull <IOSElement>(); IsAppStartedCorrectly = true; } catch (Exception e) { Console.WriteLine(e); Telemetry.Instance.TrackException(e); IsAppStartedCorrectly = false; throw; } }
public void Dispose(ServicesCollection container) { var webDriver = container.Resolve <IWebDriver>(); DisposeDriverService.Dispose(webDriver, container); }
public static void CloseIOSApp(ServicesCollection childContainer) { var iosDriver = childContainer.Resolve <IOSDriver <IOSElement> >(); iosDriver?.CloseApp(); }