Пример #1
0
        public static IWebDriver GetDriver(Driver driverType, DriverOptions options)
        {
            var directory = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location) + Config.Default.DriverPath;
            var timeout   = TimeSpan.FromMilliseconds(Config.Default.ExplicitWait);

            switch (driverType)
            {
            case Driver.Chrome:
                return(new ChromeDriver(ChromeDriverService.CreateDefaultService(directory), options as ChromeOptions, timeout));

            case Driver.Firefox:
                return(new FirefoxDriver(FirefoxDriverService.CreateDefaultService(directory), options as FirefoxOptions, timeout));
            }

            return(null);
        }
Пример #2
0
        private IWebDriver SeleniumLocal(string location)
        {
            var driverService = FirefoxDriverService.CreateDefaultService("/usr/local/bin/");

            driverService.HideCommandPromptWindow = true;

            var firefoxOptions = new FirefoxOptions();

            firefoxOptions.AddArgument("--headless");

            var driver = new FirefoxDriver(driverService, firefoxOptions, TimeSpan.FromSeconds(10));

            driver.Manage().Window.Size = new System.Drawing.Size(1280, 1024);

            return(driver);
        }
Пример #3
0
        public AddressesTests()
        {
            var geckoService = FirefoxDriverService.CreateDefaultService(Environment.CurrentDirectory);

            geckoService.Host = "::1";
            var firefoxOptions = new FirefoxOptions
            {
                AcceptInsecureCertificates = true
            };

            _driver      = new FirefoxDriver(geckoService, firefoxOptions);
            _page        = new AddressPage(_driver, "Settings/Addresses/Add");
            _loginHelper = new LoginHelper(_driver);

            _page.Navigate();
        }
        protected virtual IWebDriver CreateFirefoxWebDriver(long loginWaitTime)
        {
            DriverOptions driverOptions;
            IWebDriver    driver;

            driverOptions = BrowserOptionsFactory.Create();
            Encoding.RegisterProvider(CodePagesEncodingProvider.Instance);
            var ffService = FirefoxDriverService.CreateDefaultService(ConfigurationReader.GetConfigurationValue(Configuration.DriverServerLocationKey), "geckodriver.exe");

            ffService.Host = "::1";
            ffService.FirefoxBinaryPath = string.IsNullOrWhiteSpace(ConfigurationReader.GetConfigurationValue(Configuration.DriverServerLocationKey)) ? @"C:\Program Files\Mozilla Firefox\firefox.exe" : ConfigurationReader.GetConfigurationValue(Configuration.BrowserLocationKey);
            driver = new FirefoxDriver(ffService, (FirefoxOptions)driverOptions, TimeSpan.FromMinutes(loginWaitTime));
            driver.Manage().Cookies.DeleteAllCookies();
            driver.Manage().Window.Maximize();
            return(driver);
        }
Пример #5
0
        public static FirefoxDriverService CreateDriverService(string driverDirectory = null)
        {
            FirefoxDriverService service;

            if (driverDirectory != null)
            {
                service = FirefoxDriverService.CreateDefaultService(driverDirectory);
            }
            else
            {
                service = FirefoxDriverService.CreateDefaultService();
            }
            service.HideCommandPromptWindow = true;
            service.SuppressInitialDiagnosticInformation = true;
            return(service);
        }
        /// <summary>
        /// Retorna o Driver de acordo com o navegador
        /// </summary>
        /// <param name="typeTestBrowser"></param>
        /// <returns></returns>
        public virtual IWebDriver CreateDriver(TypeTestBrowser typeTestBrowser)
        {
            switch (typeTestBrowser)
            {
            case TypeTestBrowser.FireFox: return(new FirefoxDriver(FirefoxDriverService.CreateDefaultService(GetDriver(typeTestBrowser), "geckodriver.exe")));

            case TypeTestBrowser.Chrome: return(new ChromeDriver(GetDriver(typeTestBrowser)));

            case TypeTestBrowser.Edge: return(new EdgeDriver(GetDriver(typeTestBrowser)));

            case TypeTestBrowser.IE: return(new InternetExplorerDriver(GetDriver(typeTestBrowser)));

            //   case TypeTestBrowser.Phantom: return new PhantomJSDriver(GetDriver(typeTestBrowser));
            default: return(null);
            }
        }
