Example #1
0
        public void TestPrompt()
        {
            NavigationHelper.NavigateToUrl("http://www.w3schools.com/js/tryit.asp?filename=tryjs_prompt");
            BrowserHelper.SwitchToFrame(By.Id("iframeResult"));
            ButtonHelper.ClickButton(By.XPath("//button[text()='Try it']"));
            var text = JavaScriptPopHelper.GetPopUpText();

            JavaScriptPopHelper.SendKeys(text);
            JavaScriptPopHelper.ClickOkOnPopup();
            BrowserHelper.RefreshPage();
            BrowserHelper.SwitchToFrame(By.Id("iframeResult"));
            ButtonHelper.ClickButton(By.XPath("//button[text()='Try it']"));
            text = JavaScriptPopHelper.GetPopUpText();
            JavaScriptPopHelper.SendKeys(text + "abc");
            JavaScriptPopHelper.ClickCancelOnPopup();
            ObjectRepository.Driver.SwitchTo().DefaultContent();
            GenericHelper.WaitForWebElement(By.Id("textareaCode"), TimeSpan.FromSeconds(60));
            JavaScriptExecutor.ExecuteScript("document.getElementById('textareaCode').style.display='block';");
            TextBoxHelper.ClearTextBox(By.Id("textareaCode"));
            TextBoxHelper.TypeInTextBox(By.Id("textareaCode"), text);
            //IAlert prompt = ObjectRepository.Driver.SwitchTo().Alert();
            //prompt.SendKeys("This is automation");
            //prompt.Accept();

            // ButtonHelper.ClickButton(By.XPath("//button[text()='Try it']"));
            //prompt = ObjectRepository.Driver.SwitchTo().Alert();
            //prompt.SendKeys("This is automation");
            //prompt.Dismiss();
            Logger.Info("Test Prompt Complete");
        }
        public void CheckBox()
        {
            string url = ObjectRepository.Config.GetWebsite();

            NavigationHelper.NavigateToUrl(url);
            LinkHelper.ClickLink(By.LinkText("File a Bug"));

            By     userTextBox = By.Id("Bugzilla_login");
            string user        = ObjectRepository.Config.GetUserName();

            TextBoxHelper.TypeinTextBox(userTextBox, user);

            By     passwordTextBox = By.Id("Bugzilla_password");
            string password        = ObjectRepository.Config.GetPassword();

            TextBoxHelper.TypeinTextBox(passwordTextBox, password);

            By checkBoxLocator = By.Id("Bugzilla_restrictlogin");

            CheckBoxHelper.CheckedCheckBox(checkBoxLocator);
            bool response = CheckBoxHelper.IsCheckBoxChecked(checkBoxLocator);


            ArrayList locators = new ArrayList {
                userTextBox, passwordTextBox
            };

            TextBoxHelper.ClearTextBox(locators);

            if (response == true)
            {
                Console.WriteLine("The checkBox is checked");
            }
        }
