/// <summary>
        /// construct an ActionManager
        /// </summary>
        /// <param name="parent">the Automation object</param>
        public SeleniumActionManager(IAutomation parent, Browser browser)
            : base(parent)
        {
            switch (browser)
            {
                case Browser.Chrome:
                    {
                        OpenQA.Selenium.Chrome.ChromeDriverService service = OpenQA.Selenium.Chrome.ChromeDriverService.CreateDefaultService();
                        service.HideCommandPromptWindow = true;
                        WebDriver = new OpenQA.Selenium.Chrome.ChromeDriver(service, new OpenQA.Selenium.Chrome.ChromeOptions());
                        break;
                    }
                case Browser.FireFox:
                    WebDriver = new OpenQA.Selenium.Firefox.FirefoxDriver();
                    break;
                case Browser.Safari:
                    WebDriver = new OpenQA.Selenium.Safari.SafariDriver();
                    break;
                default:
                    WebDriver = new OpenQA.Selenium.IE.InternetExplorerDriver();
                    break;
            };
            WebDriver.Manage().Timeouts().ImplicitlyWait(WaitTime);

            RegisterAction(new ActionClick(WebDriver));
            RegisterAction(new ActionOpenURL(WebDriver));
            RegisterAction(new ActionRefresh(WebDriver));
            RegisterAction(new ActionGoBack(WebDriver));
            RegisterAction(new ActionEnter(WebDriver));

            RegisterAction(new ActionCheckControlProperty(WebDriver));
            RegisterAction(new ActionSet(WebDriver));
        }