Пример #7
0
        // Sets the profile using local profile path
        public IWebDriver FirefoxDriver(String profilePath)
        {
            var driverService = FirefoxDriverService.CreateDefaultService(DriverLocation, "geckodriver.exe");

            firefoxProfile = new FirefoxProfile(profilePath)
            {
                EnableNativeEvents = false
            };
            var options = new FirefoxOptions
            {
                Profile = firefoxProfile
            };
            FirefoxDriver driver = new FirefoxDriver(driverService, options, TimeSpan.FromMinutes(1));

            return(driver);
        }
        /// <summary>
        /// Desc:Method is used to initializatied the driver
        /// </summary>
        /// <param name="data"></param>
        /// <param name="testCaseName"></param>
        /// <returns></returns>
        public DataRow DriverInitialization(Dictionary <string, string> data, string testCaseName)
        {
            DataRow dr = null;
            ExcelReaderUsingOleDb excelReader = new ExcelReaderUsingOleDb();

            dt = excelReader.ReadExcelData(EnumClasses.SheetNames.TestCases.ToString());
            if (dt.Rows.Count > 0)
            {
                datarow = dt.Select("testcaseid =" + data["testcaseid"]).FirstOrDefault();
                DataTable dt1 = excelReader.ReadExcelData(testCaseName);
                dr = dt1.Select("testcaseid =" + datarow["testcaseid"].ToString() + "AND id=" + data["id"].ToString()).FirstOrDefault();

                string BrowserName = dr["browsername"].ToString();
                string Url         = ConfigurationManager.AppSettings["Url"];
                string driverPath  = GetDriversPath();
                if (BrowserName == EnumClasses.BrowserName.ie.ToString())
                {
                    var options = new InternetExplorerOptions();
                    options.IntroduceInstabilityByIgnoringProtectedModeSettings = true;
                    driver = new InternetExplorerDriver(options);
                    driver = new InternetExplorerDriver(driverPath);
                }
                else if (BrowserName == EnumClasses.BrowserName.firefox.ToString())
                {
                    FirefoxProfileManager Manager  = new FirefoxProfileManager();
                    FirefoxProfile        profile  = Manager.GetProfile("Default");
                    FirefoxDriverService  Services = FirefoxDriverService.CreateDefaultService(driverPath);
                    FirefoxOptions        option   = new FirefoxOptions();
                    option.Profile = profile;
                    driver         = new FirefoxDriver(Services, option, TimeSpan.FromSeconds(60));
                }
                else if (BrowserName == EnumClasses.BrowserName.chrome.ToString())
                {
                    driver = new ChromeDriver(driverPath);
                    ChromeOptions options = new ChromeOptions();
                    options.AddArguments("--start-maximized");
                }
                else
                {
                    driver = new ChromeDriver(driverPath);
                }
                driver.Navigate().GoToUrl(Url);
                System.Threading.Thread.Sleep(100);
                driver.Manage().Window.Maximize();
            }
            return(dr);
        }
Пример #9
0
        /// <summary>
        /// Method to initialize driver
        /// </summary>
        /// <param name="browser"></param>
        public void InitializeDriver(string browser)
        {
            switch (browser.ToLower())
            {
            case "chrome":
                ChromeOptions options = new ChromeOptions();
                options.AddArguments("disable-infobars");
                options.AddAdditionalCapability("useAutomationExtension", false);
                _driver = new ChromeDriver(options);
                _driver.Manage().Window.Maximize();
                break;

            case "firefox":
                //Environment.SetEnvironmentVariable("webdriver.gecko.driver", CommonUtils.AssemblyPath + "\\geckodriver.exe");
                //FirefoxOptions op = new FirefoxOptions();
                //op.SetPreference("security.insecure_field_warning.contextual.enabled", false);
                //_driver = new FirefoxDriver(op);

                FirefoxDriverService service = FirefoxDriverService.CreateDefaultService();
                service.FirefoxBinaryPath = @"C:\Program Files\Mozilla Firefox\firefox.exe";
                _driver = new FirefoxDriver(service);
                _driver.Manage().Window.Maximize();

                break;

            case "ie11":
                _driver = new InternetExplorerDriver();
                break;

            case "edge":
                _driver = new EdgeDriver();
                break;

            default:
                _driver = new InternetExplorerDriver();
                break;
            }
            if (recordVideo)
            {
                CommonUtils.StartVideoRecord();
            }
            Logger.Info(string.Format("Launching browser: '{0}'", browser), "");
            _driver.Navigate().GoToUrl(ixmWebUrl);
            _driver.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(2);
            _wait = new WebDriverWait(_driver, TimeSpan.FromSeconds(15));
            _driver.Manage().Timeouts().PageLoad = TimeSpan.FromSeconds(20);
        }
