//Purpose : to Select the class created using template option in Global home page public void SelectTemplateClass() { try { WebDriver.SwitchTo().Window(WebDriver.WindowHandles.First()); if (GenericHelper.IsElementPresent(By.Id("lightboxid"))) { bool isAnnouncementClose = GenericHelper.CloseAnnouncementPage(); if (isAnnouncementClose) { GenericHelper.Logs("Announcement Pop up has been closed successfully", "Passed"); } else { GenericHelper.Logs("Announcement Pop up has not been closed", "Failed"); } } GenericHelper.WaitUntilElement(By.Id("tblMain")); int classCount = WebDriver.FindElements(By.XPath("//table[@id='tblMain']/tbody/tr")).Count; string classname = string.Empty; for (int i = 1; i <= classCount; i++) { if (Browser.Equals("IE")) { classname = WebDriver.FindElement(By.XPath("//table[@id='tblMain']/tbody/tr[" + i.ToString(CultureInfo.InvariantCulture) + "]")).GetAttribute("innerText"); } if (Browser.Equals("FF") || Browser.Equals("GC")) { classname = WebDriver.FindElement(By.XPath("//table[@id='tblMain']/tbody/tr[" + i.ToString(CultureInfo.InvariantCulture) + "]")).Text; } if (classname.Contains(DatabaseTools.GetClass(Enumerations.ClassType.NovaNETTemplate))) { if (Browser.Equals("FF") || Browser.Equals("IE")) { WebDriver.FindElement(By.XPath("//table[@id='tblMain']/tbody/tr[" + i.ToString(CultureInfo.InvariantCulture) + "]/td/div/table/tbody/tr/td/div/div")).SendKeys(""); } WebDriver.FindElement(By.XPath("//table[@id='tblMain']/tbody/tr[" + i.ToString(CultureInfo.InvariantCulture) + "]/td/div/table/tbody/tr/td/div/div")).Click(); break; } else if (i == classCount) { GenericHelper.Logs(DatabaseTools.GetClass(Enumerations.ClassType.NovaNETTemplate) + " class not found in global home page", "FAILED"); } } } catch (Exception e) { GenericHelper.Logs(e.ToString(), "FAILED"); throw new Exception(e.ToString()); } }
//Purpose: To click Create Course button in classes page public void ClickCreateCourse() { try { int rowcount = WebDriver.FindElements(By.XPath(Table_tblmain + "/tbody/tr")).Count; for (int i = 1; i <= rowcount; i++) { string classname = null; if (Browser.Equals("IE")) { classname = WebDriver.FindElement(By.XPath(Table_tblmain + "/tbody/tr[" + i.ToString(CultureInfo.InvariantCulture) + "]")).GetAttribute("innerText"); } if (Browser.Equals("FF") || Browser.Equals("GC")) { classname = WebDriver.FindElement(By.XPath("//table[@id='tblMain']/tbody/tr[" + i + "]")).Text; } if (classname != null && classname.Contains(DatabaseTools.GetClass(Enumerations.ClassType.NovaNETTemplate))) { Thread.Sleep(2000); if (Browser.Equals("FF") || Browser.Equals("IE")) { WebDriver.FindElement(By.XPath(Table_tblmain + "/tbody/tr[" + i.ToString(CultureInfo.InvariantCulture) + "]/td/div/table/tbody/tr/td" + Button_Createcourse)).SendKeys(""); } WebDriver.FindElement(By.XPath(Table_tblmain + "/tbody/tr[" + i.ToString(CultureInfo.InvariantCulture) + "]/td/div/table/tbody/tr/td" + Button_Createcourse)).Click(); break; } else if (i == rowcount) { GenericHelper.Logs("Create course button not found for the corresponding class", "FAILED"); } } } catch (Exception e) { GenericHelper.Logs(e.ToString(), "FAILED"); throw new Exception(e.ToString()); } }
//Purpose : To select the class in Enrollment tab of Manage Organization Page public void SelectClass(Enumerations.ClassType classType) { try { string classname = DatabaseTools.GetClass(classType); GenericHelper.SelectWindow("Manage Organization"); GenericHelper.WaitUntilElement(By.Id("frm")); WebDriver.SwitchTo().Frame("frm"); WebDriver.SwitchTo().DefaultContent(); GenericHelper.WaitUntilElement(By.Id("frm")); WebDriver.SwitchTo().Frame("frm"); WebDriver.SwitchTo().Frame("ifrmright"); GenericHelper.WaitUntilElement(By.Id("spnSearch")); WebDriver.FindElement(By.Id("spnSearch")).Click(); GenericHelper.WaitUntilElement(By.Id("txtSectionDetail")); WebDriver.FindElement(By.Id("txtSectionDetail")).SendKeys(classname); GenericHelper.WaitUntilElement(By.Id("btnSearch")); WebDriver.FindElement(By.Id("btnSearch")).Click(); try { bool isEnrollTablePresent = GenericHelper.IsElementPresent(By.Id("MainTable")); if (isEnrollTablePresent) { string noRecordMessagePresent = WebDriver.FindElement(By.Id("MainTable")).Text; if (noRecordMessagePresent.Contains("There are no classes or courses available to you.")) { GenericHelper.Logs("There are no classes or courses available to you.", "FAILED"); throw new NoSuchElementException("There are no classes or courses available to you."); } } } catch (Exception e) { GenericHelper.Logs(e.ToString(), "FAILED"); throw new Exception(e.ToString()); } GenericHelper.WaitUntilElement(By.XPath("//table[@class='CourseLabelHeight']/tbody/tr/td/span")); #region Browser Selection if (Browser.Equals("FF") || Browser.Equals("GC")) { if (classname.StartsWith(WebDriver.FindElement(By.XPath("//table[@class='CourseLabelHeight']/tbody/tr/td/span")).Text.TrimEnd('.'))) { GenericHelper.WaitUntilElement(By.XPath(ImageExpand)); WebDriver.FindElement(By.XPath(ImageExpand)).Click(); GenericHelper.WaitUntilElement(By.CssSelector("input[id$='allcourse']")); WebDriver.FindElement(By.CssSelector("input[id$='allcourse']")).Click(); GenericHelper.Logs("Searched class " + classname + " found", "PASSED"); } else { GenericHelper.Logs("Searched class " + classname + " not found", "FAILED"); } } if (Browser.Equals("IE")) { if (classname.StartsWith(WebDriver.FindElement(By.XPath("//table[@class='CourseLabelHeight']/tbody/tr/td/span")).Text.TrimEnd('.'))) { GenericHelper.WaitUntilElement(By.Id("grdEnrollmentClasses__ctl0_expandImgDiv")); WebDriver.FindElement(By.Id("grdEnrollmentClasses__ctl0_expandImgDiv")).Click(); GenericHelper.WaitUntilElement(By.CssSelector("input[id$='allcourse']")); WebDriver.FindElement(By.CssSelector("input[id$='allcourse']")).Click(); GenericHelper.Logs("Searched class " + classname + " found", "PASSED"); } else { GenericHelper.Logs("Searched class " + classname + " not found", "FAILED"); } } #endregion Browser Selection } catch (Exception e) { GenericHelper.Logs(e.ToString(), "FAILED"); if (GenericHelper.IsPopUpWindowPresent("Manage Organization")) { GenericHelper.SelectWindow("Manage Organization"); WebDriver.Close(); } throw new Exception(e.ToString()); } }
//purpose - to search for assigned to copy class public void ToSearchForAssigned(Enumerations.ClassType classtype) { try { GenericHelper.SelectWindow("Manage Organization"); WebDriver.SwitchTo().Frame("frm"); GenericHelper.WaitUntilElement(By.Id("spnSearch")); WebDriver.FindElement(By.Id("spnSearch")).Click(); string className = DatabaseTools.GetClass(classtype); GenericHelper.WaitUntilElement(By.Id("txtSectionDetail")); WebDriver.FindElement(By.Id("txtSectionDetail")).Clear(); WebDriver.FindElement(By.Id("txtSectionDetail")).SendKeys(className); GenericHelper.WaitUntilElement(By.Id("SearchSections")); IWebElement searchSection = WebDriver.FindElement(By.Id("SearchSections")); new Actions(WebDriver).Click(searchSection).Perform(); // Purpose: Method To Verify Assigned to Copy State GenericHelper.SelectWindow("Manage Organization"); WebDriver.SwitchTo().Frame("frm"); GenericHelper.WaitUntilElement(By.Id("grdClasses$divContent")); #region Browser Selection if (Browser.Equals("FF") || Browser.Equals("GC")) { if (WebDriver.FindElement(By.Id("grdClasses$divContent")).Text.Contains(className)) { GenericHelper.Logs(string.Format("Class '{0}' found in the grid after searching it from the search option.", className), "PASSED"); } else { GenericHelper.Logs(string.Format("Class '{0}' not found in the grid after searching it from the search option.", className), "FAILED"); throw new NoSuchElementException(string.Format("Class '{0}' not found in the grid after searching it from the search option.", className)); } } if (Browser.Equals("IE")) { if (WebDriver.FindElement(By.Id("grdClasses$divContent")).GetAttribute("innerText").Contains(className)) { GenericHelper.Logs(string.Format("Class '{0}' found in the grid after searching it from the search option.", className), "PASSED"); } else { GenericHelper.Logs(string.Format("Class '{0}' not found in the grid after searching it from the search option.", className), "FAILED"); throw new NoSuchElementException(string.Format("Class '{0}' not found in the grid after searching it from the search option.", className)); } } #endregion Browser Selection Stopwatch sw = new Stopwatch(); sw.Start(); int minutesToWait = Int32.Parse(ConfigurationManager.AppSettings["AssignedToCopyInterval"]); while (sw.Elapsed.Minutes < minutesToWait) { IWebElement redTextPresent = WebDriver.FindElement(By.TagName("body")); if (redTextPresent.Text.Contains("[Assigned to copy]") == false) { break; } { GenericHelper.SelectWindow("Manage Organization"); WebDriver.SwitchTo().Frame("frm"); GenericHelper.WaitUntilElement(By.Id("spnSearch")); WebDriver.FindElement(By.Id("spnSearch")).Click(); Thread.Sleep(5000);// This I added to load the search panel GenericHelper.WaitUntilElement(By.Id("txtSectionDetail")); WebDriver.FindElement(By.Id("txtSectionDetail")).Clear(); WebDriver.FindElement(By.Id("txtSectionDetail")).SendKeys(className); GenericHelper.WaitUntilElement(By.Id("SearchSections")); IWebElement searchClass = WebDriver.FindElement(By.Id("SearchSections")); new Actions(WebDriver).Click(searchClass).Perform(); Thread.Sleep(10000); GenericHelper.SelectWindow("Manage Organization"); WebDriver.SwitchTo().Frame("frm"); } } if (GenericHelper.IsElementPresent(By.XPath(Text_AssignedToCopy))) { GenericHelper.Logs(string.Format("[AssignedToCopy] state has not validated under:'{0}' minutes for copying '{1}'.", minutesToWait, className), "FAILED"); } else { GenericHelper.Logs(string.Format("[AssignedToCopy] state has validated under:'{0}' minutes for copying '{1}'.", minutesToWait, className), "PASSED"); } sw.Stop(); sw = null; } catch (Exception e) { GenericHelper.Logs(e.ToString(), "FAILED"); if (GenericHelper.IsPopUpWindowPresent("Manage Organization")) { GenericHelper.SelectWindow("Manage Organization"); WebDriver.Close(); } throw new Exception(e.ToString()); } }
//purpose - to search for assigned to copy class public void ToSearchForAssigned(Enumerations.ClassType classtype) { GenericHelper.SelectWindow("Manage Organization"); GenericHelper.WaitUntilElement(By.Id("frm")); WebDriver.SwitchTo().Frame("frm"); GenericHelper.WaitUntilElement(By.Id("spnSearch")); WebDriver.FindElement(By.Id("spnSearch")).Click(); WebDriver.SwitchTo().ActiveElement(); string className = DatabaseTools.GetClass(classtype); GenericHelper.WaitUntilElement(By.Id("txtSectionDetail")); WebDriver.FindElement(By.Id("txtSectionDetail")).Clear(); WebDriver.FindElement(By.Id("txtSectionDetail")).SendKeys(className); WebDriver.FindElement(By.Id("SearchSections")).Click(); Thread.Sleep(3000); // Purpose: Method To Verify Assigned to Copy State GenericHelper.SelectWindow("Manage Organization"); WebDriver.SwitchTo().Frame("frm"); GenericHelper.WaitUntilElement(By.Id("grdClasses$divContent")); Stopwatch sw = new Stopwatch(); sw.Start(); int minutesToWait = Int32.Parse(ConfigurationManager.AppSettings["AssignedToCopyInterval"]); while (sw.Elapsed.Minutes < minutesToWait) { IWebElement redTextPresent = WebDriver.FindElement(By.TagName("body")); if (redTextPresent.Text.Contains("[Assigned to copy]")) { GenericHelper.SelectWindow("Manage Organization"); GenericHelper.WaitUntilElement(By.Id("frm")); WebDriver.SwitchTo().Frame("frm"); Thread.Sleep(20000); GenericHelper.WaitUntilElement(By.Id("spnSearch")); WebDriver.FindElement(By.Id("spnSearch")).Click(); Thread.Sleep(3000); WebDriver.SwitchTo().ActiveElement(); GenericHelper.WaitUntilElement(By.Id("txtSectionDetail")); WebDriver.FindElement(By.Id("txtSectionDetail")).Clear(); WebDriver.FindElement(By.Id("txtSectionDetail")).SendKeys(className); WebDriver.FindElement(By.Id("SearchSections")).Click(); Thread.Sleep(3000); WebDriver.SwitchTo().ActiveElement(); GenericHelper.SelectWindow("Manage Organization"); WebDriver.SwitchTo().Frame("frm"); GenericHelper.WaitUntilElement(By.Id("grdClasses$divContent")); #region Browser Selection if (Browser.Equals("FF")) { if (WebDriver.FindElement(By.Id("grdClasses$divContent")).Text.Contains(className)) { GenericHelper.Logs("Class found in the grid after searching it from the search option", "PASSED"); } else { GenericHelper.Logs("Class not found in the grid after searching it from the search option", "FAILED"); } } if (Browser.Equals("IE")) { if (WebDriver.FindElement(By.Id("grdClasses$divContent")).GetAttribute("innerText").Contains(className)) { GenericHelper.Logs("Class found in the grid after searching it from the search option", "PASSED"); } else { GenericHelper.Logs("Class not found in the grid after searching it from the search option", "FAILED"); } } #endregion Browser Selection } else { break; } } try { IWebElement redTextPresent = WebDriver.FindElement(By.TagName("body")); if (redTextPresent.Text.Contains("[Assigned to copy]")) { GenericHelper.Logs(string.Format("[AssignedToCopy] state has not validated under:'{0}' minutes for copying '{1}'.", minutesToWait, className), "FAILED"); } else { GenericHelper.Logs(string.Format("[AssignedToCopy] state has validated under:'{0}' minutes for copying '{1}'.", minutesToWait, className), "PASSED"); } } catch (Exception e) { GenericHelper.Logs(e.Message, "FAILED"); } sw.Stop(); sw = null; }