public async Task GlobalSetup()
 {
     ExecutionEnvironment executionEnvironment = new ExecutionEnvironment()
     {
     };
     await WebDriverHelper.EnsureDriverAsync(executionEnvironment);
 }
Exemple #2
0
        public void ClickSimpleFormDemo()
        {
            var wait = new WebDriverWait(_driver, TimeSpan.FromSeconds(2));

            wait.Until(WebDriverHelper.ElementIsDisplayed(paneBasic));
            WebDriverHelper.StaleElementHandleClick(_driver.FindElement(simpleFormDemoLink));
        }
        internal void NewUserIsReturned()
        {
            var wait = new WebDriverWait(_driver, TimeSpan.FromSeconds(10));

            wait.Until(WebDriverHelper.TextToBePresentInElement(userAndLoading, "First Name :"));
            string name = userAndLoading.Text;

            //TODO split name
            string[] nameArray = name.Replace("\r\n\r\n", "|").Split('|');

            //'FirstName : ' is present
            Assert.AreEqual("First Name : ", nameArray[0].Substring(0, 13));
            Assert.AreEqual("Last Name : ", nameArray[1].Substring(0, 12));

            string firstName = nameArray[0].Substring(13, nameArray[0].Length - 13);
            string lastName  = nameArray[1].Substring(12, nameArray[1].Length - 12);

            IsNameInCorrectFormat(firstName);
            IsNameInCorrectFormat(lastName);

            //TODO regex url
            string imageUrl = userAndLoading.FindElement(By.TagName("img")).GetAttribute("src");

            Assert.AreEqual("https://randomuser.me/api/portraits/", imageUrl.Substring(0, 36));
            Assert.AreEqual(".jpg", imageUrl.Substring(imageUrl.Length - 4, 4));
        }
 public void Setup()
 {
     TestLogger.LogTestCaseStart();
     WebDriverHelper.InitialiseDriver();
     WebDriverHelper.LaunchUrl(TestRun.SelectedEnvironment);
     WebDriverHelper.Maximise();
 }
Exemple #5
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);
            }
        }
Exemple #6
0
        public void RemoveProductsFromCart()
        {
            var page = new UpdateProductToCart(_webDriver);

            page.RemoveProductFromCartByIndex(1);
            WebDriverHelper.Wait(_webDriver);
        }
Exemple #7
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();
            }
        }
Exemple #8
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);
            }
        }
        public virtual void TestCleanUp()
        {
            var testResult = TestContext.CurrentTestOutcome;

            bool isTestFailed = !(testResult == UnitTestOutcome.Passed || testResult == UnitTestOutcome.Inconclusive);


            if (isTestFailed)
            {
                try
                {
                    var myUniqueFileName = string.Format(@"screenshot_{0}.png", Guid.NewGuid());
                    var fullPath         = Path.Combine(Path.GetTempPath(), myUniqueFileName);

                    var screenshot = WebDriverHelper.TakeScreenshot();
                    screenshot.SaveAsFile(fullPath, ImageFormat.Png);

                    // Attach image to the log file
                    TestContext.AddResultFile(fullPath);
                }
                catch (Exception e)
                {
                    Console.WriteLine("Unable to take screenshot:" + e.Message);
                }
            }

            bool shouldRestartBrowser = isTestFailed;

            if (shouldRestartBrowser)
            {
                WebDriverHelper.CloseDriver();
            }
        }
Exemple #10
0
        public void BasicIsDislayed()
        {
            //Basic Examples is expanded
            Assert.AreEqual("true", _driver.FindElement(toggleBasic).GetAttribute("aria-expanded"));

            var wait    = new WebDriverWait(_driver, TimeSpan.FromSeconds(10));
            var element = wait.Until(WebDriverHelper.GetElementOnceVisible(paneBasic));

            //Header is correct
            Assert.AreEqual("BASIC EXAMPLES TO START WITH SELENIUM", element.FindElement(By.ClassName("head")).Text);

            //Practise components are displayed as expected
            var demoComponents = element.FindElements(By.ClassName("list-group-item"));
            //TODO: Context injection for execpted components?
            var expectedComponents = new List <string> {
                "Simple Form Demo", "Check Box Demo", "Radio Buttons Demo", "Select Dropdown List", "Javascript Alerts", "Window Popup Modal", "Bootstrap Alerts", "Bootstrap Modals"
            };
            var actualComponents = new List <string>();

            foreach (var item in demoComponents)
            {
                var text = item.Text;
                actualComponents.Add(text);
            }

            Assert.AreEqual(expectedComponents, actualComponents);
        }