Example #3
0
        public void TestPrompt()
        {
            NavigationHelper.NavigateToUrl("http://www.w3schools.com/js/tryit.asp?filename=tryjs_prompt");
            BrowserHelper.SwitchToFrame(By.Id("iframeResult"));
            ButtonHelper.ClickButton(By.XPath("//button[text()='Try it']"));
            var text = JavaScriptPopHelper.GetPopUpText();

            JavaScriptPopHelper.SendKeys(text);
            JavaScriptPopHelper.ClickOkOnPopup();
            BrowserHelper.RefreshPage();
            BrowserHelper.SwitchToFrame(By.Id("iframeResult"));
            ButtonHelper.ClickButton(By.XPath("//button[text()='Try it']"));
            text = JavaScriptPopHelper.GetPopUpText();
            JavaScriptPopHelper.SendKeys(text + "abc");
            JavaScriptPopHelper.ClickCancelOnPopup();
            ObjectRepository.Driver.SwitchTo().DefaultContent();
            TextBoxHelper.ClearTextBox(By.Id("textareaCode"));
            TextBoxHelper.TypeInTextBox(By.Id("textareaCode"), text);
            //IAlert prompt = ObjectRepository.Driver.SwitchTo().Alert();
            //prompt.SendKeys("This is automation");
            //prompt.Accept();

            // ButtonHelper.ClickButton(By.XPath("//button[text()='Try it']"));
            //prompt = ObjectRepository.Driver.SwitchTo().Alert();
            //prompt.SendKeys("This is automation");
            //prompt.Dismiss();
        }
 public void TextBox()
 {
     NavigationHelper.NavigateToUrl(ObjectRepository.Config.GetWebsite());
     LinkHelper.ClickLink(By.LinkText("File a Bug"));
     TextBoxHelper.TypeInTextBox(By.Id("Bugzilla_login"), ObjectRepository.Config.GetUsername());
     TextBoxHelper.TypeInTextBox(By.Id("Bugzilla_password"), ObjectRepository.Config.GetPassword());
     TextBoxHelper.ClearTextBox(By.Id("Bugzilla_login"));
 }
 public void TestBox()
 {
     LinkHelper.ClickLink(By.LinkText("File a Bug"));
     TextBoxHelper.TypeInTextBox(By.Id("Bugzilla_login"), ObjectRepository.Config.GetUsername());
     TextBoxHelper.TypeInTextBox(By.Id("Bugzilla_password"), ObjectRepository.Config.GetPassword());
     TextBoxHelper.ClearTextBox(By.Id("Bugzilla_login"));
     CheckBoxHelper.IsCheckedBoxChecked(By.Id("Bugzilla_restrictlogin"));
     CheckBoxHelper.CheckedCheckBox(By.Id("Bugzilla_restrictlogin"));
 }
Example #6
0
 public void TextBox()
 {
     NavigationHelper.NavigateToURL(ObjectRepository.Config.GetDemoRegister());
     LinkHelper.ClickLink(By.Id("input-email"));
     //IWebElement EmaiBoxField = ObjectRepository.driver.FindElement(By.Name("email"));
     //EmaiBoxField.Clear();
     TextBoxHelper.ClearTextBox(By.Id("input-email"));
     TextBoxHelper.SendTextToTextbox(By.Id("input-email"), ObjectRepository.Config.GetEmail());
     TextBoxHelper.ClearTextBox(By.Id("input-password"));
     TextBoxHelper.SendTextToTextbox(By.Id("input-password"), ObjectRepository.Config.GetPassword());
 }
Example #7
0
 public void TextBox()
 {
     NavigationHelper.NavigateToUrl(ObjectRepository.config.GetWebsite());
     LinkHelper.ClickOnLink(By.LinkText("File a Bug"));
     //IWebElement element=ObjectRepository.Driver.FindElement(By.Id("Bugzilla_login"));
     //element.SendKeys(ObjectRepository.config.GetUsername());
     //element.SendKeys(ObjectRepository.config.GetPassword());
     //element.Clear();
     TextBoxHelper.TypeInTextBox(By.Id("Bugzilla_login"), ObjectRepository.config.GetUsername());
     TextBoxHelper.TypeInTextBox(By.Id("Bugzilla_password"), ObjectRepository.config.GetPassword());
     TextBoxHelper.ClearTextBox(By.Id("Bugzilla_login"));
 }
        public void CheckBox()
        {
            NavigationHelper.NavigateToUrl(ObjectRepository.Config.GetWebsite());
            LinkHelper.clickLink(By.LinkText("File a Bug"));
            TextBoxHelper.TypeInTextBox(By.Id("Bugzilla_login"), ObjectRepository.Config.GetUsername());
            TextBoxHelper.TypeInTextBox(By.Id("Bugzilla_password"), ObjectRepository.Config.GetPassword());
            TextBoxHelper.TypeInTextBox(By.Id("Bugzilla_login"), ObjectRepository.Config.GetUsername());
            TextBoxHelper.ClearTextBox(By.Id("Bugzilla_login"));
            IWebElement ele = ObjectRepository.Driver.FindElement(By.Id("Bugzilla_restrictlogin"));

            ele.Click();
            Console.WriteLine(CheckBoxHelper.IsCheckCheckBoxChecked(By.Id("Bugzilla_restrictlogin")));
            CheckBoxHelper.CheckedCheckBox(By.Id("Bugzilla_restrictlogin"));
        }