Пример #10
0
        public WebDriverConfiguration GetBrowser(Constants.BrowserType browser, string browserPath)
        {
            WebDriverConfiguration webDriverConfiguration = new WebDriverConfigurationFactory().Create();

            switch (browser)
            {
            case Constants.BrowserType.Chrome:
                var chromeOptions = new ChromeOptions();
                chromeOptions.SetLoggingPreference(LogType.Browser, LogLevel.All);
                chromeOptions.AddArgument("--ignore-certificate-errors");
                //chromeOptions.AddUserProfilePreference("profile.managed_default_content_settings.images", 2);
                chromeOptions.AddUserProfilePreference("profile.default_content_settings.state.flash", 0);

                webDriverConfiguration.WebDriver = new ChromeDriver(AppDomain.CurrentDomain.BaseDirectory + browserPath, chromeOptions);
                break;

            case Constants.BrowserType.FireFox:
                webDriverConfiguration.FireFoxService = FirefoxDriverService.CreateDefaultService(AppDomain.CurrentDomain.BaseDirectory + browserPath, "geckodriver.exe");

                FirefoxOptions firefoxOptions = new FirefoxOptions();
                firefoxOptions.SetLoggingPreference(LogType.Browser, LogLevel.All);
                firefoxOptions.AddAdditionalCapability("acceptInsecureCerts", true, true);

                webDriverConfiguration.WebDriver = new FirefoxDriver(webDriverConfiguration.FireFoxService, firefoxOptions, TimeSpan.FromSeconds(180));
                break;

            case Constants.BrowserType.InternetExplorer:
                var internetExplorerOptions = new InternetExplorerOptions();

                internetExplorerOptions.AddAdditionalCapability(CapabilityType.AcceptSslCertificates, true);
                internetExplorerOptions.EnsureCleanSession = true;

                webDriverConfiguration.WebDriver = new InternetExplorerDriver(AppDomain.CurrentDomain.BaseDirectory + browserPath, internetExplorerOptions);

                break;

            default:
            {
                string errorMsg = FormattableString.Invariant(
                    $"Browser type: {browser}. Try and use BrowserStack by setting UseBrowserStack to true in app.config and run the StartBrowserStackLocal.ps1 before running the test.");

                throw new NotSupportedException(errorMsg);
            }
            }

            return(webDriverConfiguration);
        }
Пример #11
0
        /// <summary>
        /// <see cref="https://github.com/SeleniumHQ/selenium/wiki/FirefoxDriver"/>
        /// <seealso cref="https://seleniumhq.github.io/selenium/docs/api/dotnet/html/T_OpenQA_Selenium_Firefox_FirefoxDriver.htm"/>
        /// </summary>
        /// <returns></returns>
        private static IWebDriver FF()
        {
            try
            {
                string        firefoxBin = "";
                List <String> possibleFF = new List <string>()
                {
                    { @"C:\Program Files (x86)\Mozilla Firefox\firefox.exe" },
                    { @"C:\Program Files\Mozilla Firefox\firefox.exe" },
                    { @"C:\Program Files\Nightly\firefox.exe" },
                    { Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), @"Mozilla Firefox\firefox.exe") }
                };

                for (int i = 0; i < possibleFF.Count; i++)
                {
                    firefoxBin = possibleFF[i];
                    if (File.Exists(possibleFF[i]))
                    {
                        break;
                    }
                }

                //FirefoxDriverService service = FirefoxDriverService.CreateDefaultService(Path.Combine(Environment.CurrentDirectory, "drivers"), "geckodriver.exe");
                FirefoxDriverService service = FirefoxDriverService.CreateDefaultService(Environment.CurrentDirectory, "geckodriver.exe");
                //service.Port = 64444;
                service.FirefoxBinaryPath = firefoxBin;
                IWebDriver driver = new FirefoxDriver(service, new FirefoxOptions(), TimeSpan.FromSeconds(180));
                //new FirefoxDriver(new FirefoxBinary(), new FirefoxProfile(), TimeSpan.FromSeconds(180));

                /*
                 * working, but cannot control driver path
                 * FirefoxProfile profile = new FirefoxProfile();
                 * profile.SetPreference("webdriver.firefox.bin", firefoxBin);
                 * IWebDriver driver = new FirefoxDriver(profile);
                 */

                //FirefoxBinary bin = new FirefoxBinary(firefoxBin);
                //IWebDriver driver = new FirefoxDriver(bin, profile);          //OBSOLETE

                return(driver);
            }
            catch (Exception x)
            {
                XLogger.Error(x);
                throw;
            }
        }
