public void ClickOnResults() { if (Selenide.IsElementExists(Driver, Util.GetLocator("ResultsTable_frm"))) { Selenide.SwitchToFrame(Driver, Util.GetLocator("ResultsTable_frm")); if (Selenide.IsElementExists(Driver, Util.GetLocator("ResultsTable1_tbl"))) { Step = "Click on any store number"; StoreSchedulerPage.ClickOnAnyStoreNumber(Driver, Reporter, resultsPath); } else if (Selenide.IsElementExists(Driver, Util.GetLocator("ResultsTable2_tbl"))) { Step = "Click on any store number"; StoreSchedulerPage.ClickOnAnyStoreNumber(Driver, Reporter, resultsPath); } if (Selenide.IsElementExists(Driver, Util.GetLocator("StoreInfoPopUp_win"))) { Step = "Close store popup window"; StoreSchedulerPage.CloseStoreLocatorPopupWindow(Driver, Reporter, resultsPath); } else { Step = "No Results Found"; Selenide.SwitchToDefaultContent(Driver); } } }
/// <summary> /// CloseStoreLocatorPopupWindow clicks on close icon of doctors entry popup /// </summary> /// <param name="Driver">Initialized RemoteWebDriver instance</param> /// <param name="reporter"></param> public static void CloseStoreLocatorPopupWindow(RemoteWebDriver driver, Iteration reporter, string resultsPath) { try { reporter.Add(new Act("Close Store Locator Popup Window")); //Selenide.SwitchToDefaultContent(driver); //Selenide.SwitchToFrame(driver, Locator.Get(LocatorType.ID, "dlg_ifrm_search")); Selenide.WaitForElementNotVisible(driver, Locator.Get(LocatorType.ClassName, "dlg_spinner")); if (Selenide.IsElementExists(driver, Locator.Get(LocatorType.ID, "createmsgdiv"))) { CommonPage.AcceptErrorMessageIfPresent(driver, reporter, resultsPath); } //if (Selenide.IsElementExists(driver, Util.GetLocator("Cancel_btn"))) //{ // Selenide.Click(driver, Util.GetLocator("Cancel_btn")); //} if (Selenide.IsElementExists(driver, Util.GetLocator("StoreInfoCloseBtn_win"))) { Selenide.Click(driver, Util.GetLocator("StoreInfoCloseBtn_win")); } //CommonPage.WaitUntilSpinnerDisappears(driver); //CommonPage.AcceptOrDissmissAlertIfPresent(driver, reporter); //CommonPage.AcceptErrorMessageIfPresent(driver); Selenide.SwitchToDefaultContent(driver); } catch (Exception ex) { CommonPage.AcceptOrDissmissAlertIfPresent(driver, reporter); CommonPage.AcceptErrorMessageIfPresent(driver, reporter, resultsPath); } }
/// <summary> /// AcceptErrorMessageIfPresent method Closes errormessage if error present /// </summary> /// <param name="driver"></param> /// <param name="reporter"></param> /// <param name="postion">Position of the link </param> /// <returns></returns> public static void AcceptErrorMessageIfPresent(RemoteWebDriver driver) { bool error = Selenide.IsElementExists(driver, Locator.Get(LocatorType.XPath, "//div[@id='createmsgdiv']/descendant::img")); if (error) { Selenide.Click(driver, Locator.Get(LocatorType.XPath, string.Format(@"//div[@id='createmsgdiv']/descendant::img"))); //CommonPage.takeScreenshot(driver, screenshotName, saveTo, reporter); } }
/// <summary> /// TypeCostCenterNumber method enters cost center number in cost center number field /// </summary> /// <param name="driver"></param> /// <param name="reporter"></param> /// <param name="costCenterNumber">Store Number</param> public static void TypeCostCenterNumber(RemoteWebDriver driver, Iteration reporter, string costCenterNumber) { reporter.Add(new Act("Enter cost center number in cost center number field")); Selenide.SwitchToFrame(driver, Locator.Get(LocatorType.ID, "iFrameSiteContents")); if (costCenterNumber.Equals("")) { return; } else if (Selenide.IsElementExists(driver, Util.GetLocator("CostCenterNumber1_txt"))) { Selenide.Clear(driver, Util.GetLocator("CostCenterNumber1_txt"), Selenide.ControlType.Textbox); Selenide.SetText(driver, Util.GetLocator("CostCenterNumber1_txt"), Selenide.ControlType.Textbox, costCenterNumber); } //Selenide.SwitchToDefaultContent(driver); }
public void VerifyResults() { if (Selenide.IsElementExists(Driver, Util.GetLocator("ResultsTable_frm"))) { Selenide.SwitchToFrame(Driver, Util.GetLocator("ResultsTable_frm")); if (Selenide.IsElementExists(Driver, Util.GetLocator("ResultsTable1_tbl"))) { Step = "Results Found"; } else if (Selenide.IsElementExists(Driver, Util.GetLocator("ResultsTable2_tbl"))) { Step = "Results Found"; } else { Step = "No Results Found"; Selenide.SwitchToDefaultContent(Driver); } } }
/// <summary> /// ClickOnAnyStoreNumber method clicks on store number in the results /// </summary> /// <param name="driver"></param> /// <param name="reporter"></param> /// <param name="resultsPath"></param> public static void ClickOnAnyStoreNumber(RemoteWebDriver driver, Iteration reporter, string resultsPath) { try { reporter.Add(new Act("Click on store number in results of Stores Directory Page")); //Selenide.SwitchToFrame(driver, Locator.Get(LocatorType.ID, "iFrameSiteContents")); if (Selenide.IsElementExists(driver, Locator.Get(LocatorType.XPath, "//table[@class='formview']/descendant::tr[2]/td//a/nobr"))) { Selenide.Click(driver, Locator.Get(LocatorType.XPath, ("//table[@class='formview']/descendant::tr[2]/td//a/nobr"))); } else if (Selenide.IsElementExists(driver, Locator.Get(LocatorType.XPath, "//table[@class='formview']/descendant::tr[2]/td//a"))) { Selenide.Click(driver, Locator.Get(LocatorType.XPath, ("//table[@class='formview']/descendant::tr[2]/td//a"))); } else { reporter.Add(new Act("Results not found")); } Selenide.WaitForElementNotVisible(driver, Locator.Get(LocatorType.ClassName, "dlg_spinner")); //WaitForPageLoad(driver, 10); //CommonPage.WaitUntilSpinnerDisappears(driver); CommonPage.AcceptOrDissmissAlertIfPresent(driver, reporter); CommonPage.AcceptErrorMessageIfPresent(driver, reporter, resultsPath); //Selenide.SwitchToFrame(driver,Locator.Get(LocatorType.ID, "dlg_ifrm_search")); Selenide.SwitchToDefaultContent(driver); } catch (SystemException sysex) { // this.Reporter.Chapter.Step.Action.Extra = sysex.Message + "<br/>" + sysex.StackTrace; // Reporter.Chapter.Step.Action.IsSuccess = false; CommonPage.AcceptOrDissmissAlertIfPresent(driver, reporter); CommonPage.AcceptErrorMessageIfPresent(driver, reporter, resultsPath); } }
public void ClickOnResults() { if (Selenide.IsElementExists(Driver, Util.GetLocator("ResultsTable_frm"))) { try { Selenide.SwitchToFrame(Driver, Util.GetLocator("ResultsTable_frm")); if (Selenide.IsElementExists(Driver, Util.GetLocator("ResultsTable1_tbl"))) { Step = "Click on any store number"; StoreSchedulerPage.ClickOnAnyStoreNumber(Driver, Reporter); } else if (Selenide.IsElementExists(Driver, Util.GetLocator("ResultsTable2_tbl"))) { Step = "Click on any store number"; StoreSchedulerPage.ClickOnAnyStoreNumber(Driver, Reporter); } if (Selenide.IsElementExists(Driver, Util.GetLocator("StoreInfoPopUp_win"))) { Step = "Close store popup window"; StoreSchedulerPage.CloseStoreLocatorPopupWindow(Driver, Reporter); } else { Step = "No Results Found"; Selenide.SwitchToDefaultContent(Driver); } } catch (Exception ex) { CommonPage.AcceptOrDissmissAlertIfPresent(Driver, Reporter); CommonPage.AcceptErrorMessageIfPresent(Driver); CommonPage.CloseBrowserNewTab(Driver); } } }
/// <summary> /// ClickContentLinks method clicks the content links in the WebPortal /// </summary> /// <param name="driver"></param> /// <param name="reporter"></param> public static void ClickExternalApplicationMenus(RemoteWebDriver driver, Iteration reporter, string resultsPath) { int ExternalMenuCount, LinksCountInExternalMenu; bool IsExternalApplication; int NumberOfExternalMenu; int NumberOfSubmenuInExternalMenu; string LinkTextInExternalMenu; string ExternalMenuText; string submenu1 = string.Empty; //Checks for external application IsExternalApplication = Selenide.IsElementExists(driver, Locator.Get(LocatorType.XPath, "//div[@class='secmenu']/ul/li/a")); if (IsExternalApplication) { //Counts number of Menu's in external application NumberOfExternalMenu = Selenide.GetElementCount(driver, Locator.Get(LocatorType.XPath, "//div[@class='secmenu']/ul/li/a")); for (ExternalMenuCount = 1; ExternalMenuCount <= NumberOfExternalMenu; ExternalMenuCount++) { //Clicks a menu in external application Selenide.Click(driver, Locator.Get(LocatorType.XPath, string.Format(@"//div[@class='secmenu']/ul/li[{0}]/a", ExternalMenuCount + 1))); Thread.Sleep(1000); ExternalMenuText = Selenide.GetText(driver, Locator.Get(LocatorType.XPath, string.Format (@"//div[@class='secmenu']/ul/li[{0}]/a", ExternalMenuCount + 1)), Selenide.ControlType.Label); reporter.Add(new Act(string.Format(@"Click on <b>{0}</b> menu in the external application", ExternalMenuText))); Selenide.Click(driver, Locator.Get(LocatorType.XPath, string.Format(@"//div[@class='secmenu']/ul/li[{0}]/a", ExternalMenuCount + 1))); NumberOfSubmenuInExternalMenu = Selenide.GetElementCount(driver, Locator.Get(LocatorType.XPath, string.Format (@"//div[@class='secmenu']/ul/li[{0}]/ul/li", ExternalMenuCount + 1))); reporter.Add(new Act(string.Format (@"Menu count in each external application(Ex: SIM): <b>{0}</b>", NumberOfSubmenuInExternalMenu))); for (LinksCountInExternalMenu = 1; LinksCountInExternalMenu <= NumberOfSubmenuInExternalMenu; LinksCountInExternalMenu++) { Selenide.Click(driver, Locator.Get(LocatorType.XPath, string.Format (@"//div[@class='secmenu']/ul/li[{0}]/a", ExternalMenuCount + 1))); LinkTextInExternalMenu = Selenide.GetText(driver, Locator.Get(LocatorType.XPath, string.Format (@"//div[@class='secmenu']/ul/li[{0}]/ul/li[{1}]", ExternalMenuCount + 1, LinksCountInExternalMenu)), Selenide.ControlType.Label); reporter.Add(new Act(string.Format (@"Click on " + "<b>" + "{0}" + "</b>" + " submenu In the external application", LinkTextInExternalMenu))); try { Selenide.Click(driver, Locator.Get(LocatorType.XPath, string.Format (@"//div[@class='secmenu']/ul/li[{0}]/a", ExternalMenuCount + 1))); Selenide.Click(driver, Locator.Get(LocatorType.XPath, string.Format (@"//div[@class='secmenu']/ul/li[{0}]/ul/li[{1}]/a", ExternalMenuCount + 1, LinksCountInExternalMenu))); AcceptOrDissmissAlertIfPresent(driver, reporter); AcceptErrorMessageIfPresent(driver); Selenide.WaitForElementNotVisible(driver, Locator.Get(LocatorType.ClassName, "dlg_spinner")); Selenide.WaitForElementNotVisible(driver, Util.GetLocator("Spinner1_img")); Selenide.WaitForElementNotVisible(driver, Util.GetLocator("Spinner2_img")); CloseBrowserNewTab(driver); Selenide.Focus(driver, Locator.Get(LocatorType.XPath, string.Format(@"//td[@class='left']"))); //Thread.Sleep(1000); } catch (Exception ex) { reporter.Add(new Act(string.Format (@"Error found in external application menu link: <b>{0}</b>", LinkTextInExternalMenu))); CommonPage.TakeScreenShotAndAttachToReport(driver, LinkTextInExternalMenu, resultsPath, reporter); } } } } }
/// <summary> /// ClickAllSubMenusInMenu method click the links in each menu of WebPortal /// </summary> /// <param name="driver"></param> /// <param name="reporter"></param> /// <param name="tabName">tabName</param> /// <param name="resultsPath">resultsPath</param> /// public static void ClickAllSubMenusInMenu(RemoteWebDriver driver, Iteration reporter, string resultsPath, string menu) { string subMenu = string.Empty, subMenuAttribute = string.Empty; int linksCountInEachMenu, linksCountInSubMenu, subMenuCount, subMenuCountInEachMenu, clickableLinksInEachMenu, linksCountInSubMenu1 = 0; //Clicks menu Selenide.Click(driver, Locator.Get(LocatorType.XPath, string.Format(@"//div[@class='menu']/ul/li/a[contains(text(),'{0}')]", menu))); //Number of submenu's in a menu //subMenuCountInEachMenu = Selenide.GetElementCount(driver, Locator.Get(LocatorType.XPath,string.Format(@"//div[@class='menu']/ul/li/a[contains(text(),'{0}')]/following-sibling::ul/li", menu))); subMenuCountInEachMenu = Selenide.GetElementCount(driver, Locator.Get(LocatorType.XPath, string.Format (@"//div[@class='menu']/ul/li/a[normalize-space(text())='{0}']/following-sibling::ul/li", menu))); //Number of clickable submenu's in a menu linksCountInEachMenu = Selenide.GetElementCount(driver, Locator.Get(LocatorType.XPath, string.Format(@"//div[@class='menu']/ul/li/a[contains(text(),'{0}')]/following-sibling::ul/li/a[@onclick]", menu))); //Number of clickable submenu2's in a menu linksCountInSubMenu = Selenide.GetElementCount(driver, Locator.Get(LocatorType.XPath, string.Format(@"//div[@class='menu']/ul/li/a[contains(text(),'{0}')]/following-sibling::ul/li/a[@class='drop']/following-sibling::ul/li/a[@onclick]", menu))); //Total clickable links in a menu clickableLinksInEachMenu = linksCountInEachMenu + linksCountInSubMenu; reporter.Add(new Act(string.Format(@"Number of clickable links under <b>{0}</b> menu are: <b>{1}</b>", menu, clickableLinksInEachMenu))); for (subMenuCount = 1; subMenuCount <= subMenuCountInEachMenu; subMenuCount++) { subMenuAttribute = Selenide.GetElement(driver, Locator.Get(LocatorType.XPath, string.Format (@"//div[@class='menu']/ul/li/a[contains(text(),'{0}')]/following-sibling::ul/li[{1}]/a", menu, subMenuCount))).GetAttribute("onclick"); if (subMenuAttribute != null) { if (subMenuAttribute.Contains("PortalMenu") || subMenuAttribute.Contains("Schedule")) { subMenu = string.Empty; while (subMenu == null || subMenu == string.Empty) { //Clicks menu Selenide.Click(driver, Locator.Get(LocatorType.XPath, string.Format(@"//div[@class='menu']/ul/li/a[contains(text(),'{0}')]", menu))); subMenu = Selenide.GetText(driver, Locator.Get(LocatorType.XPath, string.Format(@"//div[@class='menu']/ul/li/a[contains(text(),'{0}')]/following-sibling::ul/li[{1}]/a", menu, subMenuCount)), Selenide.ControlType.Label); } reporter.Add(new Act(String.Format("Click submenu item <b>{0}</b> under <b>{1}</b> menu", subMenu, menu))); //Clicks submenu Selenide.Click(driver, Locator.Get(LocatorType.XPath, string.Format(@"//div[@class='menu']/ul/li/a[contains(text(),'{0}')]/following-sibling::ul/li[{1}]/a", menu, subMenuCount))); AcceptOrDissmissAlertIfPresent(driver, reporter); //Thread.Sleep(5000); Selenide.WaitForElementNotVisible(driver, Locator.Get(LocatorType.ClassName, "dlg_spinner")); Selenide.WaitForElementNotVisible(driver, Util.GetLocator("Spinner1_img")); Selenide.WaitForElementNotVisible(driver, Util.GetLocator("Spinner2_img")); AcceptErrorMessageIfPresent(driver); if (Selenide.IsElementExists(driver, Util.GetLocator("Spinner1_img")) || Selenide.IsElementExists(driver, Util.GetLocator("Spinner2_img"))) { Thread.Sleep(5000); } //WaitUntilSpinnerDisappears(driver); CloseBrowserNewTab(driver); Selenide.Focus(driver, Locator.Get(LocatorType.XPath, string.Format(@"//td[@class='left']"))); //Clicks external applications ClickExternalApplicationMenus(driver, reporter, resultsPath); Thread.Sleep(500); } } if (subMenuAttribute == null) { string submenuname = string.Empty; while (submenuname == null || submenuname == string.Empty) { //Clicks menu Selenide.Click(driver, Locator.Get(LocatorType.XPath, string.Format (@"//div[@class='menu']/ul/li/a[contains(text(),'{0}')]", menu))); Thread.Sleep(250); submenuname = Selenide.GetText(driver, Locator.Get(LocatorType.XPath, string.Format (@"//div[@class='menu']/ul/li/a[contains(text(),'{0}')]/following-sibling::ul/li[{1}]/a/span", menu, subMenuCount)), Selenide.ControlType.Label); } reporter.Add(new Act(string.Format(@"Sub Menu Name is: <b>{0}</b>", submenuname))); //Clicks menu Selenide.Click(driver, Locator.Get(LocatorType.XPath, string.Format(@"//div[@class='menu']/ul/li/a[contains(text(),'{0}')]", menu))); //Clicks submenu1 Selenide.Click(driver, Locator.Get(LocatorType.XPath, string.Format (@"//div[@class='menu']/ul/li/a[contains(text(),'{0}')]/following-sibling::ul/li[{1}]/a", menu, subMenuCount))); //Number of submenu2 in submenu1 linksCountInSubMenu1 = Selenide.GetElementCount(driver, Locator.Get(LocatorType.XPath, string.Format (@"//div[@class='menu']/ul/li/a[contains(text(),'{0}')]/following-sibling::ul/li[{1}]/ul/li/a", menu, subMenuCount))); for (int eachSubLink = 1; eachSubLink <= linksCountInSubMenu1; eachSubLink++) { //Clicks menu Selenide.Click(driver, Locator.Get(LocatorType.XPath, string.Format (@"//div[@class='menu']/ul/li/a[contains(text(),'{0}')]", menu))); //Clicks submenu1 Selenide.Click(driver, Locator.Get(LocatorType.XPath, string.Format (@"//div[@class='menu']/ul/li/a[contains(text(),'{0}')]/following-sibling::ul/li[{1}]/a", menu, subMenuCount))); string sublinkname = Selenide.GetText(driver, Locator.Get(LocatorType.XPath, string.Format (@"//div[@class='menu']/ul/li/a[contains(text(),'{0}')]/following-sibling::ul/li[{1}]/ul/li[{2}]/a", menu, subMenuCount, eachSubLink)), Selenide.ControlType.Label); reporter.Add(new Act(String.Format ("Click submenu link " + "<b>" + "{0}" + "</b>" + " of " + "<b>" + "{1}" + "</b>" + " submenu under " + "<b>" + "{2}" + "</b>" + " menu", sublinkname, submenuname, menu))); //Clicks submenu2 Selenide.Click(driver, Locator.Get(LocatorType.XPath, string.Format (@"//div[@class='menu']/ul/li/a[contains(text(),'{0}')]/following-sibling::ul/li[{1}]/ul/li[{2}]/a", menu, subMenuCount, eachSubLink))); AcceptOrDissmissAlertIfPresent(driver, reporter); AcceptErrorMessageIfPresent(driver); Selenide.WaitForElementNotVisible(driver, Locator.Get(LocatorType.ClassName, "dlg_spinner")); Selenide.WaitForElementNotVisible(driver, Util.GetLocator("Spinner1_img")); Selenide.WaitForElementNotVisible(driver, Util.GetLocator("Spinner2_img")); WaitUntilSpinnerDisappears(driver); if (Selenide.IsElementExists(driver, Util.GetLocator("Spinner1_img")) || Selenide.IsElementExists(driver, Util.GetLocator("Spinner2_img"))) { Thread.Sleep(5000); } CloseBrowserNewTab(driver); ClickExternalApplicationMenus(driver, reporter, resultsPath); } } } }
/// <summary> /// IsMenuAnExternalApplication checks whether menu external application /// </summary> /// <param name="driver">Initialized RemoteWebDriver instance</param> /// <param name="reporter"></param> /// <param name="submenuname">Link Name</param> public static bool IsMenuAnExternalApplication(RemoteWebDriver driver, Iteration reporter, string submenuname) { reporter.Add(new Act(String.Format("Verify whether the menu {0} is an external application", submenuname))); return(Selenide.IsElementExists(driver, Util.GetLocator("ExternalApplication_menu"))); }