public AlertMessage(IAlert alert) { AlertId = alert.AlertId.ToString(); Timestamp = alert.Timestamp; SymbolName = alert.Symbol.name; Type = alert.Type; Quantity = alert.Quantity; Price = alert.Price; SentTo = alert.SentTo; ResponseCode = alert.ResponseCode; Response = alert.Response; }
private string CloseAlertAndGetItsText() { try { IAlert alert = driver.SwitchTo().Alert(); string alertText = alert.Text; if (acceptNextAlert) { alert.Accept(); } else { alert.Dismiss(); } return(alertText); } finally { acceptNextAlert = true; } }
public void DeleteUser() { SwitchToContent(); BrowserDriver.Instance.Driver.SwitchTo().Frame("ADMIN_EXPLORER"); javascriptClick(By.XPath("//div[text()='777']")); Thread.Sleep(2000); SwitchToContent(); BrowserDriver.Instance.Driver.SwitchTo().Frame("ADMIN_EXPLORER"); javascriptClick(By.XPath(General.Default.DeleteB)); Thread.Sleep(2000); SwitchToPopUps(); //((IJavaScriptExecutor)BrowserDriver.Instance.Driver).ExecuteScript("window.confirm = function(msg) {return true;};"); javascriptClick(By.XPath("//button[text()='Yes']")); Thread.Sleep(2000); IAlert ele = BrowserDriver.Instance.Driver.SwitchTo().Alert(); ele.Accept(); Thread.Sleep(4000); SwitchToContent(); BrowserDriver.Instance.Driver.SwitchTo().Frame("ADMIN_EXPLORER"); }
public async Task ShouldHandleAlertOnFormSubmit() { await driver.GoToUrl(EnvironmentManager.Instance.UrlBuilder.CreateInlinePage(new InlinePage() .WithTitle("Testing Alerts"). WithBody("<form id='theForm' action='javascript:alert(\"Tasty cheese\");'>", "<input id='unused' type='submit' value='Submit'>", "</form>"))); IWebElement element = await driver.FindElement(By.Id("theForm")); await element.Submit(); IAlert alert = await driver.SwitchTo().Alert(); string text = await alert.Text(); await alert.Accept(); Assert.AreEqual("Tasty cheese", text); Assert.AreEqual("Testing Alerts", await driver.Title()); }
public async Task ShouldHandleAlertOnPageLoad() { string pageWithOnLoad = EnvironmentManager.Instance.UrlBuilder.CreateInlinePage(new InlinePage() .WithOnLoad("javascript:alert(\"onload\")") .WithBody("<p>Page with onload event handler</p>")); await driver.GoToUrl(EnvironmentManager.Instance.UrlBuilder.CreateInlinePage(new InlinePage() .WithBody(string.Format("<a id='open-page-with-onload-alert' href='{0}'>open new page</a>", pageWithOnLoad)))); await driver.FindElement(By.Id("open-page-with-onload-alert")).Click(); IAlert alert = await WaitFor(AlertToBePresent(), "No alert found"); string value = await alert.Text(); await alert.Accept(); Assert.AreEqual("onload", value); IWebElement element = await driver.FindElement(By.TagName("p")); await WaitFor(ElementTextToEqual(element, "Page with onload event handler"), "Element text was not 'Page with onload event handler'"); }
public async Task ShouldAllowUsersToAcceptAnAlertInANestedFrame() { string iframe = EnvironmentManager.Instance.UrlBuilder.CreateInlinePage(new InlinePage() .WithBody("<a href='#' id='alertInFrame' onclick='alert(\"framed cheese\");'>click me</a>")); string iframe2 = EnvironmentManager.Instance.UrlBuilder.CreateInlinePage(new InlinePage() .WithBody($"<iframe src='{iframe}' name='iframeWithAlert'></iframe>")); await driver.GoToUrl(EnvironmentManager.Instance.UrlBuilder.CreateInlinePage(new InlinePage() .WithTitle("Testing Alerts") .WithBody($"<iframe src='{iframe2}' name='iframeWithIframe'></iframe>"))); await driver.SwitchTo().Frame("iframeWithIframe").SwitchTo().Frame("iframeWithAlert"); await driver.FindElement(By.Id("alertInFrame")).Click(); IAlert alert = await WaitFor(AlertToBePresent(), "No alert found"); await alert.Accept(); // If we can perform any action, we're good to go Assert.AreEqual("Testing Alerts", await driver.Title()); }
public void AlertOkOrCancelPressCancel() { AlertPage alertdo = new AlertPage(driver); alertdo.AlertWithOkayAndCancelChoose(); alertdo.DisplayConfirmButtonClick(); IAlert alert = driver.SwitchTo().Alert(); alert.Dismiss(); IWebElement AlertResponse = driver.FindElement(By.Id("demo")); try { Assert.IsTrue(AlertResponse.Text.Contains("You Pressed Cancel")); } catch { throw; } }
protected string CloseAlertAndGetItsText() { try { IAlert alert = this.WebDriver.SwitchTo().Alert(); string alertText = alert.Text; if (this.acceptNextAlert) { alert.Accept(); } else { alert.Dismiss(); } return(alertText); } finally { this.acceptNextAlert = true; } }
public void TestConfirmDismiss() { //Clicking button will show a Confirmation Alert with OK and Cancel Button IWebElement button = driver.FindElement(By.Id("confirm")); button.Click(); try { //Get the Alert IAlert alert = driver.SwitchTo().Alert(); //Click OK button, by calling accept() method of Alert Class alert.Dismiss(); //Verify Page displays correct message on Accept IWebElement message = driver.FindElement(By.Id("demo")); Assert.AreEqual("You Dismissed Alert!", message.Text); } catch (NoAlertPresentException e) { Assert.Fail("Alert not found!!"); } }
public void SettingTheValueOfAnAlertThrows() { driver.Url = CreateAlertPage("cheese"); driver.FindElement(By.Id("alert")).Click(); IAlert alert = WaitFor <IAlert>(AlertToBePresent, "No alert found"); try { alert.SendKeys("cheese"); Assert.Fail("Expected exception"); } catch (ElementNotInteractableException) { } finally { alert.Accept(); } }
/// <summary> /// Close Alert and Get Its Txt /// Created by Selenium in default /// </summary> /// <returns></returns> internal static string CloseAlertAndGetItsText(this TestBase uiTest) { try { IAlert alert = uiTest.driver.SwitchTo().Alert(); string alertText = alert.Text; if (uiTest.acceptNextAlert) { alert.Accept(); } else { alert.Dismiss(); } return(alertText); } finally { uiTest.acceptNextAlert = true; } }
public void TestPromptAlert() { driver.Url = "http://toolsqa.wpengine.com/handling-alerts-using-selenium-webdriver/"; driver.Manage().Timeouts().ImplicitWait = TimeSpan.FromMinutes(3); driver.Manage().Window.Maximize(); driver.FindElement(By.XPath("//div[@id='content']/p[11]/button")).Click(); IAlert promptAlert = driver.SwitchTo().Alert(); string alertText = promptAlert.Text; Console.WriteLine("Alert Text is " + alertText); promptAlert.SendKeys("Accepting the alert"); Thread.Sleep(2000); promptAlert.Accept(); driver.Close(); }
static void Main() { string url = "http://testing.todvachev.com/special-elements/alert-box/"; driver.Navigate().GoToUrl(url); //this initialises the alert and clicks on the accept button alert = driver.SwitchTo().Alert(); Console.WriteLine(alert.Text); Console.ReadLine(); alert.Accept(); /* This try and catch block will assist on automation when for some reason the accept button failed but * still bassed and we are making sure that we see the image displayed after OK button and * see the image afer alert text box. */ image = driver.FindElement(By.CssSelector("#post-119 > div > figure > img")); try { if (image.Displayed) { Console.WriteLine("The alert was successfuly accepted and I can see the image"); } } catch (NoSuchElementException) { Console.WriteLine("Something went wrong!!"); } Thread.Sleep(3000); driver.Quit(); }
public void alertpop() { IWebDriver driver = new ChromeDriver(); driver.Navigate().GoToUrl("https://demo.opencart.com/"); driver.Manage().Window.Maximize(); driver.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(10); IJavaScriptExecutor js = (IJavaScriptExecutor)driver; js.ExecuteScript("alert('This is an information box')"); System.Threading.Thread.Sleep(2000); IAlert alert = driver.SwitchTo().Alert(); string alertmsg = alert.Text; alert.Accept(); if (alertmsg.Equals("This is an information box")) { Console.WriteLine("Alert Message match found"); } else { Console.WriteLine("Alert message match not found"); } //conform alert popup js = (IJavaScriptExecutor)driver; js.ExecuteScript("confirm('Do u want to continue(y/n)?')"); System.Threading.Thread.Sleep(2000); alert = driver.SwitchTo().Alert(); alertmsg = alert.Text; alert.Dismiss(); if (alertmsg.Equals("Do u want to continue(y/n)?")) { Console.WriteLine("Alert Message match found"); } else { Console.WriteLine("Alert Message match not found"); } }
public void HandlingAlertsTest() { Init(); driver.Navigate().GoToUrl("http://toolsqa.com/handling-alerts-using-selenium-webdriver/"); Thread.Sleep(5000); try { IWebElement SimpleAlertBtn = driver.FindElement(By.XPath("//button[.= 'Simple Alert']")); SimpleAlertBtn.Click(); Thread.Sleep(2000); IAlert SimpleAlert = driver.SwitchTo().Alert(); Console.WriteLine(SimpleAlert.Text); SimpleAlert.Accept(); driver.SwitchTo().DefaultContent(); IWebElement ConfirmAlertBtn = driver.FindElement(By.XPath("//button[.= 'Confirm Pop up']")); ConfirmAlertBtn.Click(); Thread.Sleep(2000); IAlert ConfirmAlert = driver.SwitchTo().Alert(); Console.WriteLine(ConfirmAlert.Text); ConfirmAlert.Dismiss(); driver.SwitchTo().DefaultContent(); IWebElement PromptPopupBtn = driver.FindElement(By.XPath("//button[.= 'Prompt Pop up']")); PromptPopupBtn.Click(); Thread.Sleep(2000); IAlert PromptAlert = driver.SwitchTo().Alert(); Console.WriteLine(PromptAlert.Text); PromptAlert.SendKeys("Yes"); PromptAlert.Accept(); } catch (Exception e) { Console.WriteLine(e.StackTrace); } finally { driver.Quit(); } }
public static void ListRental() { Thread.Sleep(1000); //Driver.driver.FindElement(By.XPath("//*[@id='main - content]/div/div[1]/div/div[2]/div/div[2]/a[1]")).Click(); Driver.driver.FindElement(By.XPath("//div[@id='main-content']/div/div/div/div[2]/div/div[2]/a")).Click(); Thread.Sleep(1000); Driver.driver.FindElement(By.CssSelector("#main-content > div > form > fieldset > div.field > select")).Click(); Thread.Sleep(1000); Driver.driver.FindElement(By.CssSelector("#main-content > div > form > fieldset > div.field > select > option:nth-child(493)")).Click(); Driver.driver.FindElement(By.CssSelector("#main-content > div > form > fieldset > div:nth-child(4) > div:nth-child(1) > input[type='text']:nth-child(2)")).SendKeys("House for rent"); Driver.driver.FindElement(By.XPath("(//input[@type='text'])[2]")).SendKeys("1600"); Driver.driver.FindElement(By.XPath("(//input[@type='text'])[3]")).SendKeys("235"); Driver.driver.FindElement(By.Name("AvailableDate")).Click(); Thread.Sleep(1000); Driver.driver.FindElement(By.XPath("//div[@id='main-content']/div/form/fieldset/div[5]/div/div/ul/li/div/div/table/tbody/tr[4]/td[2]")).Click(); Driver.driver.FindElement(By.XPath("//*[@id='main-content']/div/form/fieldset/div[6]/div[1]/input")).SendKeys("2"); Driver.driver.FindElement(By.CssSelector("#main-content > div > form > fieldset > div:nth-child(4) > div:nth-child(2) > textarea")).SendKeys("Single bedroom house for rent"); Driver.driver.FindElement(By.CssSelector("#main-content > div > form > fieldset > div:nth-child(5) > div:nth-child(2) > input[type='text']")).SendKeys("yes"); Driver.driver.FindElement(By.CssSelector("#main-content > div > form > fieldset > div:nth-child(6) > div:nth-child(2) > input[type='text']")).SendKeys("Students"); // photo upload IWebElement fileupload = Driver.driver.FindElement(By.CssSelector("#file-upload")); fileupload.Click(); AutoItX3 autoit = new AutoItX3(); autoit.WinActivate("Open"); autoit.Send(@"C:\Users\house-1429409_640.png"); Thread.Sleep(1000); autoit.Send("{Enter}"); Thread.Sleep(1000); Driver.driver.FindElement(By.CssSelector("#main-content > div > form > fieldset > div.ui.grid > div > button.teal.ui.button")).Click(); Thread.Sleep(1000); IAlert alert = Driver.driver.SwitchTo().Alert(); alert.Accept(); Thread.Sleep(1000); }
public void removeOwner() { IWebElement removeStoreOwner = driver.FindElement(By.Id("removeStoreOwner0")); removeStoreOwner.Click(); Thread.Sleep(sleepTime); IWebElement oldOwnerName = driver.FindElement(By.Id("old-owner-name")); oldOwnerName.SendKeys("aviadTest"); Thread.Sleep(sleepTime); IWebElement removeOwner = driver.FindElement(By.Id("aviad-Remove-owner")); removeOwner.Click(); Thread.Sleep(sleepTime * 3); IAlert alert = driver.SwitchTo().Alert(); string alertText = alert.Text; Assert.IsTrue(alertText.Contains("successfuly")); alert.Accept(); }
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(); }
public void Check_Mail_PopUp() { IWebElement FourthLetter = driver.FindElement(By.XPath("//span[text()='Ласкаво просимо на I.UA!']")); Actions actions = new Actions(driver); actions.MoveToElement(FourthLetter).Build().Perform(); IWebElement Popup = driver.FindElement(By.Id("prflpudvmbox_userInfoPopUp")); IWebElement PopupText = Popup.FindElement(By.XPath("//li[2]")); IWebElement MailCheckBox = driver.FindElement(By.XPath("//input[@value='5b026e6ede88']")); MailCheckBox.Click(); Assert.IsTrue(MailCheckBox.Selected); IWebElement DeleteButton = driver.FindElement(By.XPath("//div[@id='fieldset1']/fieldset[3]")); DeleteButton.Click(); IAlert RemoveMailAlert = driver.SwitchTo().Alert(); RemoveMailAlert.Dismiss(); }
static void Main() { url = "http://testing.todvachev.com/special-elements/alert-box/"; driver.Navigate().GoToUrl(url); alert = driver.SwitchTo().Alert(); Console.WriteLine(alert.Text); alert.Accept(); try { image = driver.FindElement(By.CssSelector("#post-119 > div > figure > img")); if (image.Displayed) { Console.WriteLine("The alert was accepted successfully"); } }catch (Exception e) { Console.WriteLine("No that did not work"); } Thread.Sleep(4000); driver.Quit(); }
IAlert GetAlert(TimeSpan timeout) { SwitchToTab(CurrentTab); DateTime beginTime = DateTime.Now; while (DateTime.Now - beginTime < timeout) { try { IAlert alert = driver.SwitchTo().Alert(); return(alert); } catch { } finally { Wait(); } } return(null); }
public void simpleAddOwner() { IWebElement addStoreOwnerBtn = driver.FindElement(By.Id("addStoreOwner0")); addStoreOwnerBtn.Click(); Thread.Sleep(sleepTime); IWebElement OwnerName = driver.FindElement(By.Id("new-owner-name")); OwnerName.SendKeys("aviadTest"); Thread.Sleep(sleepTime); IWebElement AddOwner = driver.FindElement(By.Id("AddOwnerBtn")); AddOwner.Click(); Thread.Sleep(sleepTime * 3); IAlert alert = driver.SwitchTo().Alert(); string alertText = alert.Text; Assert.IsTrue(alertText.Contains("added as owner sussesfuly")); alert.Accept(); }
//*****************************************************************************************************************// //Start Alert pop ups //*****************************************************************************************************************// /*** * Method to accept and close alert and return the text within the alert * @return :alert message ***/ public String closeAlertAndReturnText() { String alertMessage = null; try { if (waitForAlert()) { IAlert alert = browser.SwitchTo().Alert(); alertMessage = alert.Text; alert.Accept(); log.Info("Closed the alert successfully with text->" + alertMessage); Common.testStepPassed("Closed the alert successfully with text->" + alertMessage); } } catch (Exception Ex) { log.Error("Unable to close the alert with text->" + alertMessage); Common.testStepFailed("Exception Caught while accepting the alert, Message is->" + Ex); } return(alertMessage); }
//Obsluga Alert'ow private string handleAlert() { try { IAlert alert = driver.SwitchTo().Alert(); string alertText = alert.Text; if (accAlert = true) { alert.Accept(); } else { alert.Dismiss(); } return(alertText); } finally { accAlert = true; } }
public string addItemToCartPartialLink(string textToSearch) { Driver.FindElement(By.PartialLinkText(textToSearch)).Click(); Thread.Sleep(1000); string productName = Driver.FindElement(By.CssSelector("#tbodyid > h2")).Text; WebDriverWait wait = new WebDriverWait(Driver, TimeSpan.FromSeconds(5)); Driver.FindElement(By.CssSelector("#tbodyid > div.row > div > a")).Click(); Thread.Sleep(1000); IAlert alert = wait.Until(ExpectedConditions.AlertIsPresent()); Assert.Equal("Product added", alert.Text); Thread.Sleep(1000); alert.Accept(); return(productName); }
/// <summary> /// Clicks all accordion menus lists on a member's page /// </summary> public uint CountClickableAccordions() { uint totalClicked = 0; string[] AccoridionIDs = { "abasicConfig", "ainformationDetails", "aQuesSupp", "testReq", "aPaymentReq", "aSupReq", "aRecReq", "aCutOffConfig", "aSDSConfiguration", "aFinAidConfig", "aDynamicText" }; foreach (string id in AccoridionIDs) { try { _utilsValidation.ExplicitWait(DriverUtilities.ElementAccessorType.ID, id, 60); _utilsValidation.Click(DriverUtilities.ElementAccessorType.ID, id); totalClicked++; //Thread.Sleep(200); // works, but not an optimal solution } catch (UnhandledAlertException ex) { IAlert alert = _driver.SwitchTo().Alert(); alert.Dismiss(); Console.WriteLine(ex.Message); } } return(totalClicked); }
public void alerttest() { //ImplicitWait driver.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(10); IWebElement Custid = driver.FindElement(By.Name("cusid")); Custid.SendKeys("422"); IWebElement Subbutton = driver.FindElement(By.Name("submit")); Subbutton.Click(); IAlert alert = driver.SwitchTo().Alert(); String alertMsg = alert.Text; Console.WriteLine("Alert message is = " + alertMsg); alert.Accept(); }
private CoversTabPage ClickRemoveByCoverName_Button(string coverToRemove, MainFlowData data) { //TODO Refactor WebDriverWrapper.WebDriver.Manage().Timeouts().PageLoad = TimeSpan.FromSeconds(5); try { this.WebDriverWrapper.FindAndClick($"//span[text()='{coverToRemove}']/../following-sibling::td/input[@value='Remove']", How.XPath); IAlert alert = this.WebDriverWrapper.WebDriver.SwitchTo().Alert(); var t = alert.Text; alert.Accept(); } catch (WebDriverTimeoutException ex) { } finally { WebDriverWrapper.WebDriver.Manage().Timeouts().PageLoad = TimeSpan.FromSeconds(300); } return(this); }
public void simpleAddMannegers() { IWebElement addStoreBtn = driver.FindElement(By.Id("addStoreManager0")); addStoreBtn.Click(); Thread.Sleep(sleepTime); IWebElement mannegerName = driver.FindElement(By.Id("new-manager-name")); mannegerName.SendKeys("aviadTest"); Thread.Sleep(sleepTime); IWebElement addManagerBtn = driver.FindElement(By.Id("Add-manager-Btn")); addManagerBtn.Click(); Thread.Sleep(sleepTime * 3); IAlert alert = driver.SwitchTo().Alert(); string alertText = alert.Text; Assert.IsTrue(alertText.Contains("manager added successfuly")); alert.Accept(); }
protected void DismissAlert(int maxWaitTime = 0) { IAlert alertHandle = null; maxWaitTime = maxWaitTime > 0 ? maxWaitTime : ElementSyncTimeOut; try { alertHandle = GetAlertHandle(maxWaitTime); if (alertHandle != null) { alertHandle.Dismiss(); } else { throw new Exception("Alert handle not available"); } } catch (Exception ex) { throw new Exception(ex.Message); } }
//WebDriver.FindElement(By.id(“Element”),WaitTime) //alertBox public static void AlertBox(this IWebElement image, IAlert alert) { alert = DriverUtils.driver.SwitchTo().Alert(); Console.WriteLine(alert.Text); alert.Accept(); try { if (image.Displayed) { Console.WriteLine("The alert was successfuly accepted and I can see the image!"); Common.ExtentReport.test.Log(AventStack.ExtentReports.Status.Pass, "The alert was successfuly accepted and I can see the image!"); } } catch (NoSuchElementException) { Console.WriteLine("Something went wrong!!"); Common.ExtentReport.test.Log(AventStack.ExtentReports.Status.Fail, "Something went wrong!!"); string s = BasicMethods.TakeScreenShot(); Common.ExtentReport.test.Log(AventStack.ExtentReports.Status.Fail, MarkupHelper.CreateLabel(" Test case FAILED due to below issue:", ExtentColor.Red)).AddScreenCaptureFromPath(s); } Thread.Sleep(3000); }
/// <summary> /// Method to dismiss condition specify in alert /// </summary> public void AlertDismiss() { try { //Implicitely wait for an alert to appear. DelAlertLoaded = WaitAndGetAlert; _alert = AlertLoadingWait.Until(DelAlertLoaded); _alert.Dismiss(); } catch (WebDriverException e) { if (e.Message.Contains(Exceptions.ERROR_NORESPONSEURL)) { throw new WebDriverException(Utility.GetCommonMsgVariable("KRYPTONERRCODE0007") + ":" + e.Message); } throw new Exception(Utility.GetCommonMsgVariable("KRYPTONERRCODE0054") + ":" + e.Message); } catch (Exception) { throw new Exception(Utility.GetCommonMsgVariable("KRYPTONERRCODE0011")); } }
/// <summary> /// Initializes a new instance of the <see cref="UnhandledAlertException"/> class with /// a specified error message and alert text. /// </summary> /// <param name="message">The message that describes the error.</param> /// <param name="alertText">The text of the unhandled alert.</param> public UnhandledAlertException(string message, string alertText) : base(message) { this.alertText = alertText; this.alert = new UnhandledAlert(alertText); }
private void SetActiveAlert() { if (ActiveAlert == null) { this.Act(CommandType.Action, () => { try { ActiveAlert = this.webDriver.SwitchTo().Alert(); } catch (Exception ex) { throw new FluentException(ex.Message, ex); } }); } }
public Deployer() { _reader = new TfsConfigReader(); _runner = null; _alerter = new EmailAlerter(); }
public HomeController(IAlert alerter) { _alerter = alerter; }
private void AlertMsg(String expMsg) { alert = driver.SwitchTo().Alert(); alertMsg = alert.Text; Assert.AreEqual(expMsg, alertMsg); alert.Accept(); }
/// <summary> /// This method will return true or false depending whether Text is present on alert or not /// </summary> /// <param name="text"></param> /// <param name="keyWordDic"></param> /// <returns>bool</returns> public bool VerifyAlertText(string text, Dictionary<int, string> keyWordDic) { try { DelAlertLoaded = WaitAndGetAlert; _alert = AlertLoadingWait.Until(DelAlertLoaded); string alertText = _alert.Text; var result = false; result = !keyWordDic.Count.Equals(0) ? Utility.DoKeywordMatch(text, alertText) : alertText.Equals(text); //Return remarks if alert text matching failed. if (!result) { Property.Remarks = "Actual alert text '" + alertText + "' does not matches with expected text '" + text + "'"; } return result; } 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"); } catch (Exception) { throw new Exception(Utility.GetCommonMsgVariable("KRYPTONERRCODE0011")); } }
/// <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")); } }
/// <summary> /// Add a new alert /// </summary> /// <param name="alert"></param> public void AddAlert(IAlert alert) { alert.OnTriggerAlert += OnTriggerAlert; m_alerts.Add(alert.GetName(), alert); }
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); }
public void AlertClick(Alert accessor) { this.SetActiveAlert(); if (ActiveAlert == null) return; try { this.Act(CommandType.Action, () => { try { if (accessor == Alert.OK) ActiveAlert.Accept(); else ActiveAlert.Dismiss(); } catch (NoAlertPresentException ex) { throw new FluentException(ex.Message, ex); } }); } finally { ActiveAlert = null; } }