Example #1
0
        public void Selenium_ClickOnButtonIntoIFrame_WithActionClick_WithoutChangingPadding(string idButton, string alertText)
        {
            using (var webDriver = WebDriverHelper.CreateSession())
            {
                webDriver.ResizeWindow(SeleniumConfig.BrowserSize);
                webDriver.Navigate().GoToUrl(Path.Combine(ConfigHelper.GetCodeLocation(), _iframeWithComponents));
                var frame = webDriver.FindElement(OpenQA.Selenium.By.Id(_iframeId));
                webDriver.SwitchTo().Frame(frame);

                var element    = By.Id(idButton);
                var webElement = webDriver.FindElement(element);
                if (webElement.Displayed && webElement.Enabled)
                {
                    var action = new Actions(webDriver);
                    action.Click(webElement).Build().Perform();
                }

                var alert = webDriver.SwitchTo().Alert();
                Assert.IsNotNull(alert);
                var actualText = webDriver.SwitchTo().Alert().Text;


                Assert.AreEqual(alertText, actualText);
            }
        }
Example #2
0
        public void Selenium_ClickOnRadioButtonIntoIFrame_WithoutChangingPadding()
        {
            using (var webDriver = WebDriverHelper.CreateSession())
            {
                webDriver.ResizeWindow(SeleniumConfig.BrowserSize);
                webDriver.Navigate().GoToUrl(Path.Combine(ConfigHelper.GetCodeLocation(), _iframeWithComponents));
                var frame = webDriver.FindElement(OpenQA.Selenium.By.Id(_iframeId));
                webDriver.SwitchTo().Frame(frame);
                var element = new ByChained(By.XPath("//input[@name='sex'][@type='radio']"), By.XPath("./self::input[@value='male']"));

                var webElement = webDriver.FindElement(element);
                if (webElement.Displayed && webElement.Enabled)
                {
                    //webDriver.FindElement(element).Click();
                    var action = new Actions(webDriver);
                    action.Click(webElement).Build().Perform();
                }
                var    allElements   = webDriver.FindElements(By.XPath("//input[@name='sex'][@type='radio']"));
                string selectedValue = string.Empty;
                foreach (var el in allElements)
                {
                    if (el.Selected)
                    {
                        selectedValue = el.GetAttribute("value");
                    }
                }
                Assert.AreEqual("male", selectedValue);
            }
        }
Example #3
0
        public void Selenium_ClickOnButtonIntoIFrame_WithSimpleClick_WithChangingPadding(string idButton, string alertText)
        {
            using (var webDriver = WebDriverHelper.CreateSession())
            {
                webDriver.ResizeWindow(SeleniumConfig.BrowserSize);
                webDriver.Navigate().GoToUrl(Path.Combine(ConfigHelper.GetCodeLocation(), _iframeWithComponents));
                var frame = webDriver.FindElement(OpenQA.Selenium.By.Id(_iframeId));
                (webDriver as IJavaScriptExecutor).ExecuteScript($"document.getElementById('{_iframeId}').style.padding = 0");

                webDriver.SwitchTo().Frame(frame);

                var element    = By.Id(idButton);
                var webElement = webDriver.FindElement(element);
                if (webElement.Displayed && webElement.Enabled)
                {
                    webDriver.FindElement(element).Click();
                }

                var alert = webDriver.SwitchTo().Alert();
                Assert.IsNotNull(alert);
                var actualText = webDriver.SwitchTo().Alert().Text;


                Assert.AreEqual(alertText, actualText);
            }
        }
Example #4
0
        public static void Execute(this Step step, ref IWebDriver webDriver)
        {
            switch (step.Type)
            {
            case (StepType.CREATE_SESSION):
                webDriver = WebDriverHelper.CreateSession();
                webDriver.ResizeWindow(SeleniumConfig.BrowserSize);
                break;

            case (StepType.NAVIGATE_URL):
                webDriver.Url = step.Url;
                webDriver.Navigate().GoToUrl(step.Url);
                break;

            case (StepType.CLICK_BUTTON):
                break;

            case (StepType.TAKE_SCREENSHOT):
                break;

            case (StepType.RESIZE_WINDOW):
                webDriver.ResizeWindow(SeleniumConfig.BrowserSize);
                break;

            default:
                throw new NotImplementedException();
            }
        }