Пример #12
0
        private static FirefoxDriver FirefoxDriver()
        {
            const string winX86Path = @"C:\Program Files (x86)\Mozilla Firefox\firefox.exe";
            const string winPath    = @"C:\Program Files\Mozilla Firefox\firefox.exe";
            const string unixPath   = @"/usr/bin/firefox/firefox-bin";

            if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows) && File.Exists(winX86Path))
            {
                SetUpDriverService(winX86Path, "win32");
            }
            else if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows) && File.Exists(winPath) && Architecture.X64 == RuntimeInformation.OSArchitecture)
            {
                SetUpDriverService(winPath, "win64");
            }
            else if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows) && File.Exists(winPath) && Architecture.X86 == RuntimeInformation.OSArchitecture)
            {
                SetUpDriverService(winPath, "win32");
            }
            else if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux) && File.Exists(unixPath))
            {
                SetUpDriverService(unixPath, "linux64");
            }
            else if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX) && File.Exists(unixPath))
            {
                SetUpDriverService(unixPath, "mac64");
            }
            else
            {
                throw new Exception("Firefox not found installed or invalid SO");
            }

            var firefoxOptions = new FirefoxOptions();

            firefoxOptions.AddArgument("--headless");

            FirefoxDriverService driverService;

            return(new FirefoxDriver(driverService, firefoxOptions));

            void SetUpDriverService(string path, string driverFolder)
            {
                var driverLocation = GetNugetPackageDir("Selenium.WebDriver.GeckoDriver", "driver", driverFolder);

                driverService = FirefoxDriverService.CreateDefaultService(driverLocation);
                driverService.FirefoxBinaryPath = path;
            }
        }
Пример #13
0
        public void SetupTest()
        {
            if ("ff".Equals(this.browser))
            {
                var service = FirefoxDriverService.CreateDefaultService();
                this.driver = new FirefoxDriver(service);
            }
            else
            {
                ChromeOptions option = new ChromeOptions();
                option.AddArgument("disable-infobars");
                this.driver = new ChromeDriver(option);
            }

            this.driver.Navigate().GoToUrl(this.baseUrl);
            this.driver.Manage().Window.Maximize();
        }
Пример #14
0
 public Filler(string url, IWebDriver drv = null)
 {
     if (driver == null)
     {
         var service = FirefoxDriverService.CreateDefaultService();
         service.HideCommandPromptWindow = true;
         service.SuppressInitialDiagnosticInformation = true;
         //service.ConnectToRunningBrowser = true;
         driver = new FirefoxDriver(service);
     }
     else
     {
         driver = drv;
     }
     baseURL            = url;
     verificationErrors = new StringBuilder();
 }
Пример #15
0
        public IWebDriver Create()
        {
            var driver = GetWebDriverType();

            if (driver == "Remote")
            {
                return(new RemoteWebDriver(new Uri("http://seleniumhub:4444/wd/hub"), new FirefoxOptions()));
            }

            var driverPath = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
            var service    = FirefoxDriverService.CreateDefaultService(driverPath, "geckodriver.exe");
            var options    = new FirefoxOptions();

            options.AddArguments("--headless");

            return(new FirefoxDriver(service, options));
        }
Пример #16
0
        public ReportTests()
        {
            var geckoService = FirefoxDriverService.CreateDefaultService(Environment.CurrentDirectory);

            geckoService.Host = "::1";
            var firefoxOptions = new FirefoxOptions
            {
                AcceptInsecureCertificates = true
            };

            _driver = new FirefoxDriver(geckoService, firefoxOptions);
            //_page = new ReportPage(_driver, "Admin/Reports");
            _page        = new ReportPage(_driver, "/Admin/Reports/Games");
            _loginHelper = new LoginHelper(_driver);

            _page.Navigate();
        }