Example #9
0
        public void TestFrame()
        {
            NavigationHelper.NavigateToUrl("http://www.w3schools.com/js/js_popup.asp");
            ButtonHelper.ClickButton(By.XPath("//div[@id='main']/descendant::a[position()=3]"));
            BrowserHelper.SwitchToWindow(1);
            ButtonHelper.ClickButton(By.XPath("//div[@class='textarea']/descendant::button"));
            BrowserHelper.SwitchToFrame(By.Id("iframeResult"));
            ButtonHelper.ClickButton(By.XPath("//button[text()='Try it']"));
            var a = ObjectRepository.Driver.SwitchTo().Alert().Text;

            ObjectRepository.Driver.SwitchTo().Alert().Accept();
            ObjectRepository.Driver.SwitchTo().DefaultContent();
            TextBoxHelper.ClearTextBox(By.Id("textareaCode"));
            TextBoxHelper.TypeInTextBox(By.Id("textareaCode"), a);
        }
Example #10
0
 public void WhenIEnterInMaxField(string p0)
 {
     try
     {
         TextBoxHelper.ClearTextBox(By.XPath(".//*[@id='total-space-max']"));
         TextBoxHelper.TypeInTextBox(By.XPath(".//*[@id='total-space-max']"), p0);
         Thread.Sleep(5000);
     }
     catch (Exception e)
     {
         Logger.Error("Exception: " + e);
         Assert.Fail("Exception" + e);
         throw;
     }
 }
Example #11
0
        public void TestAlert()
        {
            NavigationHelper.NavigateToUrl("http://www.w3schools.com/js/js_popup.asp");
            ButtonHelper.ClickButton(By.XPath("//div[@id='main']/descendant::a[position()=3]"));
            BrowserHelper.SwitchToWindow(1);
            IWebElement textarea = ObjectRepository.Driver.FindElement(By.Id("textareaCode"));

            JavaScriptExecutor.ExecuteScript("document.getElementById('textareaCode').setAttribute('style','display: inline;')");
            TextBoxHelper.ClearTextBox(By.CssSelector("#textareawrapper"));
            BrowserHelper.SwitchToFrame(By.Id("iframeResult"));
            var text = JavaScriptPopHelper.GetPopUpText();

            JavaScriptPopHelper.ClickOkOnPopup();
            ObjectRepository.Driver.SwitchTo().DefaultContent();
            GenericHelper.WaitForWebElement(By.Id("textareaCode"), TimeSpan.FromSeconds(60));
            //GenericHelper.Wait(ExpectedConditions.ElementIsVisible(By.Id("id")), TimeSpan.FromSeconds(60));
        }
Example #12
0
        public void TestAlert()
        {
            NavigationHelper.NavigateToUrl("http://www.w3schools.com/js/js_popup.asp");
            ButtonHelper.ClickButton(By.XPath("//div[@id='main']/descendant::a[position()=3]"));
            BrowserHelper.SwitchToWindow(1);
            BrowserHelper.SwitchToFrame(By.Id("iframeResult"));
            // ButtonHelper.ClickButton(By.XPath("//button[text()='Try it']"));
            var text = JavaScriptPopHelper.GetPopUpText();

            JavaScriptPopHelper.ClickOkOnPopup();
            //IAlert alert = ObjectRepository.Driver.SwitchTo().Alert();
            //var text = alert.Text;
            //alert.Accept();
            ObjectRepository.Driver.SwitchTo().DefaultContent();
            TextBoxHelper.ClearTextBox(By.Id("textareaCode"));
            TextBoxHelper.TypeInTextBox(By.Id("textareaCode"), text);
        }
