/// <summary> /// SelectApplication method selects the application at login screen /// </summary> /// <param name="Driver">Initialized RemoteWebDriver instance</param> /// <param name="applicationName">Link Name</param> public static void SelectApplication(RemoteWebDriver driver, Iteration reporter, string applicationName) { reporter.Add(new Act(String.Format("Select the {0} link ", applicationName))); Selenide.SwitchToFrame(driver, Locator.Get(LocatorType.ID, "dlg_ifrm_modal2")); try { Actions action = new Actions(driver); IWebElement application = Selenide.GetElement(driver, Locator.Get(LocatorType.XPath, string.Format(@"//table[@id='tblSelect']/descendant::a[contains(@title,""{0}"")]/div", applicationName))); //Selenide.Click(driver,Locator.Get(LocatorType.XPath, string.Format(@"//table[@id='tblSelect']/descendant::a[contains(@title,""{0}"")]/div", applicationName))); //Selenide.Click(driver, Locator.Get(LocatorType.XPath, string.Format(@"//table[@id='tblSelect']/descendant::a[contains(@title,'{0}')]/div", applicationName))); action.MoveToElement(application).Click().Build().Perform(); WaitForPageLoad(driver, 10); Selenide.WaitForElementNotVisible(driver, Locator.Get(LocatorType.ClassName, "dlg_spinner")); Selenide.SwitchToDefaultContent(driver); } catch (Exception ex) { throw new Exception(String.Format("{ 0 } link not found in the website", applicationName)); } }
/// <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); } } } }