Example #5
0
        public static void Execute(this Step step, ref IWebDriver webDriver)
        {
            try
            {
                step.Measure.StartDate = DateTime.Now;
                switch (step.Type)
                {
                case (StepType.CREATE_SESSION):
                    webDriver = WebDriverHelper.CreateSession();
                    var sessionId = ((OpenQA.Selenium.Remote.RemoteWebDriver)webDriver).SessionId;
                    webDriver.ResizeWindow(SeleniumConfig.BrowserSize);
                    step.SessionId = sessionId.ToString();
                    break;

                case (StepType.NAVIGATE_URL):
                    //webDriver.Url = step.Param;
                    webDriver.Navigate().GoToUrl(step.Param);
                    break;

                case (StepType.CLICK_BUTTON):
                    webDriver.SmartClick(step.Selector);
                    break;

                case (StepType.SET_TEXT):
                    webDriver.SetText(step.Selector, step.Value);
                    break;

                case (StepType.ASSERT_TEXT):
                    webDriver.AssertTextEqual(step.Selector, step.Value);
                    break;

                case (StepType.TAKE_SCREENSHOT):
                    webDriver.TakeScreenshot(step.Value);
                    break;

                case (StepType.RESIZE_WINDOW):
                    webDriver.ResizeWindow(SeleniumConfig.BrowserSize);
                    break;

                case StepType.EXECUTE_SCENARIO:
                    throw new InvalidOperationException("Selenium launcher execute only elementary step");

                default:
                    throw new NotImplementedException();
                }
                step.Measure.EndDate = DateTime.Now;
            }
            catch (Exception ex)
            {
                step.Failed     = true;
                step.StackTrace = ex.Message;
                throw ex;
            }
        }
Example #6
0
        public static void Execute(this Step step, ref IWebDriver webDriver, ExecutionEnvironment executionEnvironment)
        {
            try
            {
                step.Measure.StartDate = DateTime.Now;
                _log_.Trace($"Begin Executing Step {step.Name} | {step.Param}| {step.Value} | {step.Measure.StartDate}");
                switch (step.Type)
                {
                case (StepType.CREATE_SESSION):
                {
                    webDriver = WebDriverHelper.CreateSession(executionEnvironment);
                    var sessionId  = ((OpenQA.Selenium.Remote.RemoteWebDriver)webDriver).SessionId;
                    var windowSize = ConvertStringToSize(step.Param);
                    webDriver.ResizeWindow(windowSize);
                    _log_.Trace($"Session created : {sessionId.ToString()}");
                    step.SessionId = sessionId.ToString();
                    break;
                }

                case (StepType.NAVIGATE_URL):
                    var url = UrlHelper.Combine(webDriver.Url, step.Param);
                    webDriver.Navigate().GoToUrl(url);
                    break;

                case (StepType.CLICK_BUTTON):
                    webDriver.SmartClick(step.Selector);
                    break;

                case (StepType.SET_TEXT):
                    webDriver.SetText(step.Selector, step.Value);
                    break;

                case (StepType.MOUSE_HOVER):
                    webDriver.MouseHover(step.Selector);
                    break;

                case (StepType.ASSERT_TEXT):
                    webDriver.AssertTextEqual(step.Selector, step.Value);
                    break;

                case (StepType.TAKE_SCREENSHOT):
                    webDriver.TakeScreenshot(step.Value, Path.Combine(executionEnvironment.OutputDirectoryLocation));
                    break;

                case (StepType.RESIZE_WINDOW):
                {
                    var windowSize = ConvertStringToSize(step.Param);
                    webDriver.ResizeWindow(windowSize);
                    break;
                }

                case (StepType.EXECUTE_JAVASCRIPT):
                    var result = webDriver.ExecuteJavaScript <string>(step.Param);
                    if (result != step.Value)
                    {
                        throw new Exception($"{step.Param} return {result} and not {step.Value} as expected.");
                    }
                    break;

                case (StepType.ASSERT_EXISTS):
                    webDriver.AssertExists(step.Selector);
                    break;

                case StepType.EXECUTE_SCENARIO:
                    throw new InvalidOperationException("Selenium launcher execute only elementary step");

                default:
                    throw new NotImplementedException();
                }
                step.Measure.EndDate = DateTime.Now;
                step.Failed          = false;
                _log_.Trace($"End Executing Step {step.Name} | {step.Measure.StartDate} - {step.Measure.EndDate}");
            }
            catch (Exception ex)
            {
                _log_.Trace($"End Executing Step with failure {step.Name} | {ex.Message}");
                step.Failed     = true;
                step.StackTrace = ex.Message;
                throw ex;
            }
        }