Example #2
0
        internal static IWebDriver LaunchBrowser(Type browser)
        {
            switch (browser)
            {
            case Type.CHROME:
                Driver = new OpenQA.Selenium.Chrome.ChromeDriver();
                break;

            case Type.FIREFOX:
                Driver = new OpenQA.Selenium.Firefox.FirefoxDriver();
                break;

            case Type.IE:
                Driver = new OpenQA.Selenium.IE.InternetExplorerDriver();
                break;

            case Type.SAFARI:
                Driver = new OpenQA.Selenium.Safari.SafariDriver();
                break;

            default:
                throw new ApplicationException("No appropriate browser driver was provided.");
            }
            return(Driver);
        }
        /// <summary>
        /// construct a Selenium Action Manager with an Automation Engine
        /// </summary>
        /// <param name="automation">the Automation Engine</param>
        public SeleniumActionManager(abt.Automation automation, Browser browser)
            : base(automation)
        {
            switch (browser)
            {
                case Browser.Chrome:
                    {
                        OpenQA.Selenium.Chrome.ChromeDriverService service = OpenQA.Selenium.Chrome.ChromeDriverService.CreateDefaultService();
                        service.HideCommandPromptWindow = true;
                        WebDriver = new OpenQA.Selenium.Chrome.ChromeDriver(service, new OpenQA.Selenium.Chrome.ChromeOptions());
                        break;
                    }
                case Browser.FireFox:
                    WebDriver = new OpenQA.Selenium.Firefox.FirefoxDriver();
                    break;
                case Browser.Safari:
                    WebDriver = new OpenQA.Selenium.Safari.SafariDriver();
                    break;
                default:
                    WebDriver = new OpenQA.Selenium.IE.InternetExplorerDriver();
                    break;
            };
            WebDriver.Manage().Timeouts().ImplicitlyWait(new TimeSpan(0, 0, 30));

            RegisterAction(new ActionClick(WebDriver));
            RegisterAction(new ActionOpenURL(WebDriver));
            RegisterAction(new ActionRefresh(WebDriver));
            RegisterAction(new ActionGoBack(WebDriver));
        }
        public void Initialize()
        {
            RemoteWebDriver driver = new OpenQA.Selenium.IE.InternetExplorerDriver();

            selenium = new WebDriverBackedSelenium(driver, "http://localhost/SiteStarter");

            selenium.Start();
            verificationErrors = new StringBuilder();
        }
        public void Initialize()
        {
            RemoteWebDriver driver = new OpenQA.Selenium.IE.InternetExplorerDriver();

            selenium = new WebDriverBackedSelenium(driver, "http://localhost/SiteStarter");

            selenium.Start();
            verificationErrors = new StringBuilder();
        }
 public void TestMethod_IE_Opening()
 {
     using (IWebDriver webdriver = new OpenQA.Selenium.IE.InternetExplorerDriver(@"drivers"))
     {
         webdriver.Navigate().GoToUrl("about:blank");
         Assert.AreEqual("about:blank", webdriver.Url);
         webdriver.Quit();
     }
 }
        public override void RunCommand(object sender)
        {
            var engine         = (Core.Automation.Engine.AutomationEngineInstance)sender;
            var driverPath     = System.IO.Path.Combine(System.IO.Path.GetDirectoryName(System.Windows.Forms.Application.ExecutablePath), "Resources");
            var seleniumEngine = v_EngineType.ConvertToUserVariable(sender);
            var instanceName   = v_InstanceName.ConvertToUserVariable(sender);

            OpenQA.Selenium.DriverService driverService;
            OpenQA.Selenium.IWebDriver    webDriver;

            if (seleniumEngine == "Chrome")
            {
                OpenQA.Selenium.Chrome.ChromeOptions options = new OpenQA.Selenium.Chrome.ChromeOptions();

                if (!string.IsNullOrEmpty(v_SeleniumOptions))
                {
                    var convertedOptions = v_SeleniumOptions.ConvertToUserVariable(sender);
                    options.AddArguments(convertedOptions);
                }

                driverService = OpenQA.Selenium.Chrome.ChromeDriverService.CreateDefaultService(driverPath);
                webDriver     = new OpenQA.Selenium.Chrome.ChromeDriver((OpenQA.Selenium.Chrome.ChromeDriverService)driverService, options);
            }
            else
            {
                driverService = OpenQA.Selenium.IE.InternetExplorerDriverService.CreateDefaultService(driverPath);
                webDriver     = new OpenQA.Selenium.IE.InternetExplorerDriver((OpenQA.Selenium.IE.InternetExplorerDriverService)driverService, new OpenQA.Selenium.IE.InternetExplorerOptions());
            }


            //add app instance
            engine.AddAppInstance(instanceName, webDriver);


            //handle app instance tracking
            if (v_InstanceTracking == "Keep Instance Alive")
            {
                GlobalAppInstances.AddInstance(instanceName, webDriver);
            }

            //handle window type on startup - https://github.com/saucepleez/taskt/issues/22
            switch (v_BrowserWindowOption)
            {
            case "Maximize":
                webDriver.Manage().Window.Maximize();
                break;

            case "Normal":
            case "":
            default:
                break;
            }
        }
        static void Main(string[] args)
        {
            // Please keep your IE configuration settings:
            // 1. Check on "Enable Protected Mode" at ALL zones in "Security" tab of Internet Options dialog.
            // 2. Browser zoom level keep to 100%.
            using (var driver = new OpenQA.Selenium.IE.InternetExplorerDriver())
            {
                driver.Navigate().GoToUrl("https://www.bing.com/");
                driver.FindElementById("sb_form_q").SendKeys("Selenium WebDriver");
                driver.FindElementById("sb_form_go").Click();

                Console.WriteLine("OK");
                Console.ReadKey(intercept: true);
            }
        }
Example #9
0
        public void TestMethod2()
        {
            string userInput1 = "12";
            string userInput2 = "10";
            var    driver     = new OpenQA.Selenium.IE.InternetExplorerDriver();

            driver.Navigate().GoToUrl("http://localhost/demo/test");
            driver.FindElementByXPath("//*[@id='Value1']").SendKeys(userInput1);
            driver.FindElementByXPath("//*[@id='Value2']").SendKeys(userInput2);
            driver.FindElementByXPath("/html/body/div[2]/form/div/div[3]/div/input").SendKeys(OpenQA.Selenium.Keys.Enter);
            Thread.Sleep(2000);
            var result = driver.FindElementByXPath("/html/body/div[2]/h2").Text;

            Assert.AreEqual("22", result);
            driver.Dispose();
        }