Пример #17
0
 /// <summary>
 /// Gets the capabilities for FIREFOX
 /// </summary>
 /// <param name="_logLevel"></param>
 /// <param name="_alertBehaviour"></param>
 /// <param name="acceptSlefSignedSSL"></param>
 /// <param name="_loadStrategy"></param>
 /// <returns></returns>
 private FirefoxOptions GetFirefoxBrowserOptions(FirefoxDriverLogLevel _logLevel         = FirefoxDriverLogLevel.Default,
                                                 UnhandledPromptBehavior _alertBehaviour = UnhandledPromptBehavior.Default,
                                                 bool acceptSlefSignedSSL       = true,
                                                 PageLoadStrategy _loadStrategy = PageLoadStrategy.Default)
 {
     FirefoxService = FirefoxDriverService.CreateDefaultService(Directory.GetCurrentDirectory(), @"geckodriver.exe");
     FirefoxService.HideCommandPromptWindow = true;
     FirefoxService.Start();
     return(new FirefoxOptions()
     {
         LogLevel = _logLevel,
         UnhandledPromptBehavior = _alertBehaviour,
         PageLoadStrategy = _loadStrategy,
         AcceptInsecureCertificates = acceptSlefSignedSSL,
         UseLegacyImplementation = true
     });
 }
        public static IWebDriver CreateWebDriver(BrowserOptions options)
        {
            IWebDriver driver;

            switch (options.BrowserType)
            {
            case BrowserType.Chrome:
                var chromeService = ChromeDriverService.CreateDefaultService(options.DriversPath);
                chromeService.HideCommandPromptWindow = options.HideDiagnosticWindow;
                driver = new ChromeDriver(chromeService, options.ToChrome());
                break;

            case BrowserType.Firefox:
                var ffService = FirefoxDriverService.CreateDefaultService(options.DriversPath);
                ffService.HideCommandPromptWindow = options.HideDiagnosticWindow;
                driver = new FirefoxDriver(ffService);
                driver.Manage().Timeouts().ImplicitWait = new TimeSpan(0, 0, 5);
                break;

            case BrowserType.Edge:
                var edgeService = EdgeDriverService.CreateDefaultService(options.DriversPath);
                edgeService.HideCommandPromptWindow = options.HideDiagnosticWindow;
                driver = new EdgeDriver(edgeService, options.ToEdge(), TimeSpan.FromMinutes(20));

                break;

            default:
                throw new InvalidOperationException(
                          $"The browser type '{options.BrowserType}' is not recognized.");
            }

            driver.Manage().Timeouts().PageLoad = options.PageLoadTimeout;

            if (options.StartMaximized && options.BrowserType != BrowserType.Chrome) //Handle Chrome in the Browser Options
            {
                driver.Manage().Window.Maximize();
            }

            if (options.FireEvents || options.EnableRecording)
            {
                // Wrap the newly created driver.
                driver = new EventFiringWebDriver(driver);
            }

            return(driver);
        }
Пример #19
0
        public FireFoxFixture()
        {
            //Environment.SetEnvironmentVariable("webdriver.log.file", "log-file.txt");
            //Environment.SetEnvironmentVariable("webdriver.firefox.logfile", "ff-log.txt");
            //driver = new FirefoxDriver(new FirefoxOptions());
            var driverService = FirefoxDriverService.CreateDefaultService();

            driverService.FirefoxBinaryPath = @"C:\Program Files (x86)\Mozilla Firefox\firefox.exe";
            if (!File.Exists(driverService.FirefoxBinaryPath))
            {
                driverService.FirefoxBinaryPath = @"C:\Program Files\Mozilla Firefox\firefox.exe";
            }
            driverService.HideCommandPromptWindow = true;
            driverService.SuppressInitialDiagnosticInformation = true;

            driver = new FirefoxDriver(driverService, new FirefoxOptions(), TimeSpan.FromSeconds(60));
        }