Example #13
0
        public void TestConfimPopup()
        {
            NavigationHelper.NavigateToUrl("http://www.w3schools.com/js/tryit.asp?filename=tryjs_confirm");
            BrowserHelper.SwitchToFrame(By.Id("iframeResult"));
            ButtonHelper.ClickButton(By.XPath("//button[text()='Try it']"));
            var text = JavaScriptPopHelper.GetPopUpText();

            JavaScriptPopHelper.ClickOkOnPopup();
            //IAlert confirm = ObjectRepository.Driver.SwitchTo().Alert();
            //confirm.Accept();
            ButtonHelper.ClickButton(By.XPath("//button[text()='Try it']"));
            JavaScriptPopHelper.ClickCancelOnPopup();
            ObjectRepository.Driver.SwitchTo().DefaultContent();
            TextBoxHelper.ClearTextBox(By.Id("textareaCode"));
            TextBoxHelper.TypeInTextBox(By.Id("textareaCode"), text);
            //confirm = ObjectRepository.Driver.SwitchTo().Alert();
            //confirm.Dismiss();
        }
        public void LoggingTextBox()
        {
            string url = ObjectRepository.Config.GetWebsite();

            NavigationHelper.NavigateToUrl(url);
            LinkHelper.ClickLink(By.LinkText("File a Bug"));

            By     userTextBox = By.Id("Bugzilla_login");
            string user        = ObjectRepository.Config.GetUserName();

            TextBoxHelper.TypeinTextBox(userTextBox, user);

            By     passwordTextBox = By.Id("Bugzilla_password");
            string password        = ObjectRepository.Config.GetPassword();

            TextBoxHelper.TypeinTextBox(passwordTextBox, password);

            ArrayList locators = new ArrayList {
                userTextBox, passwordTextBox
            };

            TextBoxHelper.ClearTextBox(locators);
        }
        public static void ExecuteScript(IPage pageObject, string xlPath, string text)
        {
            // var totalRow = ExcelReaderHelper.GetTotalRows(xlPath, sheetName);
            // for (var i = 2; i < totalRow; i++)
            // {
            var action = "";    //ExcelReaderHelper.GetCellValue(xlPath, sheetName, i, 1);
            var webEle = "";    //ExcelReaderHelper.GetCellValue(xlPath, sheetName, i, 2);


            var locator = pageObject.GetLocatorOfWebElement(webEle);

            Log.Info("Action " + action + ", WebElement " + webEle + ", Locator  " + locator);
            switch (action)
            {
            case "SendKeys":
            {
                // var text = ExcelReaderHelper.GetCellValue(xlPath, sheetName, i, 3);
                TextBoxHelper.TypeInTextBox(locator, text);
            }
            break;

            case "ClearAndSendKeys":
            {
                //var text = ExcelReaderHelper.GetCellValue(xlPath, sheetName, i, 3);
                TextBoxHelper.ClearTextBox(locator);
                TextBoxHelper.TypeInTextBox(locator, text);
            }
            break;

            case "Click":
            {
                ButtonHelper.ClickButton(locator);
            }
            break;

            case "ClickIfExist":
            {
                if (GenericHelper.IsElementPresentQuick(locator))
                {
                    ButtonHelper.ClickButton(locator);
                }
            }
            break;

            case "Select":
            {
                // var text = ExcelReaderHelper.GetCellValue(xlPath, sheetName, i, 3);
                DropDownHelper.SelectByVisibleText(locator, text);
            }
            break;

            case "SelectIndex":
            {
                //var text = ExcelReaderHelper.GetCellValue(xlPath, sheetName, i, 3);
                DropDownHelper.SelectByIndex(locator, Convert.ToInt32(text));
            }
            break;

            case "WaitForEle":
            {
                //  var text = ExcelReaderHelper.GetCellValue(xlPath, sheetName, i, 3);
                if (text == string.Empty)
                {
                    GenericHelper.WaitForElement(locator);
                }
                else
                {
                    GenericHelper.WaitForElement(locator, Convert.ToInt32(text));
                }
            }
            break;

            case "Sleep":
            {
                // var text = ExcelReaderHelper.GetCellValue(xlPath, sheetName, i, 3);
                Thread.Sleep(Convert.ToInt32(text));
            }
            break;

            case "SelectFile":
            {
                // var text = ExcelReaderHelper.GetCellValue(xlPath, sheetName, i, 3);
                pageObject.FileUpload(text);
            }
            break;

            case "AssertTitle":
            {
                // var text = ExcelReaderHelper.GetCellValue(xlPath, sheetName, i, 3);
                Assert.AreEqual(text, ObjectRepository.Driver.Title);
            }

            break;

            case "PerformClick":
            {
                MouseActionHelper.PerformClick(locator);
            }
            break;

                // }
            }
        }