Exemple #11
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);
            }
        }
Exemple #12
0
 public void Setup()
 {
     WebDriverHelper.Init("Chrome");
     _Driver = WebDriverHelper.Driver;
     _Driver.Manage().Window.Maximize();
     SiteHelper.SignIn(_Driver);
     _securityPage = new SecurityPage(_Driver);
 }
Exemple #13
0
        static async Task Main(string[] args)
        {
            await WebDriverHelper.EnsureChromeDriverAsync();

            var annee = (args != null && args.Count() > 0) ? args[0] : "2020";

            RecupererSociete(annee);
        }
Exemple #14
0
 public void Setup()
 {
     WebDriverHelper.Init("Chrome");
     Driver = WebDriverHelper.Driver;
     Driver.Manage().Window.Maximize();
     SiteHelper.SignIn(Driver);
     _appsPage = new AppsPage(Driver);
 }
Exemple #15
0
        public void CheckoutCart()
        {
            var page = new Checkout(_webDriver);

            page.RedirectToStepOne();

            WebDriverHelper.Wait(_webDriver);
        }
        public void IsOnSingleInputPage()
        {
            Assert.AreEqual(url, _driver.Url);
            var wait = new WebDriverWait(_driver, TimeSpan.FromSeconds(5));

            wait.Until(WebDriverHelper.ElementIsDisplayed(headerFirstExample));
            Assert.IsTrue(_driver.FindElement(headerFirstExample).Text.Contains("first example"));
        }
Exemple #17
0
        public void CompleteCheckout()
        {
            var    page   = new Checkout(_webDriver);
            string result = page.CompleteCheckout();

            Assert.AreEqual("THANK YOU FOR YOUR ORDER", result);

            WebDriverHelper.Wait(_webDriver);
        }
        public void IsOnCheckboxPage()
        {
            var wait = new WebDriverWait(_driver, TimeSpan.FromSeconds(10));

            Assert.IsTrue(wait.Until(WebDriverHelper.ElementIsDisplayed(bySingleCheckboxDemoTitle)));
            var expectedTitle = "Single Checkbox Demo";

            Assert.AreEqual(expectedTitle, singleCheckoutDemoTitle.Text);
        }
Exemple #19
0
        /// <summary>
        /// Waits for spinner ti disappear
        /// </summary>
        /// <param name="sec"></param>
        /// <returns></returns>
        public HomePage WaitForSpinnerToDisappear(int sec = 60)
        {
            if (SpinnerExists())
            {
                WebDriverHelper.WaitForCondition(() => !Spinner.Displayed, sec);
            }

            return(this);
        }
Exemple #20
0
        public void AddProductsToCart()
        {
            var page = new UpdateProductToCart(_webDriver);

            page.AddProductToCartByIndex(1);
            page.AddProductToCartByIndex(2);

            WebDriverHelper.Wait(_webDriver);
        }
        /// <summary>
        /// Constructor to create the class.
        /// </summary>
        /// <param name="driver">The browser to interact with</param>
        public ProviderSearchResultsPage(IWebDriver driver)
        {
            this.driver = driver;
            this.helper = new WebDriverHelper(driver);

            // Because this page loads the results from an AJAX call, we have to pause while the results
            // finish loading. Once they're loaded, we can then access all the search results.
            PauseForSearchResultsToLoad();
        }
