Beispiel #1
0
 public WebDriverAssertions(IDecoratedWebDriver webDriver, IControlSettings controlSettings, ITestCaseReporter testCaseReporter, ILogger logger)
 {
     _testCaseReporter = testCaseReporter ?? throw new ArgumentNullException(nameof(testCaseReporter));
     _webDriver        = webDriver ?? throw new ArgumentNullException(nameof(webDriver));;
     _controlSettings  = controlSettings ?? throw new ArgumentNullException(nameof(controlSettings));;
     _logger           = logger ?? throw new ArgumentNullException(nameof(logger));
 }
        public void SetupSeleniumTest()
        {
            DriverSession = Resolve <IDriverSession>();

            TestCaseReporter = Resolve <ITestCaseReporter>();
            TestCaseReporter.Initialize(TestContext.TestName);

            NavigateToBaseUrl();
        }
Beispiel #3
0
        public DecoratedWebDriver(IWebDriver original, IControlSettings controlSettings, ITestCaseReporter testCaseReporter, ILogger logger)
        {
            _original         = original ?? throw new System.ArgumentNullException(nameof(original));
            _controlSettings  = controlSettings ?? throw new System.ArgumentNullException(nameof(controlSettings));
            _testCaseReporter = testCaseReporter ?? throw new System.ArgumentNullException(nameof(testCaseReporter));
            _logger           = logger ?? throw new System.ArgumentNullException(nameof(logger));

            Assert = new WebDriverAssertions(this, _controlSettings, _testCaseReporter, _logger);
        }
Beispiel #4
0
        public DriverSession(IDecoratedWebDriver webDriver, EnvironmentSettings environmentSettings, IControlSettings controlSettings, ITestCaseReporter testCaseReporter)
        {
            if (webDriver == null)
            {
                throw new System.ArgumentNullException(nameof(webDriver));
            }
            if (environmentSettings == null)
            {
                throw new System.ArgumentNullException(nameof(environmentSettings));
            }
            if (controlSettings == null)
            {
                throw new System.ArgumentNullException(nameof(controlSettings));
            }
            if (testCaseReporter == null)
            {
                throw new System.ArgumentNullException(nameof(testCaseReporter));
            }

            WebDriver           = webDriver;
            EnvironmentSettings = environmentSettings;
            ControlSettings     = controlSettings;
            TestCaseReporter    = testCaseReporter;
        }
Beispiel #5
0
        // TODO: Refactor. Too many parameters.
        public IDriverSession Create(IDeviceProperties deviceProperties, IBrowserProperties browserProperties, RemoteWebDriverSettings remoteWebDriverSettings, EnvironmentSettings environmentSettings, IControlSettings controlSettings, ILogger logger, ITestCaseReporter testCaseReporter, ICommandExecutor httpCommandExecutor)
        {
            if (deviceProperties == null)
            {
                throw new ArgumentNullException(nameof(deviceProperties));
            }
            if (browserProperties == null)
            {
                throw new ArgumentNullException(nameof(browserProperties));
            }
            if (remoteWebDriverSettings == null)
            {
                throw new ArgumentNullException(nameof(remoteWebDriverSettings));
            }
            if (environmentSettings == null)
            {
                throw new ArgumentNullException(nameof(environmentSettings));
            }
            if (controlSettings == null)
            {
                throw new ArgumentNullException(nameof(controlSettings));
            }
            if (logger == null)
            {
                throw new ArgumentNullException(nameof(logger));
            }
            if (testCaseReporter == null)
            {
                throw new ArgumentNullException(nameof(testCaseReporter));
            }
            if (httpCommandExecutor == null)
            {
                throw new ArgumentNullException(nameof(httpCommandExecutor));
            }

            var browser = default(IWebDriver);

            // There are several kinds of platform we can create our software on:
            // 1. Desktop (ie: 'traditional' Web Browser Automation)
            // 2. Android (Devices)

            if (deviceProperties.Name == "DESKTOP")
            {
                switch (browserProperties.Name)
                {
                case "CHROME":
                    var chromeBrowserSettings = browserProperties.BrowserSettings as ChromeBrowserSettings;
                    if (null == chromeBrowserSettings)
                    {
                        throw new InvalidOperationException($"The browserSettings for {browserProperties.Name} are not availble. Were they correctly registered in the Container? ");
                    }

                    browser = StartBrowser(remoteWebDriverSettings, chromeBrowserSettings, controlSettings);

                    break;

                case "EDGE":
                    var edgeBrowserSettings = browserProperties.BrowserSettings as EdgeBrowserSettings;
                    if (null == edgeBrowserSettings)
                    {
                        throw new InvalidOperationException($"The browserSettings for {browserProperties.Name} are not availble. Were they correctly registered in the Container? ");
                    }

                    browser = StartBrowser(remoteWebDriverSettings, edgeBrowserSettings, controlSettings);

                    break;

                case "INTERNETEXPLORER":
                    var ieBrowserSettings = browserProperties.BrowserSettings as InternetExplorerBrowserSettings;
                    if (null == ieBrowserSettings)
                    {
                        throw new InvalidOperationException($"The browserSettings for {browserProperties.Name} are not availble. Were they correctly registered in the Container? ");
                    }

                    browser = StartBrowser(remoteWebDriverSettings, ieBrowserSettings, controlSettings);

                    break;

                case "FIREFOX":
                    var ffBrowserSettings = browserProperties.BrowserSettings as FireFoxBrowserSettings;
                    if (null == ffBrowserSettings)
                    {
                        throw new InvalidOperationException($"The browserSettings for {browserProperties.Name} are not availble. Were they correctly registered in the Container? ");
                    }

                    browser = StartBrowser(remoteWebDriverSettings, ffBrowserSettings, controlSettings);

                    break;

                default:
                    throw new ArgumentOutOfRangeException($"There is no support for starting browsers of type {browserProperties.Name}");
                }

                var decoratedWebDriver = new DecoratedWebDriver(browser, controlSettings, testCaseReporter, logger);

                return(new DriverSession(decoratedWebDriver, environmentSettings, controlSettings, testCaseReporter));
            }

            if (deviceProperties.Name == "ANDROID")
            {
                if (!remoteWebDriverSettings.UseRemoteDriver)
                {
                    throw new InvalidOperationException($"For Appium, we always configure the RemoteWebDriver settings. If running Appium locally, use the 'common-localhost-appium.json' file. ");
                }

                var appiumSettings        = deviceProperties.DeviceSettings as AppiumSettings;
                var appiumSettingsAdapter = new AppiumSettingsAdapter();
                var options = appiumSettingsAdapter.ToAppiumOptions(appiumSettings);

                var androidDriver = default(AndroidDriver);

                foreach (var currentAttempt in Enumerable.Range(1, controlSettings.AppiumDriverCreationRetries))
                {
                    try
                    {
                        androidDriver = new AndroidDriver(httpCommandExecutor, options);

                        break;
                    }
                    catch (Exception ex)
                    {
                        logger.Error($"ERROR: Starting Android Driver attempt {currentAttempt}");
                        logger.Error($"ERROR: {ex}");

                        if (currentAttempt == controlSettings.AppiumDriverCreationRetries)
                        {
                            throw;
                        }
                    }
                }

                return(new DriverSession(new DecoratedWebDriver(androidDriver, controlSettings, testCaseReporter, logger), environmentSettings, controlSettings, testCaseReporter));
            }

            throw new InvalidOperationException($"The device {deviceProperties.Name} is not supported as a Driver Session. ");
        }