Example #16
0
        public static void ExecuteScript(IPage pageObject, string xlPath, string sheetName)
        {
            var totalRow = ExcelReaderHelper.GetTotalRows(xlPath, sheetName);

            for (var i = 2; i < totalRow; i++)
            {
                var action = ExcelReaderHelper.GetCellValue(xlPath, sheetName, i, 1);
                var webEle = ExcelReaderHelper.GetCellValue(xlPath, sheetName, i, 2);

                if ((webEle == string.Empty) && (action == string.Empty))
                {
                    break;
                }

                if (webEle == string.Empty)
                {
                    continue;
                }

                var locator = pageObject.GetLocatorOfWebElement(webEle);
                Console.WriteLine("Action {0}, WebElement {1}, Locator {2} ", action, webEle, locator);
                switch (action)
                {
                case "SendKeys":
                {
                    var text = ExcelReaderHelper.GetCellValue(xlPath, sheetName, i, 3);
                    TextBoxHelper.TypeInTextBox(locator, text);
                }
                break;

                case "ClearAndSendKeys":
                {
                    var text = ExcelReaderHelper.GetCellValue(xlPath, sheetName, i, 3);
                    TextBoxHelper.ClearTextBox(locator);
                    TextBoxHelper.TypeInTextBox(locator, text);
                }
                break;

                case "Click":
                {
                    ButtonHelper.ClickButton(locator);
                }
                break;

                case "ClickIfExist":
                {
                    if (GenericHelper.IsElementPresentQuick(locator))
                    {
                        ButtonHelper.ClickButton(locator);
                    }
                }
                break;

                case "Select":
                {
                    var text = ExcelReaderHelper.GetCellValue(xlPath, sheetName, i, 3);
                    DropDownHelper.SelectByVisibleText(locator, text);
                }
                break;

                case "SelectIndex":
                {
                    var text = ExcelReaderHelper.GetCellValue(xlPath, sheetName, i, 3);
                    DropDownHelper.SelectByIndex(locator, Convert.ToInt32(text));
                }
                break;

                case "WaitForEle":
                {
                    var text = ExcelReaderHelper.GetCellValue(xlPath, sheetName, i, 3);
                    if (text == string.Empty)
                    {
                        GenericHelper.WaitForElement(locator);
                    }
                    else
                    {
                        GenericHelper.WaitForElement(locator, Convert.ToInt32(text));
                    }
                }
                break;

                case "Sleep":
                {
                    var text = ExcelReaderHelper.GetCellValue(xlPath, sheetName, i, 3);
                    Thread.Sleep(Convert.ToInt32(text));
                }
                break;

                case "SelectFile":
                {
                    var text = ExcelReaderHelper.GetCellValue(xlPath, sheetName, i, 3);
                    pageObject.FileUpload(text);
                }
                break;

                case "AssertTitle":
                {
                    var text = ExcelReaderHelper.GetCellValue(xlPath, sheetName, i, 3);
                    Assert.AreEqual(text, ObjectRepository.Driver.Title);
                }

                break;

                case "PerformClick":
                {
                    MouseActionHelper.PerformClick(locator);
                }
                break;
                }
            }
        }