Example #10
0
        public void TipTest()
        {
            RemoteWebDriver driver = new OpenQA.Selenium.IE.InternetExplorerDriver();
               driver.Url = "www.tourol.com";
             //  driver.Manage().Timeouts().SetPageLoadTimeout(new TimeSpan(1000));
               string tbxKeyword = "tbxKeywords";
               string btnSearchID="btnSearch";
               string tipMsg = "输入景区或景点名称";
               IWebElement element = driver.FindElementById(tbxKeyword);
               Assert.AreEqual(tipMsg,element.GetAttribute("value"));
               element.Click();
               Assert.AreEqual(string.Empty, element.GetAttribute("value"));
               string searchWord="杭州";
               element.SendKeys(searchWord);
               Assert.AreEqual(searchWord, element.GetAttribute("value"));
               driver.Mouse.Click(((RemoteWebElement)element).Coordinates);

               Assert.AreEqual(searchWord, element.GetAttribute("value"));
        }
Example #11
0
        private QA.IWebDriver InitWebDriver()
        {
            QA.IWebDriver theDriver = null;
            switch (this.browser)
            {
            case Browsers.IE:
            {
                QA.IE.InternetExplorerOptions _ieOptions = new QA.IE.InternetExplorerOptions();
                _ieOptions.IntroduceInstabilityByIgnoringProtectedModeSettings = true;
                theDriver = new QA.IE.InternetExplorerDriver(_ieOptions);
            }; break;

            case Browsers.Chrome:
            {
                theDriver = new QA.Chrome.ChromeDriver();
            }; break;

            case Browsers.Firefox:
            {
                theDriver = new QA.Firefox.FirefoxDriver();
            }; break;

            case Browsers.Safari:
            {
                theDriver = new QA.Safari.SafariDriver();
            }; break;

            case Browsers.PhantomJS:
            {
                theDriver = new QA.PhantomJS.PhantomJSDriver();
            }; break;

            default:
            {
                QA.IE.InternetExplorerOptions _ieOptions = new QA.IE.InternetExplorerOptions();
                _ieOptions.IntroduceInstabilityByIgnoringProtectedModeSettings = true;
                theDriver = new QA.IE.InternetExplorerDriver(_ieOptions);
            }; break;
            }
            return(theDriver);
        }
Example #12
0
        private IWebDriver getCurrentDriver()
        {
            OpenQA.Selenium.Remote.RemoteWebDriver driver = null;

            switch (_browserType)
            {
            case API.Enumerations.BrowserType.InternetExplorer:
                driver = new OpenQA.Selenium.IE.InternetExplorerDriver();
                break;

            case API.Enumerations.BrowserType.Firefox:
                driver = new OpenQA.Selenium.Firefox.FirefoxDriver();
                break;

            case API.Enumerations.BrowserType.Chrome:
                driver = new OpenQA.Selenium.Chrome.ChromeDriver();
                break;
            }

            driver.Manage().Cookies.DeleteAllCookies();

            return(driver);
        }
        public void BrowserAutoComplete(LoginCard card)
        {
            string browser     = IdentifyDefaultBrowser();
            string target_name = "";

            OpenQA.Selenium.IWebDriver driver = null;

            switch (browser)
            {
            case "Firefox": { driver = new OpenQA.Selenium.Firefox.FirefoxDriver(); target_name = "geckodriver"; break; }

            case "Chrome": { driver = new OpenQA.Selenium.Chrome.ChromeDriver(); target_name = "chromedriver"; break; }

            case "Edge": { driver = new OpenQA.Selenium.Edge.EdgeDriver(); target_name = "MicrosoftWebDriver"; break; }

            default: { driver = new OpenQA.Selenium.IE.InternetExplorerDriver(); target_name = "IEDriverServer"; break; }
            }

            try
            {
                driver.Navigate().GoToUrl(card.SiteURL);
                driver.FindElement(By.Name(card.LogElem)).Clear();
                driver.FindElement(By.Name(card.LogElem)).SendKeys(card.Login);
                driver.FindElement(By.Name(card.PassElem)).Clear();
                driver.FindElement(By.Name(card.PassElem)).SendKeys(card.Password);
            }
            catch
            { }

            try
            {
                System.Diagnostics.Process[] local_procs = System.Diagnostics.Process.GetProcesses();
                System.Diagnostics.Process   target_proc = local_procs.First(p => p.ProcessName == target_name);
                target_proc.Kill();
            }
            catch { }
        }
