Example #1
0
        public Browser(IRuntimeServices runtimeServices, Settings configuration)
        {
            Trace.Write($"Configuration = {(configuration?.ToString() ?? "(null)")}");

            this.configuration = configuration ?? throw new MissingConfigurationException("Configuration is missing!");

            Log.Info("Initializing Driver...");
            var driverFactory = runtimeServices.GetBrowserFactoryBuilder(configuration);

            var browserName = this.configuration?.WebDriver?.Browser?.BrowserName.ToEnum <BrowserNames>();

            Log.Info($"WebDriver.BrowserDriver = {(browserName)}");
            browserDriver = driverFactory.Create(browserName ?? BrowserNames.chrome);

            if (configuration?.WebDriver?.Mode.ToEnum <Modes>() == Modes.browser)
            {
                var isMaximized = configuration?.WebDriver?.Browser?.Window?.IsMaximized ?? false;
                // configuring browser window
                Log.Info($"BrowserWindow.IsMaximized = {isMaximized}");

                if (isMaximized)
                {
                    MaximizePage();
                }
                else
                {
                    SetWindowSize(configuration?.WebDriver?.Browser?.Window?.InitialWidth ?? 800, configuration?.WebDriver?.Browser?.Window?.InitialHeight ?? 600);
                }
            }
            var  maxWait          = configuration?.WebDriver?.MaxWait;
            long waitMilliseconds = Math.Max(maxWait ?? 0, 60000L);

            Log.Info($"MaxWait = {waitMilliseconds}ms");
            var cfgMaxWait = TimeSpan.FromMilliseconds(waitMilliseconds);

            // set initial browser driver timeout to configuration or 1 minute if not defined
            lock (timeoutHistory)
            {
                timeoutHistory.Push(cfgMaxWait);
                browserDriver.ChangeBrowserDriverTimeout(cfgMaxWait);
            }

            FrameworkInit(runtimeServices);
        }