private void GetAlert() { IAlert alert = null; WebDriverWait wait = new OpenQA.Selenium.Support.UI.WebDriverWait(driver, TimeSpan.FromSeconds(WaitTime)); try { alert = wait.Until(d => { try { return(driver.SwitchTo().Alert()); } catch (NoAlertPresentException) { return(null); } }); } catch (WebDriverTimeoutException) { alert = null; } alert?.Accept(); }
/// <summary> /// Method to accept condition specify in alert. /// </summary> public void AlertAccept() { try { //Implicitely Wait for specicified alert to appear. DelAlertLoaded = WaitAndGetAlert; _alert = AlertLoadingWait.Until(DelAlertLoaded); _alert.Accept(); } catch (WebDriverException e) { if (e.Message.Contains(Exceptions.ERROR_NORESPONSEURL)) { throw new WebDriverException(Utility.GetCommonMsgVariable("KRYPTONERRCODE0007") + ":" + e.Message); } throw new Exception("Could Not find Alert within " + Property.Waitforalert + " seconds"); //Updated alert failure message } catch (Exception) { throw new Exception(Utility.GetCommonMsgVariable("KRYPTONERRCODE0011")); } }
public void Initialize() { WebServices.DAL.CleanDB cDB = new WebServices.DAL.CleanDB(); cDB.emptyDB(); cDB.addUserToDB("zahiSimpleRegister", "123456"); cDB.addStoreToDB("zahiSimpleRegister", "abowStore"); driver.Manage().Window.Maximize(); driver.Navigate().GoToUrl(URL); Console.WriteLine("Opened URL"); IWebElement login = driver.FindElement(By.Id("LoginLink")); login.Click(); Thread.Sleep(sleepTime); IWebElement userName = driver.FindElement(By.Id("username")); userName.SendKeys("adminTest"); Thread.Sleep(sleepTime); IWebElement password = driver.FindElement(By.Id("password")); password.SendKeys("123456"); Thread.Sleep(sleepTime); IWebElement btnLogin = driver.FindElement(By.Id("btnLogin")); btnLogin.Click(); Thread.Sleep(sleepTime); IAlert alert = null; IWebElement initdb; int i = 0; while (i == 0) { try { Thread.Sleep(sleepTime); initdb = driver.FindElement(By.Id("initdbButton")); i = 1; initdb.Click(); } catch (Exception) { continue; } } Thread.Sleep(sleepTime); IWebElement logout = driver.FindElement(By.Id("LogoutLink")); logout.Click(); Thread.Sleep(sleepTime); login = driver.FindElement(By.Id("LoginLink")); login.Click(); Thread.Sleep(sleepTime); userName = driver.FindElement(By.Id("username")); userName.SendKeys("zahiSimpleRegister"); Thread.Sleep(sleepTime); password = driver.FindElement(By.Id("password")); password.SendKeys("123456"); Thread.Sleep(sleepTime); btnLogin = driver.FindElement(By.Id("btnLogin")); btnLogin.Click(); Thread.Sleep(sleepTime); IWebElement MystoreBtn = driver.FindElement(By.Id("MyStoresPublicLink")); MystoreBtn.Click(); Thread.Sleep(sleepTime * 2); IWebElement crateStoreBtn = driver.FindElement(By.Id("addProductInStore0")); crateStoreBtn.Click(); Thread.Sleep(sleepTime); IWebElement productName = driver.FindElement(By.Id("product-name")); productName.SendKeys("colaTests"); Thread.Sleep(sleepTime); IWebElement productPrice = driver.FindElement(By.Id("product-price")); productPrice.SendKeys("100"); Thread.Sleep(sleepTime); IWebElement productAmount = driver.FindElement(By.Id("product-amount")); productAmount.SendKeys("20"); Thread.Sleep(sleepTime); IWebElement productCat = driver.FindElement(By.Id("product-cat")); productCat.SendKeys("DRINKS"); Thread.Sleep(sleepTime); IWebElement productBtn = driver.FindElement(By.Id("add_product_btn")); productBtn.Click(); Thread.Sleep(sleepTime); alert = driver.SwitchTo().Alert(); string alertText = alert.Text; Assert.IsTrue(alertText.Contains("successfuly added")); alert.Accept(); Thread.Sleep(sleepTime); }
private void AlertMsg(String expMsg) { alert = driver.SwitchTo().Alert(); alertMsg = alert.Text; Assert.AreEqual(expMsg, alertMsg); alert.Accept(); }
/// <summary> /// Add New IEP Driver /// </summary> public void AddNewIEP() { IWebDriver browser = TestRunnerInterface.Map.safePage.browser; IWebElement addNewIEP = Libary.GetPageElement(browser, RunTimeVars.ELEMENTSEARCH.XPATH, "//input [@type='submit'] [@value='Add new IEP']", RunTimeVars.REPEAT_TIMES); addNewIEP.Click(); //Wait for page to Load Libary.WaitForPageText(browser, "IEP Information", RunTimeVars.REPEAT_TIMES); //Set IEP Start Date: = current Date var date = DateTime.Today.ToString("MM/dd/yyyy"); this.SetIEPStartDate(date); //Set IEP End Date: = current Date + 1-year date = DateTime.Today.AddDays(365).ToString("MM/dd/yyyy"); this.SetIEPEndDate(date); //Set Date of Last Evaluation: = current Date - 1-year date = DateTime.Today.AddDays(-365).ToString("MM/dd/yyyy"); this.SetDateofLastEvalation(date); //Primary Disability Condition this.SetPrimaryDisabilityCondition("Autism"); //Add Available Services this.AddService("Aide Services"); //Save the data this.AddButton().Click(); //Wait for IEP Tab to be displayed this.WaitForIEPTabDisplay(RunTimeVars.REPEAT_TIMES); IWebElement serviceFinalized = this.ServiceFinalized(); serviceFinalized.Click(); //***************************************************** //Debug the dialog // Try #1 //When Service Finalized buuton is clicked // a seperate popup is displayed, with the same // browser handle // The popup is NOT a seperate window //just part of the current browser //It has no attributes on the controls to search //The OK button has focus, so just send a Enter key // to the current browser //***************************************************** //The windows handles are the same //var currentWindow = browser.CurrentWindowHandle; //Number of availableWindows = 1 //var availableWindows = new List<string>(browser.WindowHandles); //The OK button has focus, so just send a Enter key // to the current browser //Actions action = new Actions(browser); //action.SendKeys(Keys.Enter).Perform(); //Result - Exception Popup displayed // Try #2 //The OK button has focus, so just send a Enter key // to the Service Finalized button //serviceFinalized.SendKeys(Keys.Enter); //Result - Same behavior Exception Popup displayed // Try #3 //Handle Unknown Alerts //IAlert is an Interface to handle Javascripts alerts IAlert alert = browser.SwitchTo().Alert(); alert.Accept(); //Accept the Alert, same as pressing OK button //alert.Dismiss(); //Don't Accept the Alert, same as pressing Cancel button }
public void ThenClickOnOKFromThePopupToConfirmUploadCancellation_() { IAlert simpleAlert = BrowserConfig._driver.SwitchTo().Alert(); simpleAlert.Accept(); }
// TODO refactor these two following functions and distill out common code and Xpaths // TODO move into CORE /// <summary> /// Delete the named part from the Content Gallery. /// </summary> /// <param name="name"></param> public static void DeletePart(string name) { SearchPartsByName(name); IList <IWebElement> partGridNameFieldElements = null; IWebElement partSearchResultsLineElement; var wait = new WebDriverWait(Driver, TimeSpan.FromSeconds(20)); wait.IgnoreExceptionTypes(typeof(InvalidOperationException), typeof(StaleElementReferenceException)); wait.Until(d => { partSearchResultsLineElement = Driver.FindElement(By.XPath(getXPartsSearchResultsLine)); partGridNameFieldElements = Driver.FindElements(By.XPath("//table[contains(@class,'DataGrid')]//span[./text()='" + name + "']")); if (partGridNameFieldElements == null || partSearchResultsLineElement.Displayed == false || partSearchResultsLineElement.Text.Contains("No")) { return(false); } foreach (var element in partGridNameFieldElements) { element.Click(); WaitClick(getXDeleteButton); IAlert alert = Driver.SwitchTo().Alert(); alert.Accept(); } return(true); }); // Need to check enabled first for this one !! GetEnabledElement("//div[contains(@class,'ExplorerTabs')]//td[./text()='Folders']"); WaitClick("//div[contains(@class,'ExplorerTabs')]//td[./text()='Folders']"); WaitClick("//span[./text()='Deleted Parts']"); GetDisplayedElement("//div[contains(@class,'ExplorerPath')]//span[./text()='Deleted Parts']"); wait.Until(d => { partSearchResultsLineElement = Driver.FindElement(By.XPath(getXPartsSearchResultsLine)); partGridNameFieldElements = Driver.FindElements(By.XPath("//table[contains(@class,'DataGrid')]//span[./text()='" + name + "']")); if (partGridNameFieldElements == null || partSearchResultsLineElement.Displayed == false || partSearchResultsLineElement.Text.Contains("No")) { return(false); } foreach (var element in partGridNameFieldElements) { element.Click(); WaitClick(getXDeleteButton); IAlert alert = Driver.SwitchTo().Alert(); alert.Accept(); } return(true); }); }
//handling Alerts public void handlingAlerts() { IAlert simpleAlert = driver.SwitchTo().Alert(); simpleAlert.Accept(); }
/// <summary> /// Delete all parts with the passed name in their title from the Content Gallery. /// c.f. name* /// </summary> /// <param name="name"></param> public static void DeleteAllParts(string name) { SearchPartsByName(name); IWebElement partSearchResultsLineElement; IWebElement selectAllCheckBoxElement; var wait = new WebDriverWait(Driver, TimeSpan.FromSeconds(20)); wait.IgnoreExceptionTypes(typeof(InvalidOperationException), typeof(StaleElementReferenceException)); wait.Until(d => { partSearchResultsLineElement = Driver.FindElement(By.XPath(getXPartsSearchResultsLine)); selectAllCheckBoxElement = Driver.FindElement(By.XPath("//tr[contains(@class,'DataGridHeader')]//input[contains(@type,'checkbox')]")); if (selectAllCheckBoxElement == null || partSearchResultsLineElement.Displayed == false || partSearchResultsLineElement.Text.Contains("No")) { return(false); } WaitClick("//tr[contains(@class,'DataGridHeader')]//input[contains(@type,'checkbox')]"); WaitClick(getXDeleteButton); var innerwaiter = new WebDriverWait(Driver, TimeSpan.FromSeconds(10)); innerwaiter.IgnoreExceptionTypes(typeof(NoAlertPresentException)); innerwaiter.Until(dd => { IAlert alert = Driver.SwitchTo().Alert(); alert.Accept(); return(true); }); return(true); }); // Need to check enabled first for this one !! GetEnabledElement("//div[contains(@class,'ExplorerTabs')]//td[./text()='Folders']"); WaitClick("//div[contains(@class,'ExplorerTabs')]//td[./text()='Folders']"); WaitClick("//span[./text()='Deleted Parts']"); GetDisplayedElement("//div[contains(@class,'ExplorerPath')]//span[./text()='Deleted Parts']"); wait.Until(d => { partSearchResultsLineElement = Driver.FindElement(By.XPath(getXPartsSearchResultsLine)); selectAllCheckBoxElement = Driver.FindElement(By.XPath("//tr[contains(@class,'DataGridHeader')]//input[contains(@type,'checkbox')]")); if (selectAllCheckBoxElement == null || partSearchResultsLineElement.Displayed == false || partSearchResultsLineElement.Text.Contains("No")) { return(false); } WaitClick("//tr[contains(@class,'DataGridHeader')]//input[contains(@type,'checkbox')]"); WaitClick(getXDeleteButton); var innerwaiter = new WebDriverWait(Driver, TimeSpan.FromSeconds(10)); innerwaiter.IgnoreExceptionTypes(typeof(NoAlertPresentException)); innerwaiter.Until(dd => { IAlert alert = Driver.SwitchTo().Alert(); alert.Accept(); return(true); }); return(true); }); }
private void Buttons() { //Intialization definition IWebDriver driver = new ChromeDriver(); driver.Manage().Window.Maximize(); //Launch URL driver.Navigate().GoToUrl("https://demo.econz.co.nz:1000/AdminPortal/Account/Login/exptest"); //Create Webelement for Username IWebElement uname = driver.FindElement(By.Id("UserName")); uname.SendKeys("jiya"); //Create Webelement for Password IWebElement pwd = driver.FindElement(By.Id("Password")); pwd.SendKeys("Jiya@345"); //Create Webelement for Login button IWebElement LoginButton = driver.FindElement(By.XPath("/html/body/div[3]/form/div/div/div/div[2]/div[3]/input")); LoginButton.Click(); //Login Verification IWebElement Welcome = driver.FindElement(By.XPath("//*[@id='container']/div/div/h2")); // string Welcometxt = Welcome.Text; if (Welcome.Text == "Welcome") { //Console.WriteLine("Login Successfully, Test Passed"); //Creating ButtonsName String string Buttonsname = "RtestName1"; //Create Webelement for UserInterface IWebElement Uinterface = driver.FindElement(By.XPath("/ html / body / div[1] / div / div[2] / ul / li[5] / a")); Uinterface.Click(); //Create Webelement for Buttons IWebElement UButtons = driver.FindElement(By.XPath("/html/body/div[1]/div/div[2]/ul/li[5]/ul/li[3]/a")); UButtons.Click(); System.Threading.Thread.Sleep(1000); // Buttons Page Verification IWebElement buttonHdr = driver.FindElement(By.XPath("/html/body/div[2]/h2")); if (buttonHdr.Text == "Buttons") { //Console.WriteLine("Login Successfully, Test Passed"); //Console.WriteLine("Navigate to Buttons Page Successful"); System.Threading.Thread.Sleep(1000); //Create Webelement for AddNewRecord IWebElement addNew = driver.FindElement(By.XPath("/html/body/div[2]/div/div[1]/a")); addNew.Click(); //Create Webelement for Create Option System.Threading.Thread.Sleep(1000); IWebElement createNew = driver.FindElement(By.XPath("/html/body/div[6]/div[1]/span")); //Create Page Open verification if (createNew.Text == "Create") { //Create Webelement for ButtonName IWebElement bName = driver.FindElement(By.XPath("/html/body/div[6]/div[2]/div/div[2]/input")); bName.SendKeys(Buttonsname); //Create Webelement for ButtonDisplayTitle IWebElement bDisplayTitle = driver.FindElement(By.XPath("/html/body/div[6]/div[2]/div/div[4]/input")); bDisplayTitle.SendKeys("RtestDisplayTitle"); System.Threading.Thread.Sleep(1000); //Create Webelement for ButtonLogo IWebElement bLogo = driver.FindElement(By.XPath("html/body/div[6]/div[2]/div/div[6]/span/span/span[2]/span")); bLogo.Click(); System.Threading.Thread.Sleep(2000); driver.FindElement(By.XPath("/html/body/div[7]/div/ul/li[3]/table/tbody/tr/td[1]/div")).Click(); //var selectElement1 = new SelectElement(driver.FindElement(By.XPath("html/body/div[7]/div/ul"))); //selectElement1.SelectByIndex(2); //Create Webelement for PreCondition IWebElement bPreCondition = driver.FindElement(By.XPath("/html/body/div[6]/div[2]/div/div[8]/input")); bPreCondition.SendKeys("RtestPrecondition"); //Create Webelement for NextScreen IWebElement bNextScreen = driver.FindElement(By.XPath("/html/body/div[6]/div[2]/div/div[10]/span/span/span[2]/span")); //var selectElement = new SelectElement(bNextScreen); //selectElement.SelectByIndex(2); bNextScreen.Click(); System.Threading.Thread.Sleep(2000); driver.FindElement(By.XPath(".//*[@id='NEXT_SCREEN_DBID_listbox']/li[6]")).Click(); //Create Webelement for ValueUpdate IWebElement bValueUpdate = driver.FindElement(By.XPath("/html/body/div[6]/div[2]/div/div[12]/input")); bValueUpdate.SendKeys("RtestValueUpdate"); //Create Webelement for NextState IWebElement bNextState = driver.FindElement(By.XPath("/html/body/div[6]/div[2]/div/div[14]/span/span/span[1]")); //selectElement = new SelectElement(bNextState); //selectElement.SelectByIndex(2); bNextState.Click(); System.Threading.Thread.Sleep(2000); driver.FindElement(By.XPath("//*[@id='NEXT_STATE_DBID_listbox']/li[3]")).Click(); //Create Webelement for PendingState IWebElement bPendingState = driver.FindElement(By.XPath("/html/body/div[6]/div[2]/div/div[16]/span/span/span[2]")); System.Threading.Thread.Sleep(1000); bPendingState.Click(); System.Threading.Thread.Sleep(2000); driver.FindElement(By.XPath("//*[@id='PENDING_STATE_DBID_listbox']/li[3]")).Click(); //Create Webelement for Entity Type IWebElement bEntityType = driver.FindElement(By.XPath("html/body/div[6]/div[2]/div/div[18]/span/span/span[2]")); // selectElement = new SelectElement(bEntityType); //selectElement.SelectByIndex(3); System.Threading.Thread.Sleep(1000); bEntityType.Click(); System.Threading.Thread.Sleep(2000); driver.FindElement(By.XPath("//*[@id='ETT_DBID_listbox']/li[3]")).Click(); //Create Webelement for Override theme IWebElement bOverride = driver.FindElement(By.XPath("/html/body/div[6]/div[2]/div/div[20]/span[1]/span/span[1]")); bOverride.Click(); System.Threading.Thread.Sleep(2000); driver.FindElement(By.XPath("/html/body/div[12]/div/ul/li[1]")).Click(); /**************************Web element not identified, NOT WORKING*********************/ ////Create Webelement for BG Color //IWebElement bBGColor = driver.FindElement(By.XPath("/html/body/div[6]/div[2]/div/div[22]/span/span/span[2]/span")); //bBGColor.Click(); //System.Threading.Thread.Sleep(1000); //Actions action = new Actions(driver); //System.Threading.Thread.Sleep(1000); //IWebElement slider = driver.FindElement(By.XPath("/html/body/div[6]/div[2]/div/div[22]/span/span/span[1]")); //System.Threading.Thread.Sleep(1000); //action.MoveToElement(slider, 200, 100).Click().Build().Perform(); // //MoveToElement(slider,100,16).Click().Build().Perform(); //System.Threading.Thread.Sleep(1000); ////Create Webelement for Color //IWebElement bColor = driver.FindElement(By.XPath("/html/body/div[6]/div[2]/div/div[24]/span/span/span[2]/span")); //bColor.Click(); //System.Threading.Thread.Sleep(1000); //driver.FindElement(By.XPath("//*[@id='964319a6 - 4584 - 4848 - 87d7 - 640b90fc04da']/div[3]/div/div/a")).Click(); ////Create Webelement for Border Color //IWebElement bBorderColor = driver.FindElement(By.XPath("/html/body/div[6]/div[2]/div/div[26]/span/span/span[2]/span")); //bBorderColor.Click(); //System.Threading.Thread.Sleep(3000); //driver.FindElement(By.XPath("//*[@id='861eef67 - de0a - 4b54 - 9590 - a83ce91caccc']/div[2]/div[2]")).Click(); /***************************************************************/ //Create Webelement for Create button IWebElement CreateButton = driver.FindElement(By.XPath("/html/body/div[6]/div[2]/div/div[27]/a[1]")); CreateButton.Click(); System.Threading.Thread.Sleep(5000); string ststr1r; IAlert alert = driver.SwitchTo().Alert(); ststr1r = alert.Text; alert.Accept(); if (buttonHdr.Text == "Buttons" && ststr1r.ToLowerInvariant().Contains("create record is success")) { //Create Webelement for Edit button in the grid IWebElement editbGrid = driver.FindElement(By.XPath(".//*[@id='grid']/div[4]/table/tbody/tr[1]/td[14]/a[1]")); //Create Webelement for Delete button in the grid IWebElement deletebGrid = driver.FindElement(By.XPath(".//*[@id='grid']/div[4]/table/tbody/tr[1]/td[14]/a[2]")); //Create Webelement for Buttonname in the grid IWebElement buttonNameGrid = driver.FindElement(By.XPath(".//*[@id='grid']/div[4]/table/tbody/tr[1]/td[1]")); if (buttonNameGrid.Text == Buttonsname && editbGrid.Text == "Edit" && deletebGrid.Text == "Delete") { Console.WriteLine("Login Successfully, Test Passed"); Console.WriteLine("Navigate to Buttons Page Successful"); Console.WriteLine("Create Page Open successfully"); Console.WriteLine("Created new record successfully"); } else { Console.WriteLine("Login Successfully, Test Passed"); Console.WriteLine("Navigate to Buttons Page Successful"); Console.WriteLine("Create Page Open successfully"); Console.WriteLine("Button Name is not correct"); } } else { Console.WriteLine("Login Successfully, Test Passed"); Console.WriteLine("Navigate to Buttons Page Successful"); Console.WriteLine("Create Page Open successfully"); Console.WriteLine("Record not created successfully, Test Failed"); } } else { Console.WriteLine("Create Page not available, Test Fail"); } } else { Console.WriteLine("Buttons Page not available, Test Fail"); } } else { Console.WriteLine("Login Failed, Test Fail"); } }
protected Guid RegisterApp(string name, Guid?key, string description, string assemblyName, bool canAlreadyExist, bool hasToExistAlready) { this.GoToAdminHomePage(); WebDriverWait wait = new WebDriverWait(this.Driver, TimeSpan.FromSeconds(25)); this.Driver.FindElement(By.Id(Strings.Id.RegisterApplicationLink)).ClickWrapper(this.Driver); wait.Until(ExpectedConditions.ElementIsVisible(By.Id(@Strings.Id.RegisterApplicationForm))); if (key != null) { this.Driver.FindElement(By.Id(Strings.Id.TelemetryKeyInputBox)).Clear(); this.Driver.FindElement(By.Id(Strings.Id.TelemetryKeyInputBox)).SendKeys(key.ToString()); } else { IWebElement ele = this.Driver.FindElement(By.Id(Strings.Id.TelemetryKeyInputBox)); string autoGeneratedGuid = ele.GetAttribute("value"); Assert.AreNotEqual(Guid.Empty, Guid.Parse(autoGeneratedGuid)); key = new Guid(autoGeneratedGuid); } this.Driver.FindElement(By.Id(Strings.Id.ProgramNameInputBox)).SendKeys(name); this.Driver.FindElement(By.Id(Strings.Id.ProgramDescriptionInputBox)).SendKeys(description); this.Driver.FindElement(By.Id(Strings.Id.PrimaryAssemblyNameInputBox)).SendKeys(assemblyName); this.Driver.FindElement(By.Id(Strings.Id.SubmitAppRegistration)).ClickWrapper(this.Driver); IAlert alert = this.Driver.WaitForAlert(10000); if (alert != null) { if (canAlreadyExist) { if (alert.Text != "Use different telemetry key") { Assert.AreEqual($"A program with name [{name}] was already registered by TelimenaSystemDevTeam", alert.Text); } alert.Accept(); return(key.Value); } else { Assert.Fail("Test scenario expects that the app does not exist"); } } else { if (hasToExistAlready) { Assert.Fail("The app should already exist and the error was expected"); } } IWebElement programTable = wait.Until(ExpectedConditions.ElementIsVisible(By.Id(Strings.Id.ProgramSummaryBox))); var infoElements = programTable.FindElements(By.ClassName(Strings.Css.ProgramInfoElement)); Assert.AreEqual(name, infoElements[0].Text); Assert.AreEqual(description, infoElements[1].Text); Assert.AreEqual(key.ToString(), infoElements[2].Text); Assert.AreEqual(assemblyName, infoElements[4].Text); return(key.Value); }
public void ShouldAddCustomer() { // switch to "Add Customer" screen ngDriver.FindElement(NgBy.ButtonText("Bank Manager Login")).Click(); ngDriver.FindElement(NgBy.PartialButtonText("Add Customer")).Click(); // fill new Customer data IWebElement ng_first_name = ngDriver.FindElement(NgBy.Model("fName")); ngDriver.Highlight(ng_first_name); StringAssert.IsMatch("First Name", ng_first_name.GetAttribute("placeholder")); ng_first_name.SendKeys("John"); IWebElement ng_last_name = ngDriver.FindElement(NgBy.Model("lName")); ngDriver.Highlight(ng_last_name); StringAssert.IsMatch("Last Name", ng_last_name.GetAttribute("placeholder")); ng_last_name.SendKeys("Doe"); IWebElement ng_post_code = ngDriver.FindElement(NgBy.Model("postCd")); ngDriver.Highlight(ng_post_code); StringAssert.IsMatch("Post Code", ng_post_code.GetAttribute("placeholder")); ng_post_code.SendKeys("11011"); // NOTE: there are two 'Add Customer' buttons on this form NgWebElement ng_add_customer_button = ngDriver.FindElements(NgBy.PartialButtonText("Add Customer"))[1]; actions.MoveToElement(ng_add_customer_button.WrappedElement).Build().Perform(); ngDriver.Highlight(ng_add_customer_button); ng_add_customer_button.Submit(); // confirm string alert_text = null; try { alert = ngDriver.WrappedDriver.SwitchTo().Alert(); alert_text = alert.Text; StringAssert.StartsWith("Customer added successfully with customer id :", alert_text); alert.Accept(); } catch (NoAlertPresentException ex) { // Alert not present verificationErrors.Append(ex.StackTrace); } catch (WebDriverException ex) { // Alert not handled by PhantomJS verificationErrors.Append(ex.StackTrace); } int customer_id = 0; int.TryParse(alert_text.FindMatch(@"(?<customer_id>\d+)$"), out customer_id); Assert.AreNotEqual(0, customer_id); // switch to "Customers" screen ngDriver.FindElement(NgBy.PartialButtonText("Customers")).Click(); // discover newly added customer ReadOnlyCollection<NgWebElement> ng_customers = ngDriver.FindElements(NgBy.Repeater("cust in Customers")); int customer_count = ng_customers.Count; NgWebElement ng_new_customer = ng_customers.First(cust => Regex.IsMatch(cust.Text, "John Doe")); Assert.IsNotNull(ng_new_customer); actions.MoveToElement(ng_new_customer.WrappedElement).Build().Perform(); ngDriver.Highlight(ng_new_customer); // confirm searching for the customer name ngDriver.FindElement(NgBy.Model("searchCustomer")).SendKeys("John"); ng_customers = ngDriver.FindElements(NgBy.Repeater("cust in Customers")); Assert.AreEqual(1, ng_customers.Count); // show all customers again ngDriver.FindElement(NgBy.Model("searchCustomer")).Clear(); Thread.Sleep(500); wait.Until(ExpectedConditions.ElementIsVisible(NgBy.Repeater("cust in Customers"))); // discover newly added customer again ng_customers = ngDriver.FindElements(NgBy.Repeater("cust in Customers")); ng_new_customer = ng_customers.First(cust => Regex.IsMatch(cust.Text, "John Doe")); // delete new customer NgWebElement ng_delete_button = ng_new_customer.FindElement(NgBy.ButtonText("Delete")); Assert.IsNotNull(ng_delete_button); actions.MoveToElement(ng_delete_button.WrappedElement).Build().Perform(); ngDriver.Highlight(ng_delete_button, 1000); // in slow motion actions.MoveToElement(ng_delete_button.WrappedElement).ClickAndHold().Build().Perform(); Thread.Sleep(1000); actions.Release(); // sometimes actions do not work - for example in this test ng_delete_button.Click(); // wait for customer list to reload Thread.Sleep(1000); wait.Until(ExpectedConditions.ElementIsVisible(NgBy.Repeater("cust in Customers"))); // count the remaining customers ng_customers = ngDriver.FindElements(NgBy.Repeater("cust in Customers")); int new_customer_count = ng_customers.Count; // conrirm the customer count changed Assert.IsTrue(customer_count - 1 == new_customer_count); }
public void ShouldOpenAccount() { // switch to "Add Customer" screen ngDriver.FindElement(NgBy.ButtonText("Bank Manager Login")).Click(); ngDriver.FindElement(NgBy.PartialButtonText("Open Account")).Click(); // fill new Account data NgWebElement ng_customer_select = ngDriver.FindElement(NgBy.Model("custId")); StringAssert.IsMatch("userSelect", ng_customer_select.GetAttribute("id")); ReadOnlyCollection<NgWebElement> ng_customers = ng_customer_select.FindElements(NgBy.Repeater("cust in Customers")); // select customer to log in NgWebElement account_customer = ng_customers.First(cust => Regex.IsMatch(cust.Text, "Harry Potter*")); Assert.IsNotNull(account_customer); account_customer.Click(); NgWebElement ng_currencies_select = ngDriver.FindElement(NgBy.Model("currency")); // use core Selenium SelectElement currencies_select = new SelectElement(ng_currencies_select.WrappedElement); IList<IWebElement> account_currencies = currencies_select.Options; IWebElement account_currency = account_currencies.First(cust => Regex.IsMatch(cust.Text, "Dollar")); Assert.IsNotNull(account_currency); currencies_select.SelectByText("Dollar"); // add the account var submit_button = ngDriver.FindElement(By.XPath("/html/body//form/button[@type='submit']")); StringAssert.IsMatch("Process", submit_button.Text); submit_button.Click(); try { alert = driver.SwitchTo().Alert(); alert_text = alert.Text; StringAssert.StartsWith("Account created successfully with account Number", alert_text); alert.Accept(); } catch (NoAlertPresentException ex) { // Alert not present verificationErrors.Append(ex.StackTrace); } catch (WebDriverException ex) { // Alert not handled by PhantomJS verificationErrors.Append(ex.StackTrace); } // Confirm account added for customer Assert.IsEmpty(verificationErrors.ToString()); // switch to "Customers" screen ngDriver.FindElement(NgBy.PartialButtonText("Customers")).Click(); // get customers ng_customers = ngDriver.FindElements(NgBy.Repeater("cust in Customers")); // discover customer NgWebElement ng_customer = ng_customers.First(cust => Regex.IsMatch(cust.Text, "Harry Potter")); Assert.IsNotNull(ng_customer); // extract the account id from the alert message string account_id = alert_text.FindMatch(@"(?<account_id>\d+)$"); Assert.IsNotNullOrEmpty(account_id); // search accounts of specific customer ReadOnlyCollection<NgWebElement> ng_customer_accounts = ng_customer.FindElements(NgBy.Repeater("account in cust.accountNo")); NgWebElement account_matching = ng_customer_accounts.First(acc => String.Equals(acc.Text, account_id)); Assert.IsNotNull(account_matching); ngDriver.Highlight(account_matching); }