Пример #20
0
        /// <summary>
        /// Sets the Firefox Driver Service setting from the app.config file
        /// </summary>
        private void SetDriverService()
        {
            try
            {
                int.TryParse(Firefox.CommunicationPort, out int browserComm);
                bool.TryParse(Firefox.ConnectToRunningBrowser, out bool connect);
                bool.TryParse(Firefox.HideCommandPromptWindow, out bool hideCommand);
                int.TryParse(Firefox.Host, out int port);
                bool.TryParse(Firefox.SuppressInitialDiagnosticInformation, out bool sidi);

                string driverLocation = Directory.GetParent(BaseSettings.FirefoxDriverLocation).FullName;

                string binaryPath = BaseSettings.FirefoxLocation;
                string host       = Firefox.Host;

                FirefoxDriverService service = FirefoxDriverService.CreateDefaultService(driverLocation);
                service.BrowserCommunicationPort = browserComm;
                service.ConnectToRunningBrowser  = connect;
                service.FirefoxBinaryPath        = binaryPath;
                service.HideCommandPromptWindow  = hideCommand;
                //service.Host = host;
                //service.Port = port;
                service.SuppressInitialDiagnosticInformation = sidi;
                Service = service;
            }
            catch (Exception ex)
            {
                switch (BaseSettings.DebugLevel)
                {
                case EnumConsoleDebugLevel.Human:
                    Console.Out.WriteLine("Could not set the Firefox driver service settings.");
                    break;

                case EnumConsoleDebugLevel.NotSpecified:
                case EnumConsoleDebugLevel.Message:
                    Console.Out.WriteLine(ex.Message);
                    break;

                case EnumConsoleDebugLevel.StackTrace:
                    Console.Out.WriteLine(ex.Message);
                    Console.Out.WriteLine(ex.StackTrace);
                    break;
                }
                Service = null;
            }
        }
Пример #21
0
    public void SetupTest()

    {
//FirefoxDriverService service = FirefoxDriverService.CreateDefaultService(@”/Users/rakeshprabhakaran/Project/c#/expOne/lib/”, “geckodriver”);
//FirefoxDriverService service = FirefoxDriverService.CreateDefaultService("F:\\ProjectFolder\\Drivers", "geckodriver.exe");
        var relpath = $AGENT_HOMEDIRECTORY;
//Console.WriteLine($AGENT_HOMEDIRECTORY);
        FirefoxDriverService service = FirefoxDriverService.CreateDefaultService($AGENT_HOMEDIRECTORY + "/Drivers", "geckodriver.exe");

//service.Port = 64444;

        driver = new FirefoxDriver(service);

        driver.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(30);

        driver.Url = "https://code.visualstudio.com";
    }
Пример #22
0
        public static RemoteWebDriver FirefoxWebDriver(int?portaTCP = null, FileInfo webDriverLocation = null)
        {
            webDriverLocation = GetWebDriverLocation(webDriverLocation, "geckodriver*.exe");
            var driverService = FirefoxDriverService.CreateDefaultService(webDriverLocation.Directory.FullName, webDriverLocation.Name);

            driverService.FirefoxBinaryPath = @"C:\Program Files\Mozilla Firefox\firefox.exe";
            if (portaTCP.HasValue)
            {
                driverService.Port = portaTCP.Value;
            }
            var driverOptions = new FirefoxOptions()
            {
                AcceptInsecureCertificates = true, PageLoadStrategy = PageLoadStrategy.Normal
            };

            return(new FirefoxDriver(driverService, driverOptions, TimeSpan.FromSeconds(30)));
        }
        protected override IWebDriver DoBuildAndGetWebDriver(BrowserConfig browserConfig)
        {
            FirefoxDriverService firefoxDriverService = FirefoxDriverService.CreateDefaultService(browserConfig.WebDriverPath);

            FirefoxOptions firefoxOptions = new FirefoxOptions();

            firefoxOptions.BrowserExecutableLocation = browserConfig.WebDriverPath + "firefox.exe";
            if (browserConfig.BrowserOptions != null)
            {
                firefoxOptions.AddArguments(browserConfig.BrowserOptions);
            }

            TimeSpan   TimeSpan  = new TimeSpan(1, 0, 0);
            IWebDriver webDriver = new FirefoxDriver(firefoxDriverService, firefoxOptions, TimeSpan);

            return(webDriver);
        }
Пример #24
0
        public static IWebDriver GetDriver(BrowserType type, int timeOutSec)
        {
            IWebDriver driver = null;

            switch (type)
            {
            case BrowserType.Chrome:
            {
                var service = ChromeDriverService.CreateDefaultService();
                var option  = new ChromeOptions();
                option.AddArgument("disable-infobars");
                driver = new ChromeDriver(service, option, TimeSpan.FromSeconds(timeOutSec));
                driver.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(3);
                break;
            }

            case BrowserType.Firefox:
            {
                var service = FirefoxDriverService.CreateDefaultService();
                var options = new FirefoxOptions();
                driver = new FirefoxDriver(service, options, TimeSpan.FromSeconds(timeOutSec));
                driver.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(3);
                break;
            }

            case BrowserType.remoteFirefox:
            {
                var cability = new DesiredCapabilities();
                cability.SetCapability(CapabilityType.BrowserName, "firefox");
                cability.SetCapability(CapabilityType.Platform, new Platform(PlatformType.Any));
                driver = new RemoteWebDriver(new Uri("http://localhost:5566/wd/hub"), cability);
                driver.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(3);
                break;
            }

            case BrowserType.remoteChrome:
            {
                var option = new ChromeOptions();
                option.AddArgument("disable-infobars");
                option.AddArgument("--no-sandbox");
                driver = new RemoteWebDriver(new Uri("http://localhost:5566/wd/hub"), option.ToCapabilities());
                break;
            }
            }
            return(driver);
        }