Example #14
0
        public IWebDriver GetWebDriver(WebDriverParameters parameters)
        {
            IWebDriver driver = null;
            var desiredCaps = new DesiredCapabilities();

            foreach (var cap in parameters.capabilities)
            {
                desiredCaps.SetCapability(cap.Key, cap.GetValue());
            }
            //desiredCaps.SetCapability(CapabilityType.Platform, new Platform(GetPlatformTypeFromString(parameters.platform)));
            //desiredCaps.SetCapability(CapabilityType.BrowserName, parameters.browserName);
            //if (parameters.version != string.Empty)
            //{
            //    desiredCaps.SetCapability(CapabilityType.Version, parameters.version);
            //}
            var ieOptions = new OpenQA.Selenium.IE.InternetExplorerOptions();
            ieOptions.IgnoreZoomLevel = true;
            ieOptions.UnexpectedAlertBehavior = OpenQA.Selenium.IE.InternetExplorerUnexpectedAlertBehavior.Accept;

            var chromeOptions = new OpenQA.Selenium.Chrome.ChromeOptions();
            chromeOptions.AddAdditionalCapability("unexpectedAlertBehaviour", "Accept");

            switch (parameters.browserName.ToUpperInvariant())
            {
                case "CHROME":
                    driver = new OpenQA.Selenium.Chrome.ChromeDriver(chromeOptions);
                    break;
                case "ANDROIDCHROME":
                    driver = new OpenQA.Selenium.Chrome.ChromeDriver(chromeOptions);
                    break;
                case "IE":
                    driver = new OpenQA.Selenium.IE.InternetExplorerDriver(ieOptions);
                    break;
                case "FIREFOX":
                    driver = new OpenQA.Selenium.Firefox.FirefoxDriver(desiredCaps);
                    break;
            }

            //driver.S(CapabilityType.UNEXPECTED_ALERT_BEHAVIOUR, UnexpectedAlertBehaviour.ACCEPT);

            return driver;
        }
Example #15
0
        static void Main(string[] args)
        {
            var driver = new OpenQA.Selenium.IE.InternetExplorerDriver();

            driver.Navigate().GoToUrl("https://http.cat/200");
        }