Example #7
0
        private static void RecupererSociete(string annee)
        {
            List <EntrepriseModel> entrepriseModels = new List <EntrepriseModel>();
            string rootUrlRNE       = "https://www.registre-entreprises.tn/search/";
            string urlRNE           = $"{rootUrlRNE}RCCSearch.do?action=getPage&rg_type=PM&search_mode=NORMAL";
            string urlRNENext       = $"{rootUrlRNE}RCCSearch.do?action=search&id=n";
            string urlRNEPrevious   = $"{rootUrlRNE}RCCSearch.do?action=search&id=p";
            string urlDetailsResult = $"{rootUrlRNE}RCCSearch.do?action=chooseDocuments&numRegistreIndex=";
            string urlBackToList    = $"{rootUrlRNE}RCCSearch.do?action=backToList";

            using (var webDriver = WebDriverHelper.CreateSession())
            {
                webDriver.ResizeWindow(SeleniumConfig.BrowserSize);
                webDriver.Navigate().GoToUrl(urlRNE);
                Thread.Sleep(500);
                var selectAnneeInsertion = webDriver.FindElement(By.Name("searchRegistrePmRcc.registrePm.demande.anneeInsertion"));
                selectAnneeInsertion.Click();
                var option2020 = selectAnneeInsertion.FindElement(By.XPath($"option[@value='{annee}']"));
                option2020.Click();
                var searchButton = webDriver.FindElement(By.XPath("//div[text() = 'Rechercher']"));
                searchButton.Click();

                bool isElementDisplayed = webDriver.FindElement(By.ClassName("search-result-jort")).Displayed;

                int indexFile = 0;

                while (webDriver.FindElement(By.ClassName("search-result-jort")).Displayed)
                {
                    var lignes = webDriver.FindElements(By.XPath("//table[@class='search-result-jort']/tbody/tr"));

                    for (int i = 0; i < lignes.Count(); i++)
                    {
                        webDriver.Navigate().GoToUrl(urlDetailsResult + $"{i}");

                        try
                        {
                            var entreprise = new EntrepriseModel();

                            if (webDriver.FindElement(By.ClassName("search-result-jort")).Displayed)
                            {
                                entreprise.IdentifiantUnique        = webDriver.FindElement(By.XPath("//table[contains(@class,'search-result-jort')]/tbody/tr[1]/td[2]")).Text;
                                entreprise.FormeJuridique           = webDriver.FindElement(By.XPath("//table[contains(@class,'search-result-jort')]/tbody/tr[2]/td[2]")).Text;
                                entreprise.FormeJuridiqueArabe      = webDriver.FindElement(By.XPath("//table[contains(@class,'search-result-jort')]/tbody/tr[2]/td[3]")).Text;
                                entreprise.EtatRegistre             = webDriver.FindElement(By.XPath("//table[contains(@class,'search-result-jort')]/tbody/tr[3]/td[2]")).Text;
                                entreprise.EtatRegistreArabe        = webDriver.FindElement(By.XPath("//table[contains(@class,'search-result-jort')]/tbody/tr[3]/td[3]")).Text;
                                entreprise.SituationFiscale         = webDriver.FindElement(By.XPath("//table[contains(@class,'search-result-jort')]/tbody/tr[4]/td[2]")).Text;
                                entreprise.SituationFiscaleArabe    = webDriver.FindElement(By.XPath("//table[contains(@class,'search-result-jort')]/tbody/tr[4]/td[3]")).Text;
                                entreprise.DenominationSociale      = webDriver.FindElement(By.XPath("//table[contains(@class,'search-result-jort')]/tbody/tr[5]/td[2]")).Text;
                                entreprise.DenominationSocialeArabe = webDriver.FindElement(By.XPath("//table[contains(@class,'search-result-jort')]/tbody/tr[5]/td[3]")).Text;
                                entreprise.NomCommercial            = webDriver.FindElement(By.XPath("//table[contains(@class,'search-result-jort')]/tbody/tr[6]/td[2]")).Text;
                                entreprise.NomCommercialArabe       = webDriver.FindElement(By.XPath("//table[contains(@class,'search-result-jort')]/tbody/tr[6]/td[3]")).Text;;
                                entreprise.AdresseSiege             = webDriver.FindElement(By.XPath("//table[contains(@class,'search-result-jort')]/tbody/tr[7]/td[2]")).Text;
                                entreprise.AdresseSiegeArabe        = webDriver.FindElement(By.XPath("//table[contains(@class,'search-result-jort')]/tbody/tr[7]/td[3]")).Text;
                            }

                            entrepriseModels.Add(entreprise);
                        }
                        catch (Exception ex)
                        {
                        }

                        webDriver.Navigate().GoToUrl(urlBackToList);
                    }

                    if (entrepriseModels.Count() >= 1000)
                    {
                        var json = JsonConvert.SerializeObject(entrepriseModels);
                        File.WriteAllText($"export_{annee}_{indexFile}.json", json, Encoding.UTF8);
                        entrepriseModels.Clear();
                        indexFile++;
                    }

                    webDriver.Navigate().GoToUrl(urlRNENext);
                }
            }
        }