Пример #25
0
        /// <summary>
        /// Initialize a new Firefox driver
        /// </summary>
        /// <param name="commandTimeout">Browser command timeout</param>
        /// <param name="firefoxOptions">Browser options</param>
        /// <param name="size">Browser size in the following format: MAXIMIZE, DEFAULT, or #x# (such as 1920x1080)</param>
        /// <returns>A new Firefox driver</returns>
        public static IWebDriver GetFirefoxDriver(TimeSpan commandTimeout, FirefoxOptions firefoxOptions, string size = "MAXIMIZE")
        {
            return(CreateDriver(() =>
            {
                // Add support for encoding 437 that was removed in .net core
                Encoding.RegisterProvider(CodePagesEncodingProvider.Instance);

                // Create service and set host.  Setting host directly greatly improves speed.
                var service = FirefoxDriverService.CreateDefaultService();
                service.Host = "::1";

                var driver = new FirefoxDriver(service, firefoxOptions, commandTimeout);
                SetBrowserSize(driver, size);

                return driver;
            }));
        }
Пример #26
0
        public void TestCase5()
        {
            Console.WriteLine("Multiple select");
            FirefoxDriverService service = FirefoxDriverService.CreateDefaultService(@"D:\Wirtek work\Automation\Curs Automation 2018 - Gabriel Carabat\GIT\csharp_automation\Homeworks\Cristian Olariu\Lectia3\Lectia3\Lectia3");
            FirefoxOptions       options = new FirefoxOptions();
            IWebDriver           driver  = new FirefoxDriver(service, options, TimeSpan.FromMinutes(1));

            driver.Navigate().GoToUrl("https://www.seleniumeasy.com/test/table-pagination-demo.html");
            Task.Delay(2000).Wait();
            Console.WriteLine("The page title is: \r\t- " + driver.Title);
            Console.WriteLine("The Cells are: ");
            foreach (IWebElement element in driver.FindElements(By.ClassName("panel-heading")))
            {
                Console.WriteLine("\t- " + element.Text);
            }
            driver.Quit();
        }
Пример #27
0
        public void TestCase1()
        {
            Console.WriteLine("GoGo test 1");
            FirefoxDriverService service = FirefoxDriverService.CreateDefaultService(@"D:\Wirtek work\Automation\Curs Automation 2018 - Gabriel Carabat\GIT\csharp_automation\Homeworks\Cristian Olariu\Lectia3\Lectia3\Lectia3");
            FirefoxOptions       options = new FirefoxOptions();
            IWebDriver           driver  = new FirefoxDriver(service, options, TimeSpan.FromMinutes(1));

            driver.Navigate().GoToUrl("https://www.seleniumeasy.com/test/basic-first-form-demo.html");
            Task.Delay(2000).Wait();
            driver.FindElement(By.Id("user-message")).SendKeys("ASP.NET");
            driver.FindElement(By.ClassName("btn-default")).Click();
            string actualvalue = driver.FindElement(By.Id("display")).Text;

            Assert.IsTrue(actualvalue.Contains("ASP.NET"), actualvalue + " doesn't contains 'ASP.NET'");
            Task.Delay(2000).Wait();
            driver.Quit();
        }
