Пример #1
0
        public static Tuple <Thread, IWebDriver> GetFirefoxDriverHidden(out DriverService firefoxDriverService,
                                                                        IntPtr containerHandle,
                                                                        Action <IntPtr> setFirefoxWindow)
        {
            WindowCreationHookerByClassName windowCreationHookerByClassName = WindowCreationHookerByClassName.GetInstance("MozillaWindowClass");

            void InstanceFirefowWindowCreated(object sender, WindowHookEventArgs e)
            {
                Win32Interop.SetParent(e.Handle, containerHandle);
                setFirefoxWindow(e.Handle);
                windowCreationHookerByClassName.Dispose();
            }

            var process = new ByRef <Process>();

            windowCreationHookerByClassName
            .HookFirefoxCreation(process, InstanceFirefowWindowCreated);

            var referenceContainer = new ReferenceContainer <Tuple <Thread, IWebDriver> >();

            firefoxDriverService = FirefoxDriverService.CreateDefaultService();
            firefoxDriverService.HideCommandPromptWindow = true;
            var options = new FirefoxOptions();

            options.AddArgument("--url about:blank");

            //var tuple = new Tuple<Func<IEnumerable<IntPtr>>, string>(FirefoxWindowFinder.FirefoxWindows,
            //    "Mozilla Firefox");

            var firefoxDriverHidden = new FirefoxDriver((FirefoxDriverService)firefoxDriverService, options,
                                                        TimeSpan.FromSeconds(30));

            var capabilities = firefoxDriverHidden.Capabilities;
            var processId    = Convert.ToInt32(capabilities.GetCapability("moz:processID"));

            if (processId != 0)
            {
                var byId = Process.GetProcessById(processId);
                process.Value = byId;
            }
            //if(mainWindowHandle == null)
            //    findBrowserWindow = FindBrowserWindow(setFirefoxWindow, tuple);

            var driverHidden = new Tuple <Thread, IWebDriver>(windowCreationHookerByClassName.Thread, firefoxDriverHidden);

            referenceContainer.Value = driverHidden;
            return(referenceContainer.Value);
        }
Пример #2
0
        public void go()
        {
            //System.Environment.SetEnvironmentVariable("webdriver.firefox.marionette", "@C:\\Projects\\WordpressAuto\\WordpressAuto\\bin\\geckodriver.exe");
            //IWebDriver driver = new FirefoxDriver();
            //driver.Navigate().GoToUrl("http://google.com");

            FirefoxDriverService service = FirefoxDriverService.CreateDefaultService(@"C:\\Projects\\WordpressAuto\\WordpressAuto\\bin", "geckodriver.exe");

            service.Port = 64444;
            service.FirefoxBinaryPath = @"C:\\Program Files\Mozilla Firefox\\firefox.exe";
            var driver             = new FirefoxDriver(service);
            var baseURL            = "http://localhost:49539";
            var verificationErrors = new StringBuilder();

            driver.Navigate().GoToUrl("http://www.google.com");
        }
        /// <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);
            }
        }
Пример #4
0
        private static IWebDriver GetFirefoxDriver()
        {
            if (ConfigurationManager.AppSettings["REMOTE_DRIVER"].Equals("true"))
            {
                FirefoxOptions firefoxOptions = new FirefoxOptions();
                return(Driver = new RemoteWebDriver(new Uri(ConfigurationManager.AppSettings["URL_REMOTE"]), firefoxOptions.ToCapabilities(), TimeSpan.FromSeconds(300)));
            }

            FirefoxDriverService service = FirefoxDriverService.CreateDefaultService(pathFirefoxDriver);
            FirefoxOptions       options = new FirefoxOptions();

            options.BrowserExecutableLocation = @"C:\Program Files\Mozilla Firefox\firefox.exe";
            options.SetPreference("intl.accept_languages", "en-us");

            return(Driver = new FirefoxDriver(service, options, TimeSpan.FromMinutes(1)));
        }
