public void TestAlert_using_Helper() { //Javascript executor example NavigationHelper.NavigateToUrl("https://www.w3schools.com/js/js_popup.asp"); ButtonHelper.ClickButton(By.CssSelector("#main>div:nth-of-type(4)>a")); BrowserHelper.SwitchToWindow(1); ObjectRepository.Driver.SwitchTo().Frame(ObjectRepository.Driver.FindElement(By.CssSelector("#iframeResult")));//switches to frame ButtonHelper.ClickButton(By.CssSelector("button[onclick = 'myFunction()']")); var text = JavascriptPopupHelper.GetPopupText(); JavascriptPopupHelper.ClickOKOnPopup(); ObjectRepository.Driver.SwitchTo().DefaultContent(); // Add this line before the line of code , where you are trying to clear the text area IWebElement textarea = ObjectRepository.Driver.FindElement(By.Id("textareaCode")); JavaScriptExecutor.ExecuteScript("document.getElementById('textareaCode').setAttribute('style','display: inline;')"); //if wewant to enterdata in the feild JavaScriptExecutor.ExecuteScript("document.getElementById('textareaCode').value = 'new data'"); // for clicking ------JavaScriptExecutor.ExecuteScript("document.getElementById('hghgjghgjgjgjgj').click()"); // TextboxHelper.ClearTextBody(By.XPath("//*[@id='textareawrapper']/div/div[6]/div[1]/div/div/div/div[5]")); //TextboxHelper.ClearTextBody(By.Id("textareacontainer")); // TextboxHelper.ClearTextBody(By.XPath("//*[@id='textareawrapper']/div/div[6]/div[1]/div/div/div")); //TextboxHelper.ClearTextBody(By.XPath("//*[@id='textareawrapper']/div/div[1]")); // TextboxHelper.ClearTextBody(By.XPath("//*[@id='textareawrapper']/div/div[6]/div[1]/div/div")); //Thread.Sleep(200); //TextboxHelper.ClearTextBody(By.XPath("//*[@id='textareawrapper']/div/div[6]/div[1]")); TextboxHelper.ClearTextBody(By.CssSelector("#textareaCode")); TextboxHelper.TypeInTextbox(By.CssSelector("#textareaCode"), text); }
public void TestCheckox() { NavigationHelper.NavigateToUrl(ObjectRepository.Config.GetWebsite()); LinkHelper.ClickLink(By.XPath("//*[@id='authentication-link' and @class='login']")); LinkHelper.ClickLink(By.XPath("//div[@class='Qk3sp3k23b-uqHOY6J1-E']")); TextboxHelper.TypeInTextbox(By.XPath("//*[@id='email']"), ObjectRepository.Config.GetUserName()); TextboxHelper.TypeInTextbox(By.XPath("//*[@id='password']"), ObjectRepository.Config.GetPassword()); //IWebElement ele = ObjectRepository.Driver.FindElement(By.XPath("//*[@class='_2gszK83qNMGLVmjY81wTD-']")); //ele.Click(); Console.WriteLine(CheckboxHelper.IsCheckboxchecked(By.XPath("//*[@class='_2gszK83qNMGLVmjY81wTD-']"))); CheckboxHelper.CheckedCheckbox(By.XPath("//*[@class='_2gszK83qNMGLVmjY81wTD-']")); Console.WriteLine(CheckboxHelper.IsCheckboxchecked(By.XPath("//*[@class='_2gszK83qNMGLVmjY81wTD-']"))); }
public void TextBox() { NavigationHelper.NavigateToUrl(ObjectRepository.Config.GetWebsite()); LinkHelper.ClickLink(By.XPath("//*[@id='authentication-link' and @class='login']")); LinkHelper.ClickLink(By.XPath("//div[@class='Qk3sp3k23b-uqHOY6J1-E']")); //IWebElement ele = ObjectRepository.Driver.FindElement(By.XPath("//*[@id='email' and @type='email']")); //ele.SendKeys(ObjectRepository.Config.GetUserName()); //ele = ObjectRepository.Driver.FindElement(By.XPath("//*[@id='password' and @type='password']")); //ele.SendKeys(ObjectRepository.Config.GetPassword()); //when using helpers we will not write the above commented code and write the one mentioned below TextboxHelper.TypeInTextbox(By.XPath("//*[@id='email']"), ObjectRepository.Config.GetUserName()); TextboxHelper.TypeInTextbox(By.XPath("//*[@id='password']"), ObjectRepository.Config.GetPassword()); }
public void Button() { NavigationHelper.NavigateToUrl(ObjectRepository.Config.GetWebsite()); LinkHelper.ClickLink(By.XPath("//*[@id='authentication-link' and @class='login']")); LinkHelper.ClickLink(By.XPath("//div[@class='Qk3sp3k23b-uqHOY6J1-E']")); TextboxHelper.TypeInTextbox(By.XPath("//*[@id='email']"), ObjectRepository.Config.GetUserName()); TextboxHelper.TypeInTextbox(By.XPath("//*[@id='password']"), ObjectRepository.Config.GetPassword()); //IWebElement ele = ObjectRepository.Driver.FindElement(By.XPath("//*[@class='bpk-button-IZE-J ProgressionButton__button-3U-H6']")); //ele.Click(); Console.WriteLine("Enabled : {0}", ButtonHelper.IsButonEnabled(By.XPath("//*[@class='bpk-button-IZE-J ProgressionButton__button-3U-H6']"))); //Console.WriteLine("Label : {0}", ButtonHelper.GetButtonText(By.XPath("//button[@data-testid='login-button']"))); //in this case doesnt wrk but if we had got the value in the span then it would hv worked or in value locator Console.WriteLine("Label : {0}", ButtonHelper.GetButtonText_alt(By.XPath("//button[@data-testid='login-button']")));//other way of extracing the text ButtonHelper.ClickButton(By.XPath("//*[@class='bpk-button-IZE-J ProgressionButton__button-3U-H6']")); }
public void TestRadio() { NavigationHelper.NavigateToUrl(ObjectRepository.Config.GetWebsite()); Console.WriteLine("Return buttons status is :{0}", RadioButtonHelper.IsRadioButtonchecked(By.Id("fsc-trip-type-selector-return"))); Console.WriteLine("Return buttons text is :{0}", RadioButtonHelper.GetRadioButtonText(By.XPath("//*[@id='flights-search-controls-root']/div/div/form/div[1]/div/label[1]/span"))); RadioButtonHelper.ClickRadioButton(By.Id("fsc-trip-type-selector-one-way")); //IWebElement ele = ObjectRepository.Driver.FindElement(By.Id("fsc-trip-type-selector-one-way")); //ele.Click(); LinkHelper.ClickLink(By.XPath("//*[@id='authentication-link' and @class='login']")); LinkHelper.ClickLink(By.XPath("//div[@class='Qk3sp3k23b-uqHOY6J1-E']")); TextboxHelper.TypeInTextbox(By.XPath("//*[@id='email']"), ObjectRepository.Config.GetUserName()); TextboxHelper.TypeInTextbox(By.XPath("//*[@id='password']"), ObjectRepository.Config.GetPassword()); Console.WriteLine("Enabled : {0}", ButtonHelper.IsButonEnabled(By.XPath("//*[@class='bpk-button-IZE-J ProgressionButton__button-3U-H6']"))); ButtonHelper.ClickButton(By.XPath("//*[@class='bpk-button-IZE-J ProgressionButton__button-3U-H6']")); }
public void TestAlert() { //giving error in cleartextpart NavigationHelper.NavigateToUrl("https://www.w3schools.com/js/js_popup.asp"); ButtonHelper.ClickButton(By.CssSelector("#main>div:nth-of-type(4)>a")); BrowserHelper.SwitchToWindow(1); ObjectRepository.Driver.SwitchTo().Frame(ObjectRepository.Driver.FindElement(By.CssSelector("#iframeResult")));//switches to frame ButtonHelper.ClickButton(By.CssSelector("button[onclick = 'myFunction()']")); IAlert alert = ObjectRepository.Driver.SwitchTo().Alert(); var text = alert.Text; alert.Accept(); ObjectRepository.Driver.SwitchTo().DefaultContent(); TextboxHelper.ClearTextBody(By.Id("textareaCode")); TextboxHelper.TypeInTextbox(By.CssSelector("#textareaCode"), text); }
//last param means parameter with variable length public void PerformAction(string keyword, string locatorType, string locatorValue, params string[] args) { try { switch (keyword) { case "Click": ButtonHelper.ClickButton(GetElementLocator(locatorType, locatorValue)); break; case "SendKeys": TextboxHelper.TypeInTextbox(GetElementLocator(locatorType, locatorValue), args[0]); break; case "Select": ComboboxHelper.SelectElement(GetElementLocator(locatorType, locatorValue), args[0]); break; case "WaitForElement": GenericHelper.WaitforWebElementInPage(GetElementLocator(locatorType, locatorValue), TimeSpan.FromSeconds(50)); break; case "Navigate": NavigationHelper.NavigateToUrl(args[0]); break; case "GetLinkText": ButtonHelper.GetButtonText(GetElementLocator(locatorType, locatorValue)); break; case "GetLinkText_alt": ButtonHelper.GetButtonText_alt(GetElementLocator(locatorType, locatorValue)); break; case "Compare": GenericHelper.GetTextAndCompare(GetElementLocator(locatorType, locatorValue), args[0]); break; default: throw new NoSuchKeywordFoundException("Keyword Not Found : " + keyword); } } catch (Exception e) { Console.Write("Something went wrong: Keyword" + keyword + ", locator: " + locatorType); } }
public void wlll() { // Test name: wlll // Step # | name | target | value | comment // 1 | open | /login?returnUrl=%2F | | NavigationHelper.NavigateToUrl("http://support.charmhealth.com.au:492/login?returnUrl=%2F"); // 2 | setWindowSize | 1720x934 | | // driver.Manage().Window.Size = new System.Drawing.Size(1720, 934); // 3 | click | css=.form-group:nth-child(1) > .form-control | | ButtonHelper.ClickButton(By.CssSelector(".form-group:nth-child(1) > .form-control")); // 4 | type | css=.ng-valid | chadmin | TextboxHelper.TypeInTextbox(By.CssSelector(".ng-valid"), "chadmin"); // 5 | type | css=.ng-untouched | j06 | TextboxHelper.TypeInTextbox(By.CssSelector(".ng-untouched"), "j06"); // 6 | click | css=.btn-outline-primary | | ButtonHelper.ClickButton(By.CssSelector(".btn-outline-primary")); // 7 | click | name=search | | ButtonHelper.ClickButton(By.Name("search")); // 8 | type | name=search | smith | TextboxHelper.TypeInTextbox(By.Name("search"), "smith"); // 9 | click | css=.iconic-magnifying-glass | | ButtonHelper.ClickButton(By.CssSelector(".iconic-magnifying-glass")); // 10 | click | css=.ng-star-inserted:nth-child(1) > .ng-star-inserted > .inline .ng-star-inserted:nth-child(2) > .ng-star-inserted | | ButtonHelper.ClickButton(By.CssSelector(".ng-star-inserted:nth-child(1) > .ng-star-inserted > .inline .ng-star-inserted:nth-child(2) > .ng-star-inserted")); // 11 | click | css=.active .ng-star-inserted:nth-child(2) > .ng-star-inserted | | ButtonHelper.ClickButton(By.CssSelector(".active .ng-star-inserted:nth-child(2) > .ng-star-inserted")); // 12 | click | css=.col-3 > .form-control-plaintext | | ButtonHelper.ClickButton(By.CssSelector(".col-3 > .form-control-plaintext")); // 13 | mouseOver | css=#bannerBtnLv1MedLists > .iconic-list | | { var element = driver.FindElement(By.CssSelector("#bannerBtnLv1MedLists > .iconic-list")); Actions builder = new Actions(driver); builder.MoveToElement(element).Perform(); } // 14 | mouseOut | css=#bannerBtnLv1MedLists > .iconic-list | | { var element = ObjectRepository.Driver.FindElement(By.TagName("body")); Actions builder = new Actions(driver); builder.MoveToElement(element, 0, 0).Perform(); } // 15 | mouseOver | id=bannerBtnLv1MedLists | | { var element = ObjectRepository.Driver.FindElement(By.Id("bannerBtnLv1MedLists")); Actions builder = new Actions(driver); builder.MoveToElement(element).Perform(); } // 16 | mouseOut | id=bannerBtnLv1MedLists | | { var element = ObjectRepository.Driver.FindElement(By.TagName("body")); Actions builder = new Actions(driver); builder.MoveToElement(element, 0, 0).Perform(); } // 17 | click | name=search | | ButtonHelper.ClickButton(By.Name("search")); // 18 | type | name=search | smith | TextboxHelper.TypeInTextbox(By.Name("search"), "smith"); // 19 | click | css=.btn-primary:nth-child(4) | | ButtonHelper.ClickButton(By.CssSelector(".btn-primary:nth-child(4)")); // 20 | click | css=.list-group-item:nth-child(1) .list-view-pf-main-info:nth-child(3) | | ButtonHelper.ClickButton(By.CssSelector(".list-group-item:nth-child(1) .list-view-pf-main-info:nth-child(3)")); // 21 | click | css=.iconic-people | | ButtonHelper.ClickButton(By.CssSelector(".iconic-people")); // 22 | click | css=.list-group-item:nth-child(2) .flex-1 | | ButtonHelper.ClickButton(By.CssSelector(".list-group-item:nth-child(2) .flex-1")); // 23 | click | css=.navbar-brand > .ng-tns-c1-0 | | ButtonHelper.ClickButton(By.CssSelector(".navbar-brand > .ng-tns-c1-0")); // 24 | click | css=.navbar-brand > .ng-tns-c1-0 | | ButtonHelper.ClickButton(By.CssSelector(".navbar-brand > .ng-tns-c1-0")); // 25 | click | css=.iconic-home | | ButtonHelper.ClickButton(By.CssSelector(".iconic-home")); // 26 | click | css=.iconic-share | | ButtonHelper.ClickButton(By.CssSelector(".iconic-share")); // 27 | click | name=search | | ButtonHelper.ClickButton(By.Name("search")); // 28 | type | name=search | smith | TextboxHelper.TypeInTextbox(By.Name("search"), "smith"); // 29 | sendKeys | name=search | ${KEY_ENTER} | TextboxHelper.TypeInTextbox(By.Name("search"), Keys.Enter); // 30 | close | | | }