Example #16
0
        private void Form1_Shown(object sender, EventArgs e)
        {
            //Variaveis
            IWebDriver driver = null;
            int        ToRow  = 0;
            int        ToCol  = 0;
            string     munc   = string.Empty;
            string     uf     = string.Empty;

            try
            {
                #region browser

                string url = @"https://e-gov.betha.com.br/e-nota/pesquisa_prestadores.faces";

                Browser browser = (Browser)Enum.Parse(typeof(Browser), ConfigurationManager.AppSettings["selenium_webdriver"].ToString());

                switch (browser)
                {
                case Browser.Chrome:
                {
                    //Create FireFox Service
                    OpenQA.Selenium.Chrome.ChromeDriverService chromeService = OpenQA.Selenium.Chrome.ChromeDriverService.CreateDefaultService();
                    chromeService.HideCommandPromptWindow = true;
                    chromeService.SuppressInitialDiagnosticInformation = true;
                    //Create FireFox Profile object
                    OpenQA.Selenium.Chrome.ChromeOptions chromeOptions = new OpenQA.Selenium.Chrome.ChromeOptions();
                    chromeOptions.AddArguments(string.Concat("--app=", url));
                    driver = new OpenQA.Selenium.Chrome.ChromeDriver(chromeService, chromeOptions);
                }
                break;

                case Browser.Edge:
                    driver = new OpenQA.Selenium.Edge.EdgeDriver();
                    break;

                case Browser.Firefox:
                {
                    //Create FireFox Service
                    OpenQA.Selenium.Firefox.FirefoxDriverService firefoxService = OpenQA.Selenium.Firefox.FirefoxDriverService.CreateDefaultService(string.Concat(Application.StartupPath, @"\Selenium\Firefox"));
                    firefoxService.HideCommandPromptWindow = true;
                    firefoxService.SuppressInitialDiagnosticInformation = true;
                    //Create FireFox Profile object
                    OpenQA.Selenium.Firefox.FirefoxOptions firefoxOptions = new OpenQA.Selenium.Firefox.FirefoxOptions();
                    driver = new OpenQA.Selenium.Firefox.FirefoxDriver(firefoxService, firefoxOptions);
                    driver.Navigate().GoToUrl(url);
                }
                break;

                case Browser.InternetExplorer:
                {
                    //Create FireFox Service
                    OpenQA.Selenium.IE.InternetExplorerDriverService InternetExplorerService = OpenQA.Selenium.IE.InternetExplorerDriverService.CreateDefaultService(string.Concat(Application.StartupPath, @"\Selenium\InternetExplorerDriver"));
                    InternetExplorerService.HideCommandPromptWindow = true;
                    InternetExplorerService.SuppressInitialDiagnosticInformation = true;
                    //Create FireFox Profile object
                    OpenQA.Selenium.IE.InternetExplorerOptions InternetExplorerOptions = new OpenQA.Selenium.IE.InternetExplorerOptions();
                    driver = new OpenQA.Selenium.IE.InternetExplorerDriver(InternetExplorerService, InternetExplorerOptions);
                    driver.Navigate().GoToUrl(url);
                }
                break;

                case Browser.Opera:
                {
                    //Create FireFox Service
                    OpenQA.Selenium.Opera.OperaDriverService OperaService = OpenQA.Selenium.Opera.OperaDriverService.CreateDefaultService(string.Concat(Application.StartupPath, @"\Selenium\Opera"));
                    OperaService.HideCommandPromptWindow = true;
                    OperaService.SuppressInitialDiagnosticInformation = true;
                    //Create FireFox Profile object
                    OpenQA.Selenium.Opera.OperaOptions OperaOptions = new OpenQA.Selenium.Opera.OperaOptions();
                    driver = new OpenQA.Selenium.Opera.OperaDriver(OperaService, OperaOptions);
                    driver.Navigate().GoToUrl(url);
                }
                break;

                default:
                    throw new NotSupportedException(string.Format(System.Globalization.CultureInfo.CurrentCulture, "Driver {0} não suportado", browser));
                }

                if (driver == null)
                {
                    throw new Exception("WebDriver do Selenium não definido nas configurações");
                }

                #endregion browser

                //Aguarda processamento da página 5min
                WebDriverWait wait = new WebDriverWait(driver, TimeSpan.FromSeconds(60));

                //Arquivo
                FileInfo fileInfo = new FileInfo(string.Format(@"{0}\Prestadores.xls", Application.StartupPath));
                if (fileInfo.Exists)
                {
                    fileInfo.Delete();
                }

                using (ExcelPackage package = new ExcelPackage(fileInfo))
                {
                    try
                    {
                        #region UF

                        for (int i = 1; i < driver.FindElement(By.Id("mainForm:estado")).FindElements(By.TagName("option")).Count; i++)
                        {
                            try
                            {
                                if (i != 11)
                                {
                                    continue;
                                }

                                //Variaveis
                                ToRow = 1;
                                ToCol = 8; //Total de colunas
                                munc  = string.Empty;
                                uf    = string.Empty;

                                System.Threading.Thread.Sleep(1500);

                                //Seleciona UF
                                driver.FindElement(By.Id("mainForm:estado")).FindElements(By.TagName("option"))[i].Click();
                                uf = driver.FindElement(By.Id("mainForm:estado")).FindElements(By.TagName("option"))[i].Text;

                                System.Threading.Thread.Sleep(500);

                                //Worksheet
                                ExcelWorksheet worksheet = package.Workbook.Worksheets.Add(uf.Trim());

                                #region Municipio

                                for (int j = 1; j < driver.FindElement(By.Id("mainForm:municipio")).FindElements(By.TagName("option")).Count; j++)
                                {
                                    try
                                    {
                                        //if(j != 61)
                                        //    continue;

                                        //Municipio
                                        driver.FindElement(By.Id("mainForm:municipio")).FindElements(By.TagName("option"))[j].Click();
                                        munc = driver.FindElement(By.Id("mainForm:municipio")).FindElements(By.TagName("option"))[j].Text;

                                        if (!driver.FindElement(By.Id("mainForm:master:messageSection:warn")).Displayed)
                                        {
                                            string html = driver.PageSource;
                                            if (!string.IsNullOrEmpty(html))
                                            {
                                                // Load From String
                                                var htmlDocument = new HtmlAgilityPack.HtmlDocument();
                                                htmlDocument.LoadHtml(html);

                                                bool blnPrestador = htmlDocument.GetElementbyId("mainForm:prestadores") == null ? false : true;

                                                do
                                                {
                                                    htmlDocument.LoadHtml(driver.PageSource);
                                                    blnPrestador = htmlDocument.GetElementbyId("mainForm:prestadores") == null ? false : true;
                                                } while (blnPrestador == false);

                                                var prestadores = htmlDocument.GetElementbyId("mainForm:prestadores");
                                                var tabela      = prestadores.SelectNodes("table");
                                                var linhas      = tabela.ElementAt(0).SelectNodes("tbody//tr");

                                                #region Add the headers row 1

                                                worksheet.Cells["A1"].Value = "Razão/Nome";
                                                worksheet.Cells["B1"].Value = "Logradouro";
                                                worksheet.Cells["C1"].Value = "Bairro";
                                                worksheet.Cells["D1"].Value = "Complemento";
                                                worksheet.Cells["E1"].Value = "CEP";
                                                worksheet.Cells["F1"].Value = "Email";
                                                worksheet.Cells["G1"].Value = "Telefone";
                                                worksheet.Cells["H1"].Value = "UF";
                                                worksheet.Cells["I1"].Value = "Municipio";

                                                //Format row header 1 style;
                                                using (var range = worksheet.Cells["A1:I1"])
                                                {
                                                    range.Style.Font.Bold        = true;
                                                    range.Style.Fill.PatternType = ExcelFillStyle.Solid;
                                                    range.Style.Font.Color.SetColor(Color.Black);
                                                    range.Style.Fill.BackgroundColor.SetColor(Color.FromArgb(198, 198, 198));
                                                    range.Style.VerticalAlignment   = ExcelVerticalAlignment.Center;
                                                    range.Style.HorizontalAlignment = ExcelHorizontalAlignment.Center;
                                                }

                                                #endregion Add the headers row 1

                                                #region Add some items in the cells

                                                foreach (HtmlNode linha in linhas)
                                                {
                                                    ToRow++;

                                                    foreach (HtmlNode campos in linha.SelectNodes("td"))
                                                    {
                                                        if (linha.SelectNodes("td").ElementAt(0).ChildNodes.ElementAt(0).HasChildNodes)
                                                        {
                                                            worksheet.Cells[ToRow, 1].Value = ConverterCaracteresEspeciais(linha.SelectNodes("td").ElementAt(0).ChildNodes.ElementAt(0).FirstChild.InnerText);
                                                            worksheet.Cells[ToRow, 2].Value = linha.SelectNodes("td").ElementAt(0).ChildNodes.ElementAt(3).InnerText.Replace("\n", "").Replace("\t", "").Replace("\r", "").Trim();
                                                            worksheet.Cells[ToRow, 3].Value = linha.SelectNodes("td").ElementAt(0).ChildNodes.ElementAt(5).InnerText.Replace("\n", "").Replace("\t", "").Replace("\r", "").Trim();
                                                            worksheet.Cells[ToRow, 4].Value = linha.SelectNodes("td").ElementAt(0).ChildNodes.ElementAt(7).InnerText.Replace("\n", "").Replace("\t", "").Replace("\r", "").Trim();
                                                            worksheet.Cells[ToRow, 5].Value = linha.SelectNodes("td").ElementAt(0).ChildNodes.ElementAt(9).InnerText.Replace("\n", "").Replace("\t", "").Replace("\r", "").Trim();
                                                        }

                                                        if (linha.SelectNodes("td").ElementAt(1).HasChildNodes)
                                                        {
                                                            worksheet.Cells[ToRow, 6].Value = linha.SelectNodes("td").ElementAt(1).ChildNodes.ElementAt(0).InnerText.Replace("\n", "").Replace("\t", "").Replace("\r", "").Trim();
                                                            worksheet.Cells[ToRow, 7].Value = linha.SelectNodes("td").ElementAt(1).ChildNodes.ElementAt(2).InnerText.Replace("\n", "").Replace("\t", "").Replace("\r", "").Trim();
                                                        }

                                                        string[] arr = uf.ToString().Split('-');

                                                        worksheet.Cells[ToRow, 8].Value = arr[0].Trim();
                                                        worksheet.Cells[ToRow, 9].Value = munc;
                                                    }
                                                }

                                                #endregion Add some items in the cells
                                            }
                                        }
                                    }
                                    catch (Exception ex) { throw; }
                                }

                                #endregion Municipio

                                #region Format type cells
                                //Format type cells
                                for (int fc = 0; fc < ToRow; fc++)
                                {
                                    //Row
                                    if (fc <= 1)
                                    {
                                        continue;
                                    }

                                    //Campos
                                    worksheet.Cells[fc, 1].Style.Numberformat.Format = "@";
                                    worksheet.Cells[fc, 2].Style.Numberformat.Format = "@";
                                    worksheet.Cells[fc, 3].Style.Numberformat.Format = "@";
                                    worksheet.Cells[fc, 4].Style.Numberformat.Format = "@";
                                    worksheet.Cells[fc, 5].Style.Numberformat.Format = "@";
                                    worksheet.Cells[fc, 6].Style.Numberformat.Format = "@";
                                    worksheet.Cells[fc, 7].Style.Numberformat.Format = "@";
                                    worksheet.Cells[fc, 8].Style.Numberformat.Format = "@";
                                }

                                #endregion Format type cells

                                if (ToRow == 1)
                                {
                                    worksheet = null;
                                    continue;
                                }

                                //Format the values
                                using (var range = worksheet.Cells[2, 1, ToRow, ToCol])
                                {
                                    range.Style.VerticalAlignment   = ExcelVerticalAlignment.Center;
                                    range.Style.HorizontalAlignment = ExcelHorizontalAlignment.Center;
                                }

                                //Create an autofilter for the range
                                worksheet.Cells[1, 1, ToRow, ToCol].AutoFilter = true;

                                //Excel line freeze
                                worksheet.View.FreezePanes(2, 1);

                                //Autofit columns for all cells
                                worksheet.Cells.AutoFitColumns(0);

                                //// Change the sheet view to show it in page layout mode
                                //worksheet.View.PageLayoutView = false;
                            }
                            catch { }
                        }

                        #endregion UF
                    }
                    catch (Exception ex)
                    {
                        if (driver != null)
                        {
                            driver.Dispose();
                        }
                    }
                    finally
                    {
                        // set some document properties
                        package.Workbook.Properties.Title = "Prestadore e-Notas";

                        // save our new workbook and we are done!
                        package.Save();
                    }
                }
            }
            catch (Exception)
            {
                if (driver != null)
                {
                    driver.Dispose();
                }
            }
            finally
            {
                if (driver != null)
                {
                    driver.Dispose();
                }
            }
        }