Пример #28
0
        public void BooksList1()
        {
            //stworzenie listy książek na podstawie otrzymanych danych
            List <BooksObject> booksList = BA.BookList();

            //przejście do stronki
            service = FirefoxDriverService.CreateDefaultService();
            service.FirefoxBinaryPath = @"C:\Program Files\Mozilla Firefox\firefox.exe";
            driver = new FirefoxDriver(service);
            driver.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(10);//PRĘDKOŚć SKRYPTU
            driver.Navigate().GoToUrl(REPO.side);
            driver.Manage().Window.Maximize();
            //przejście do listy książek
            driver.FindElement(REPO.TB_UpMain_books).Click();

            //porównywaie listy z tym co jest wyświetlane przez książkę
            for (int i = 0, j = 0; i < booksList.Count; i++, j++)
            {
                //wszystkie stringi opisujące książkę
                string bookTitle  = booksList[i].title;
                string bookAuthor = booksList[i].author;
                string bookGenre  = booksList[i].genre;
                string bookID     = "book-" + (i + 1).ToString();

                //sprawdzenie, czy książka się wyświetla

                string xPath1 = "//td[contains(.,'" + bookAuthor + "')]/parent::tr/td[contains(.,'" + bookGenre + "')]/parent::tr/*/a[contains(.,'" + bookTitle + "')]";
                driver.FindElement(By.XPath(xPath1));


                //sprawdzenie, czy to juz nie jest ostatni element z listy
                if (i == booksList.Count - 1)
                {
                    driver.Quit();
                    Assert.Pass();
                }


                //przejście do następnej strony listy
                if (j == 9)
                {
                    j = -1;//-1 bo po zakonczeniu pętli będzie podniesione o 1, a ma startować od 0
                    driver.FindElement(REPO.BT_book_nextPage).Click();
                }
            }
        }
Пример #29
0
        internal void SelectBrowser(BrowserType browserType)
        {
            switch (browserType)
            {
            case BrowserType.Chrome:
                ChromeOptions option = new ChromeOptions();
                //option.AddArgument("--headless");
                _driver = new ChromeDriver(option);
                _objectContainer.RegisterInstanceAs <IWebDriver>(_driver);
                break;

            case BrowserType.AndroidApp:

                DesiredCapabilities cap = new DesiredCapabilities();
                cap.SetCapability("platformName", "Android");
                cap.SetCapability("deviceName", "donatello");
                // cap.SetCapability("appPackage", "com.sabithpkcmnr.admobintegration");
                cap.SetCapability("appPackage", "meteor.test.and.grade.internet.connection.speed");
                // cap.SetCapability("appActivity", "com.sabithpkcmnr.admobintegration.MainActivity");
                cap.SetCapability("appActivity", "meteor.test.and.grade.internet.connection.speed.activities.WelcomeActivity");
                cap.SetCapability("automationName", "Appium");
                cap.SetCapability(MobileCapabilityType.App, "C:\\Users\\E003755\\Downloads\\Metero.apk");

                driver = new AndroidDriver <IWebElement>(new Uri("http://127.0.0.1:4723/wd/hub"), cap);
                _objectContainer.RegisterInstanceAs <IWebDriver>(driver);

                break;

            case BrowserType.Firefox:
                var driverDir = System.IO.Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
                FirefoxDriverService service = FirefoxDriverService.CreateDefaultService(driverDir, "geckodriver.exe");
                service.FirefoxBinaryPath       = @"C:\Program Files (x86)\Mozilla Firefox\firefox.exe";
                service.HideCommandPromptWindow = true;
                service.SuppressInitialDiagnosticInformation = true;
                _driver = new FirefoxDriver(service);
                _objectContainer.RegisterInstanceAs <IWebDriver>(_driver);
                break;

            case BrowserType.IE:
                break;

            default:
                break;
            }
        }
Пример #30
0
        public static IWebDriver GetDriver(BrowserType type, int timeOutSec)
        {
            IWebDriver driver = null;

            switch (type)
            {
            case BrowserType.Chrome:
            {
                var service = ChromeDriverService.CreateDefaultService();
                var option  = new ChromeOptions();
                option.AddArgument("disable-infobars");
                driver = new ChromeDriver(service, option, TimeSpan.FromSeconds(timeOutSec));
                break;
            }

            case BrowserType.Firefox:
            {
                var service = FirefoxDriverService.CreateDefaultService();
                var options = new FirefoxOptions();
                options.SetPreference("permissions.default.image", 2);
                options.AddArguments("-private");
                driver = new FirefoxDriver(service, options);
                break;
            }

            case BrowserType.RemoteFirefox:
            {
                var option = new FirefoxOptions();
                option.AddArgument("disable-infobars");
                option.AddArgument("--no-sandbox");
                driver = new RemoteWebDriver(new Uri("http://null"), option.ToCapabilities());
                break;
            }

            case BrowserType.RemoteChrome:
            {
                var option = new ChromeOptions();
                option.AddArgument("disable-infobars");
                option.AddArgument("--no-sandbox");
                driver = new RemoteWebDriver(new Uri("http://null"), option.ToCapabilities());
                break;
            }
            }
            return(driver);
        }