Esempio n. 1
0
        /// <summary>
        /// Checks if local driver version is same with driver version from repo
        /// </summary>
        /// <param name="type">Driver type</param>
        /// <param name="executingPath">Driver location path</param>
        /// <param name="version">If version specified, checks if local driver version is equals with specified driver version from repo</param>
        /// <returns>True - drivers version is same, else false</returns>
        public static bool IsLocalVersionLatestVersion(DriverFactory.DriverTypes type, string executingPath, string version = "")
        {
            bool   result           = false;
            string latestVersion    = version == "" ? GetLatestVersionNumber(type) : version;
            string driverBinaryName = "";

            switch (type)
            {
            case DriverFactory.DriverTypes.Chrome:
                driverBinaryName = new ChromeConfig().GetBinaryName();
                result           = WebDriverManagerHelper.CheckDriverVersionFromExe(Path.Combine(executingPath, driverBinaryName), latestVersion);
                break;

            case DriverFactory.DriverTypes.Firefox:
                driverBinaryName = new FirefoxConfig().GetBinaryName();
                result           = WebDriverManagerHelper.CheckDriverVersionFromExe(Path.Combine(executingPath, driverBinaryName), latestVersion);
                break;

            case DriverFactory.DriverTypes.IE:
                driverBinaryName = new InternetExplorerConfig().GetBinaryName();
                result           = WebDriverManagerHelper.CheckDriverVerionFormExeAttributes(Path.Combine(executingPath, driverBinaryName), latestVersion);
                break;

            default:
                break;
            }
            return(result);
        }
        /// <summary>
        ///     Checks if local driver version is same with driver version from repo
        /// </summary>
        /// <param name="type">Driver type</param>
        /// <param name="executingPath">Driver location path</param>
        /// <param name="version">
        ///     If version specified, checks if local driver version is equals with specified driver version from
        ///     repo
        /// </param>
        /// <returns>True - drivers version is same, else false</returns>
        public static bool IsLocalVersionLatestVersion(DriverType type, string executingPath, string version = "")
        {
            var    result        = false;
            var    latestVersion = version == "" ? GetLatestVersionNumber(type) : version;
            string driverBinaryName;

            switch (type)
            {
            case DriverType.Chrome:
                driverBinaryName = new ChromeConfig().GetBinaryName();
                result           = Path.Combine(executingPath, driverBinaryName).CheckDriverVersionFromExe(latestVersion);
                break;

            case DriverType.Firefox:
                driverBinaryName = new FirefoxConfig().GetBinaryName();
                result           = Path.Combine(executingPath, driverBinaryName).CheckDriverVersionFromExe(latestVersion);
                break;

            case DriverType.IE:
                driverBinaryName = new InternetExplorerConfig().GetBinaryName();
                result           = Path.Combine(executingPath, driverBinaryName).CheckDriverVersionFormExeAttributes(latestVersion);
                break;
            }

            return(result);
        }
Esempio n. 3
0
        public void Setup()
        {
            //Setup and Configure Selenium for Browser Automation
            var config = new ChromeConfig();

            new DriverManager().SetUpDriver(config);
            var options = new ChromeOptions();

            options.AddLocalStatePreference("download.prompt_for_download", false);
            But = new ChromeDriver(options);

            //Initialize the Runner for your test.
            _runner = new ClassicRunner();

            // Initialize the eyes SDK (IMPORTANT: make sure your API key is set in the APPLITOOLS_API_KEY env variable).
            Eyes = new Eyes(_runner);
            Eyes.SaveNewTests = true;

            //Open AppliTool's Eyes and start a test based on the method name
            Eyes.Open(But, "VisualAiRockstar", TestContext.CurrentContext.Test.MethodName, new Size(1440, 900));

            //Utilize the Batching Feature to group tests by their Class
            Eyes.Batch.Name = TestContext.CurrentContext.Test.ClassName;

            // Navigate to the end desired Url
            But.Url = "https://demo.applitools.com/hackathon.html";
        }
        public static IWebDriver SetUpWebDriver()
        {
            if (_webDriver == null)
            {
                switch (TestContext.Parameters.Get("browser"))
                {
                case "Chrome":
                    var           dgf     = new ChromeConfig();
                    ChromeOptions options = new ChromeOptions();
                    options.AddArguments("disable-infobars");
                    options.AddArguments("--incognito");
                    options.AddArguments("--disable-gpu");
                    options.AddArguments("--no-sandbox");
                    options.AddArguments("--allow-insecure-localhost");
                    new DriverManager().SetUpDriver(new ChromeConfig());
                    _webDriver = new ChromeDriver(options);
                    break;

                default:
                    new DriverManager().SetUpDriver(new FirefoxConfig(), architecture: WebDriverManager.Helpers.Architecture.X64);
                    _webDriver = new FirefoxDriver();
                    break;
                }

                _webDriver.Manage().Window.Maximize();
            }

            return(_webDriver);
        }