Пример #5
0
        public void TestCase9()
        {
            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.Manage().Window.Maximize();
            driver.Navigate().GoToUrl("https://money.rediff.com/gainers/bsc/daily/groupa");

            //Console.WriteLine("Number of columns: " + nrColoane);
            //int nrRanduri;
            //nrRanduri = driver.FindElements(By.XPath("//*[@id=\"myTable\"]/tr[*]")).Count();
            //Console.WriteLine("Number of columns: " + nrRanduri);
            driver.Quit();
        }
Пример #6
0
        public void Firefox()
        {
            _firefoxService      = FirefoxDriverService.CreateDefaultService(_buildPath);
            _firefoxService.Host = "::1";

            var options = new FirefoxOptions()
            {
                AcceptInsecureCertificates = true
            };

            options.SetPreference("media.navigator.streams.fake", true);
            options.SetPreference("media.navigator.permission.disabled", true);
            _driver = new FirefoxDriver(_firefoxService, options);

            RunTest();
        }
Пример #7
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);
        }
Пример #8
0
        public DownloadGamesTests()
        {
            var geckoService = FirefoxDriverService.CreateDefaultService(Environment.CurrentDirectory);

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

            _driver      = new FirefoxDriver(geckoService, firefoxOptions);
            _page        = new GameLibraryPage(_driver, "/Library");
            _loginHelper = new LoginHelper(_driver);

            _page.Navigate();
        }
Пример #9
0
            public void SetUp()
            {
                // set up the webdriver for selenium
                var timespan = TimeSpan.FromMilliseconds(TimeoutMillis);
                var service  = string.IsNullOrEmpty(DriverPath)
                    ? FirefoxDriverService.CreateDefaultService()
                    : FirefoxDriverService.CreateDefaultService(DriverPath);

                _webdriver = new FirefoxDriver(service, new FirefoxOptions(), timespan);
                _webdriver.Manage().Timeouts().ImplicitWait = timespan;

                // configure mailslurp with API Key
                Assert.NotNull(YourApiKey);
                _mailslurpConfig = new Configuration();
                _mailslurpConfig.ApiKey.Add("x-api-key", YourApiKey);
            }
        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);
        }
Пример #11
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);
        }
Пример #12
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);
        }
Пример #13
0
 private void GoToAccessibility_Course(object sender, EventArgs e)
 {
     if (chrome == null)
     {
         //Open the browser to be controlled
         var manager   = new FirefoxProfileManager();
         var ffProfile = manager.GetProfile("default");
         var fds       = FirefoxDriverService.CreateDefaultService(MainWindow.panelOptions.FirefoxDriverPath);
         fds.HideCommandPromptWindow = true;
         var options = new FirefoxOptions();
         options.Profile = ffProfile;
         chrome          = new FirefoxDriver(fds, options);
         wait            = new WebDriverWait(chrome, new TimeSpan(0, 0, 10));
     }
     chrome.Url = "https://byu.instructure.com/courses/1026";
 }
Пример #14
0
        public PreferencesTests()
        {
            var geckoService = FirefoxDriverService.CreateDefaultService(Environment.CurrentDirectory);

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

            _driver      = new FirefoxDriver(geckoService, firefoxOptions);
            _page        = new PreferencesPage(_driver, "Settings/Preferences");
            _loginHelper = new LoginHelper(_driver);

            _page.Navigate();
        }
Пример #15
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);
        }
Пример #16
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;
            }
        }
        /// <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);
        }
Пример #18
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);
        }
Пример #19
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;
            }
        }
Пример #20
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);
        }
Пример #21
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)));
        }
Пример #22
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;
            }
        }
Пример #23
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();
        }
Пример #24
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();
                }
            }
        }
Пример #25
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);
        }
        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);
        }
Пример #27
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();
        }
Пример #28
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;
            }));
        }
Пример #29
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));
        }
Пример #30
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();
        }