Example #17
0
 /// <summary>Starts a new Selenium testing session</summary>
 /// <param name="browser">Name of the browser : firefox, ie, chrome, phantomjs</param>
 /// <param name="baseUrl">The base URL</param>
 /// <param name="useLastSession">Optional - Try to use the previous session if the browser is still openned (Excel only)</param>
 /// <example>
 /// <code lang="vbs">	
 ///     WebDriver driver = New WebDriver()
 ///     driver.start "firefox", "http://www.google.com"
 ///     driver.open "/"
 /// </code>
 /// </example>
 public void start(string browser, String baseUrl = null, bool useLastSession = false) {
     if (useLastSession && CopyStaticDriver(baseUrl)) return;
     _isStartedRemotely = false;
     var dir = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location);
     DesiredCapabilities capa = new DesiredCapabilities(_capabilities);
     switch (browser.ToLower().Replace("*", "")) {
         case "firefox": case "ff":
             WebDriver = new OpenQA.Selenium.Firefox.FirefoxDriver(getFirefoxOptions());
             break;
         case "cr": case "chrome":
             ChromeDriverService crService = ChromeDriverService.CreateDefaultService(dir);
             crService.EnableVerboseLogging = false;
             crService.SuppressInitialDiagnosticInformation = true;
             crService.HideCommandPromptWindow = this._hideCommandPromptWindow;
             WebDriver = new OpenQA.Selenium.Chrome.ChromeDriver(crService, getChromeOptions());
             break;
         case "phantomjs": case "pjs":
             var pjsService = PhantomJSDriverService.CreateDefaultService(dir);
             pjsService.SuppressInitialDiagnosticInformation = true;
             pjsService.IgnoreSslErrors = true;
             pjsService.HideCommandPromptWindow = this._hideCommandPromptWindow;
             if(base._proxy != null)
                 pjsService.Proxy = base._proxy.HttpProxy;
             if(base._arguments != null)
                 pjsService.AddArguments(base._arguments);
             WebDriver = new OpenQA.Selenium.PhantomJS.PhantomJSDriver(pjsService, getPhantomJSOptions());
             break;
         case "internetexplorer": case "iexplore": case "ie":
         case "internetexplorer64": case "iexplore64": case "ie64":
             var ieService = OpenQA.Selenium.IE.InternetExplorerDriverService.CreateDefaultService(dir);
             ieService.SuppressInitialDiagnosticInformation = true;
             ieService.LoggingLevel = OpenQA.Selenium.IE.InternetExplorerDriverLogLevel.Error;
             ieService.HideCommandPromptWindow = this._hideCommandPromptWindow;
             WebDriver = new OpenQA.Selenium.IE.InternetExplorerDriver(ieService, getInternetExplorerOptions());
             break;
         case "safari": case "sa":
             WebDriver = new OpenQA.Selenium.Safari.SafariDriver(getSafariOptions());
             break;
         default:
             throw new ApplicationException("Browser <" + browser + "> is not available !  \nAvailable are Firefox, IE, Chrome, Safari and PhantomJS");
     }
     this.setTimeout(_timeout);
     if (!string.IsNullOrEmpty(baseUrl))
         _baseUrl = baseUrl.TrimEnd('/');
     _timerhotkey.Start();
 }