Exemple #22
0
        protected void MoveElementToMiddleOfPage(IWebElement element)
        {
            //scroll element to middle of the page
            string script = "var viewPortHeight = Math.max(document.documentElement.clientHeight, window.innerHeight || 0);" +
                            "var elementTop = arguments[0].getBoundingClientRect().top;" +
                            "window.scrollBy(0, elementTop-(viewPortHeight/2));";

            WebDriverHelper.ExecuteJavascript(script, element);
        }
Exemple #23
0
        public void LoginTest()
        {
            var page = new Login(_webDriver);

            page.SetUsername("standard_user");
            page.SetPassword("secret_sauce");

            page.LoginClick();
            WebDriverHelper.Wait(_webDriver);
        }
Exemple #24
0
        public void SortPrice()
        {
            var page = new SortProduct(_webDriver);

            page.SelectItemByVisibleText("Name (Z to A)");
            WebDriverHelper.Wait(_webDriver);

            page.SelectItemByIndex(3);
            WebDriverHelper.Wait(_webDriver);
        }
        public void Setup()
        {
            string browser  = Properties.Settings.Default.Browser.ToUpper();
            string LoginURL = Properties.Settings.Default.LoginURL;

            this.wds    = new WebDriverHelper();
            this.driver = wds.InitDriver(browser);

            //Example URL - To be removed/modified based on testing requirement
            this.driver.Navigate().GoToUrl(LoginURL);
        }
Exemple #26
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;
            }
        }
Exemple #27
0
 private void WaitUntilDocumentHasFullyLoaded()
 {
     try
     {
         //Selenium webdriver executes to quickly at times, this method will ensure that
         //the page has always been fully loaded before each action
         WaitUntil(wd => WebDriverHelper.ExecuteJavascript("return document.readyState").ToString() == "complete");
     }
     catch
     {
         //Swallow exception - ignore exceptions thrown by Javascript
     }
 }
 /// <summary>
 /// Constructor. Will load the provider search page only if the page isn't already loading.
 /// </summary>
 /// <param name="driver">The browser to interact with</param>
 public ProviderSearchPage(IWebDriver driver)
 {
     this.driver = driver;
     if (driver == null)
     {
         throw new NullReferenceException();
     }
     this.helper = new WebDriverHelper(driver);
     if (!driver.Url.StartsWith(url))
     {
         driver.Navigate().GoToUrl(url);
     }
 }
Exemple #29
0
        public void CheckoutStepOne()
        {
            var page = new Checkout(_webDriver);

            WebDriverHelper.Wait(_webDriver);
            page.SetupStepOne();

            page.UpdateStepOne("Susen", "Maharjan", "97701");
            WebDriverHelper.Wait(_webDriver);

            page.SubmitStepOne();
            WebDriverHelper.Wait(_webDriver);
        }
Exemple #30
0
        public static async Task <string> ExecuteAsync(this Test test, ExecutionEnvironment executionEnvironment)
        {
            test.Title             = executionEnvironment.Title;
            test.Measure.StartDate = DateTime.Now;
            _log_.Trace($"Begin Executing test {test.Name} | {test.Measure.StartDate}");
            string     sessionId     = string.Empty;
            IWebDriver testWebDriver = null;

            try
            {
                foreach (Step step in test.Steps)
                {
                    if (!string.IsNullOrEmpty(sessionId))
                    {
                        step.SessionId = sessionId;
                    }
                    else
                    {
                        if (executionEnvironment.GridEnabled == false)
                        {
                            await WebDriverHelper.EnsureDriverAsync(executionEnvironment);
                        }
                    }

                    step.Execute(ref testWebDriver, executionEnvironment);
                    if (sessionId != step.SessionId)
                    {
                        sessionId = step.SessionId;
                    }
                }
                test.Failed = false;
            }
            catch (Exception ex)
            {
                test.Failed     = true;
                test.StackTrace = $"{test.Name} : {ex.Message}";
            }
            finally
            {
                test.Measure.EndDate = DateTime.Now;
                if (testWebDriver != null)
                {
                    testWebDriver.Close();
                    testWebDriver.Quit();
                }
            }

            _log_.Trace($"End Executing test {test.Name} | {test.Measure.StartDate} - {test.Measure.EndDate}");
            return(sessionId);
        }