Esempio n. 5
0
        protected void ChromeVersionListTest()
        {
            var browserConfig = new ChromeConfig();
            var version       = browserConfig.GetDriverVersion("73");

            Assert.NotEmpty(version);
            Assert.Equal("2.46", version);
        }
        public void ChromeVersionResultNotEmptyAndMatch()
        {
            var chromeConfig = new ChromeConfig();
            var version      = chromeConfig.GetLatestVersion();
            var regex        = new Regex(@"^\d+\.\d+$");
            var match        = regex.Match(version);

            Assert.NotEmpty(version);
            Assert.True(match.Success);
        }
Esempio n. 7
0
        /// <summary>
        /// Downloads driver from repo
        /// </summary>
        /// <param name="type">Driver type</param>
        /// <param name="version">Version number</param>
        /// <returns>Path of driver location</returns>
        private static string GetDriverVersion(DriverFactory.DriverTypes type, string version = "")
        {
            string       driverFullPath      = "";
            string       executingPath       = Path.Combine(AppDomain.CurrentDomain.BaseDirectory);
            string       binaryName          = "";
            string       url                 = "";
            string       latestVersionNumber = version == "" ? GetLatestVersionNumber(type) : version;
            Architecture currnetArchitecture = ArchitectureHelper.GetArchitecture();

            switch (type)
            {
            case DriverFactory.DriverTypes.Chrome:
                ChromeConfig cConfig = new ChromeConfig();
                binaryName = cConfig.GetBinaryName();
                url        = currnetArchitecture == Architecture.X32 ? cConfig.GetUrl32() : cConfig.GetUrl64();
                url        = UrlHelper.BuildUrl(url, latestVersionNumber);
                break;

            case DriverFactory.DriverTypes.Firefox:
                FirefoxConfig fConfig = new FirefoxConfig();
                binaryName = fConfig.GetBinaryName();
                url        = currnetArchitecture == Architecture.X32 ? fConfig.GetUrl32() : fConfig.GetUrl64();
                url        = UrlHelper.BuildUrl(url, latestVersionNumber);
                break;

            case DriverFactory.DriverTypes.IE:
                InternetExplorerConfig ieConfig = new InternetExplorerConfig();
                binaryName = ieConfig.GetBinaryName();
                url        = currnetArchitecture == Architecture.X32 ? ieConfig.GetUrl32() : ieConfig.GetUrl64();
                url        = UrlHelper.BuildUrl(url, latestVersionNumber);
                break;

            default:
                break;
            }
            string driverLocationPath = version == "" ? Path.Combine(executingPath, type.ToString())
                                                      : Path.Combine(Path.Combine(executingPath, type.ToString()), version);

            driverFullPath = Path.Combine(driverLocationPath, binaryName);

            if (!IsLocalVersionLatestVersion(type, driverLocationPath, version))
            {
                if (File.Exists(driverFullPath))
                {
                    File.Delete(driverFullPath);
                }

                new Manager.DriverManager().SetUpDriver(url, driverFullPath, binaryName);
            }
            return(driverLocationPath);
        }
 public DriverService GetDriverService()
 {
     if (_driverService != null)
     {
         return(_driverService);
     }
     _driverService = _driverConfig switch
     {
         ChromeConfig _ => ChromeDriverService.CreateDefaultService(_driverConfig.DriverDirectoryFullPath()),
         _ => throw new InvalidOperationException()
     };
     _driverService.Port = NextFreeTcpPort();
     return(_driverService);
 }
Esempio n. 9
0
        public void SetupDriver(string browserName)
        {
            //Default value
            IDriverConfig config = new ChromeConfig();

            switch (browserName.ToLower())
            {
            case "firefox":
                config = new FirefoxConfig();
                break;
            }

            SetupConfig(config);
        }
        /// <summary>
        ///     Get's latest driver version number
        /// </summary>
        /// <param name="type">Driver type</param>
        /// <returns>Version number</returns>
        private static string GetLatestVersionNumber(DriverType type)
        {
            var latestVersion = "";

            switch (type)
            {
            case DriverType.Chrome:
                latestVersion = new ChromeConfig().GetLatestVersion();
                break;

            case DriverType.Firefox:
                latestVersion = new FirefoxConfig().GetLatestVersion();
                break;

            case DriverType.IE:
                latestVersion = new InternetExplorerConfig().GetLatestVersion();
                break;
            }

            return(latestVersion);
        }
        /// <summary>
        /// Using the Web Driver Manager
        /// </summary>
        private static void UsingDriverManager(DriverOption driverOption)
        {
            IWebDriver    webDriver    = null;
            IDriverConfig driverConfig = null;

            switch (driverOption)
            {
            case DriverOption.Chrome:
                driverConfig = new ChromeConfig();
                webDriver    = new ChromeDriver();
                break;

            case DriverOption.Edge:
                driverConfig = new EdgeConfig();
                webDriver    = new EdgeDriver();
                break;

            case DriverOption.Firefox:
                driverConfig = new FirefoxConfig();
                webDriver    = new FirefoxDriver("./");
                break;

            case DriverOption.IE:
                driverConfig = new InternetExplorerConfig();
                webDriver    = new InternetExplorerDriver();
                break;

            case DriverOption.Opera:
                driverConfig = new OperaConfig();
                webDriver    = new OperaDriver();
                break;
            }

            new DriverManager().SetUpDriver(driverConfig);
            webDriver.Navigate().GoToUrl("https://www.google.com");
            System.Console.WriteLine($"Title : {webDriver.Title}");
            webDriver.Quit();
        }
Esempio n. 12
0
        /// <summary>
        /// Get's latest driver version number
        /// </summary>
        /// <param name="type">Driver type</param>
        /// <returns>Version number</returns>
        private static string GetLatestVersionNumber(DriverFactory.DriverTypes type)
        {
            string latestVersion = "";

            switch (type)
            {
            case DriverFactory.DriverTypes.Chrome:
                latestVersion = new ChromeConfig().GetLatestVersion();
                break;

            case DriverFactory.DriverTypes.Firefox:
                latestVersion = new FirefoxConfig().GetLatestVersion();
                break;

            case DriverFactory.DriverTypes.IE:
                latestVersion = new InternetExplorerConfig().GetLatestVersion();
                break;

            default:
                break;
            }
            return(latestVersion);
        }
Esempio n. 13
0
 public ServiceTests()
 {
     _customBinaryService   = new BinaryService();
     _customVariableService = new VariableService();
     _chromeConfig          = new ChromeConfig();
 }
Esempio n. 14
0
        /// <summary>
        /// Creates a new WebDriver instance for one of the major web
        /// browsers. Will wrap the driver in an
        /// <see cref="EventFiringWebDriver"/>.
        /// </summary>
        /// <param name="majorWebDriver"></param>
        /// <param name="windowSize"></param>
        /// <param name="track">
        /// If false, will not dispose the driver when the factory is
        /// disposed.
        /// </param>
        /// <returns></returns>
        public IWebDriver CreateDriver(MajorWebDriver majorWebDriver,
                                       Size windowSize,
                                       bool track = true)
        {
            var driver       = default(IWebDriver);
            var driverOpts   = default(DriverOptions);
            var driverConfig = default(IDriverConfig);

            switch (majorWebDriver)
            {
            case MajorWebDriver.Chrome:
                driverConfig = new ChromeConfig();
                driverOpts   = new ChromeOptions();
                break;

            case MajorWebDriver.Edge:
                driverConfig = new EdgeConfig();
                driverOpts   = new EdgeOptions();
                break;

            case MajorWebDriver.Firefox:
                driverConfig = new FirefoxConfig();
                driverOpts   = new FirefoxOptions();
                break;

            case MajorWebDriver.InternetExplorer:
                driverConfig = new InternetExplorerConfig();
                driverOpts   = new InternetExplorerOptions();
                break;

            default:
                throw new NotImplementedException();
            }

            // Download driver if not available locally.
            driverManager.SetUpDriver(driverConfig);

            if (isStandalone)
            {
                switch (majorWebDriver)
                {
                case MajorWebDriver.Chrome:
                {
                    var opts = driverOpts as ChromeOptions;
                    opts.BinaryLocation = @"C:\Program Files (x86)\Google\Chrome\Application\chrome.exe";
                    driver = new ChromeDriver(opts);
                    break;
                }

                case MajorWebDriver.Edge:
                {
                    driver = new EdgeDriver();
                    break;
                }

                case MajorWebDriver.Firefox:
                {
                    var opts = driverOpts as FirefoxOptions;
                    opts.BrowserExecutableLocation = @"C:\Program Files\Mozilla Firefox\firefox.exe";
                    driver = new FirefoxDriver(opts);
                    break;
                }

                case MajorWebDriver.InternetExplorer:
                {
                    driver = new InternetExplorerDriver();
                    break;
                }

                default:
                    throw new NotImplementedException();
                }
            }
            else
            {
                var d = new RemoteSessionSettings();
                d.AddFirstMatchDriverOption(driverOpts);

                driver = new RemoteWebDriver(d);
            }

            // Set the window size.
            driver.Manage().Window.Size = windowSize;

            // Wrap with EventFiringWebDriver.
            //driver = new EventFiringWebDriver(driver);

            if (track)
            {
                trackedDrivers.Add(driver);
            }

            return(driver);
        }