/// <summary> /// get the word count /// </summary> /// <param name="fakeText">fake text for debugging</param> /// <returns>word count</returns> public int GetWordCount(string fakeText) { //wait a second for the word count to render Thread.Sleep(TimeSpan.FromSeconds(2)); //fake data setup const char delimiter = ' '; int fakeCount = fakeText.Trim().Split(delimiter).Length; Thread.Sleep(TimeSpan.FromSeconds(1)); WordCountLabel = new WebElementWrapper(ByWordCountLabel); WordCountLabel.Wait(3); WordCountLabel.Text = "Word Count: " + Convert.ToString(fakeCount); int length = "Word Count: ".Length; string text = WordCountLabel.Text; Report.Write("text: " + text); string subText = text.Substring(length - 1); Report.Write("subText: " + subText); int count = Convert.ToInt32(subText); Report.Write("Word count: " + count); return(count); }
/// <summary> /// initialize elements /// </summary> public override void InitElements() { GradeLevelElement gradeLevel = new GradeLevelElement(PageNames.EditAssignmentCourse); GradeFromSelect = gradeLevel.FromSelectElement; GradeToSelect = gradeLevel.ToSelectElement; Course_textbox = new WebElementWrapper(ByCourse_textbox); Department_dropdown = new SelectElementWrapper(new WebElementWrapper(ByDepartment_dropdown)); //Go_button = new WebElementWrapper(ByGo_button); //LimitBySchools_button = new WebElementWrapper(ByLimitBySchools_button); AssignedCourseName_chkbox = new WebElementWrapper(ByAssignedCourseName_chkbox); AvailableCourseName_chkbox = new WebElementWrapper(ByAvailableCourseName_chkbox); NextPage = new WebElementWrapper(ByNextPage); Report.Write("Attempting to initialize Choose Course Grid component."); if (IsChooseCourseGridDisplay()) { ChooseCourseGrid = new EditAssignmentCourseGrid(ChooseGridLocator, false); Report.Write("Initialize Choose Course Grid component success."); } else { Report.Write("Initialize Choose Course Grid component failed."); } try { //Sometimes the page will not have Selected Course grid display. //Sometimes the page display warning message, but not grid. //If the grid is not display, the test should continue to run. Not a failure for this page. //Check to see if the grid is display first before initializing the grid. By ByGrid = By.CssSelector(SelectedGridLocator); WebElementWrapper Grid = new WebElementWrapper(ByGrid); Grid.Wait(3); try { //The grid was found. Check to see if warning message is display SelectedCourseWarning = new WebElementWrapper(BySelectedCourseWarning); SelectedCourseWarning.Wait(3); Report.Write("The Selected Course Grid warning message: " + BySelectedCourseWarning.ToString() + " was found."); } catch (Exception) { //The grid was found. ChooseCourseWarning message is not display. SelectedCourseGrid = new EditAssignmentCourseGrid(SelectedGridLocator, false); } } catch { Report.Write("The Selected Course Grid: ByCssSelector: " + SelectedGridLocator + " was not found."); } if (Driver.WrappedDriver.GetType() == typeof(DummyDriver)) { ChooseCourseGrid = new EditAssignmentCourseGrid(ChooseGridLocator, true); SelectedCourseGrid = new EditAssignmentCourseGrid(SelectedGridLocator, true); } }
public void SelectColumn(string columnName) { By by = GetColumnLinkLocator(columnName); WebElementWrapper column = new WebElementWrapper(by); column.Wait(3).Click(); this.DriverCommands.WaitAndMeasurePageLoadTime(); }
/// <summary> /// verify grid is showing standard mode /// </summary> public void VerifyGridIsShowingStandardMode() { StandardColumn = new WebElementWrapper(ByStandardColumn); string expect = "Standard"; string actualColumnValue = StandardColumn.Wait(3).Text; Assert.IsTrue(actualColumnValue.Contains(expect), "The grid first column did not contain expected value: " + expect + ". Actual: " + actualColumnValue); }
/// <summary> /// Click on Item Remove link /// </summary> public void ClickRemove(int Itemno) { Itemno = Itemno - 1; string ItemId = "ctl0" + Itemno.ToString(); By ByRemoveItem_Link = By.Id((ControlPrefix + "RepeaterTestItemsLinkedToPassage_" + ItemId + "_LinkButtonUnLink")); WebElementWrapper RemoveItem_Link = new WebElementWrapper(ByRemoveItem_Link); RemoveItem_Link.InitializeWebElement(); RemoveItem_Link.Wait(3).Click(); }
private void SetUniqueControlIdentifiers() { AnswerChoiceTabs = new Dictionary <string, ItemTypeTabForm>(); InteractionTabs.WaitUntilVisible(); //get the tabs ReadOnlyCollection <IWebElement> webElementTabs = Driver.FindElements(ByInteractionTabs); Report.Write("Found the elements by: '" + ByInteractionTabs.ToString() + "'."); if (Driver.WrappedDriver.GetType() == typeof(DummyDriver)) { DummyWebElement dummy1 = new DummyWebElement(); dummy1.FakeAttributeId = "tabfc5d6a01-9539-46d2-966a-15ab568698e8"; dummy1.FakeAttributeClass = "active"; DummyWebElement dummy2 = new DummyWebElement(); dummy2.FakeAttributeId = "tabe2e3dda0-5708-40b5-8354-198a1232176a"; dummy2.FakeAttributeClass = ""; DummyWebElement dummy3 = new DummyWebElement(); dummy3.FakeAttributeId = "tab76962807-988c-4d06-b977-9f9a4c35d87f"; dummy3.FakeAttributeClass = ""; List <IWebElement> list = new List <IWebElement> { dummy1, dummy2, dummy3 }; webElementTabs = new ReadOnlyCollection <IWebElement>(list); } int dummyindex = 1; int index = 0; foreach (var webElement in webElementTabs) { string tempTabId = webElement.GetAttribute("id"); Report.Write("Got the attribute: 'id' = '" + tempTabId + "' of this element by: '" + ByInteractionTabs.ToString() + "'."); //parse the tab ids to get the root id int from = tempTabId.IndexOf("tab") + "tab".Length; string tabId = tempTabId.Substring(from); string tabClass = webElement.GetAttribute("class"); Report.Write("Got the attribute: 'class' = '" + tabClass + "' of this element by: '" + ByInteractionTabs.ToString() + "'."); InteractionTab = new WebElementWrapper(By.CssSelector("#tab" + tabId + " > a")); InteractionTab.Wait(3).Text = "" + dummyindex; dummyindex++; string tabName = InteractionTab.Text.Trim(); //string tabName, string tabId, string tabClass Report.Write("Tab control identifier by tabName: " + tabName + "; tabId: " + tabId + "; tabClass: " + tabClass); //click the tab to make it visible, then create the item type tab object InteractionTab.Click(); //create an item type tab object var itemTypeFormTab = new ItemTypeTabForm(ItemType.InlineResponse, tabName, tabId, tabClass, index, ControlPrefix); //add the item type tab object to the collection (1, 2, 3) AnswerChoiceTabs.Add(tabName, itemTypeFormTab); index = index + 1000; } }
/// <summary> /// Determine if the choose course grid is display. If grid with courses data are display, return true. /// </summary> public bool IsChooseCourseGridDisplay() { try { //Sometimes the page will not have Choose Course grid display. //Sometimes the page display warning message, but not grid. //If the grid is not display, the test should continue to run. Not a failure for this page. //Check to see if the grid is display first By ByGrid = By.CssSelector(ChooseGridLocator); WebElementWrapper Grid = new WebElementWrapper(ByGrid); Grid.Wait(3); try { //The grid was found. Check to see if warning message is display ChooseCourseWarning = new WebElementWrapper(ByChooseCourseWarning); ChooseCourseWarning.Wait(3); Report.Write("The Choose Course Grid warning message: " + ByChooseCourseWarning.ToString() + " was found."); } catch (Exception) { //ChooseCourseWarning message is not display. //The grid is display with available courses data return(true); } } catch { //The grid is not found Report.Write("The Choose Course Grid: ByCssSelector: " + ChooseGridLocator + " was not found."); return(false); } return(false); }
/// <summary> /// Upload File using AutoIt (Old Framework Method adapted to New Framework) /// </summary> /// <param name="autoItData">AutoIt Data Object Instance</param> /// <param name="uploadButtonOrLink">Upload button or Link which when clicked gives the File Upload dialog</param> public void UploadFile(AutoItData autoItData, WebElementWrapper uploadButtonOrLink) { //var autoItExecutablePath = combinePathAndVerify(TestDeploymentDir, "AutoIt3.exe"); var autoItExecutablePath = CombinePathAndVerifyFileExists(autoItData.DeploymentDirectory, autoItData.AutoItExecutableName); var autoItScriptPath = ""; if (this.TestConfiguration.BrowserName == BrowserType.INTERNET_EXPLORER) { autoItScriptPath = CombinePathAndVerifyFileExists(autoItData.DeploymentDirectory, autoItData.UploadImageInIEScriptName); } else if (this.TestConfiguration.BrowserName == BrowserType.CHROME) { autoItScriptPath = CombinePathAndVerifyFileExists(autoItData.DeploymentDirectory, autoItData.UploadImageInChromeScriptName); } else { autoItScriptPath = CombinePathAndVerifyFileExists(autoItData.DeploymentDirectory, autoItData.UploadImageScriptName); } var pathofFileToBeUploaded = CombinePathAndVerifyFileExists(autoItData.DeploymentDirectory, autoItData.FileNameToBeUploaded); Action doBeforeUpload = () => { System.Threading.Thread.Sleep(1000); uploadButtonOrLink.Wait(1).Click(); }; var processStartInfo = new ProcessStartInfo() { FileName = autoItExecutablePath, WorkingDirectory = autoItData.DeploymentDirectory, Arguments = string.Format("{0} {1}", autoItScriptPath, pathofFileToBeUploaded) }; RunAutoItProcess(processStartInfo, doBeforeUpload, "Auto it upload file script failed to terminate within 30 seconds"); }
/// <summary> /// focus on main content area, to stop hover over menu /// </summary> public void FocusOnMainContentArea() { try { Point dummyPoint = new Point(0, 0); Point point; GlobalAppHeader = new WebElementWrapper(ByGlobalAppHeader); GlobalNav = new WebElementWrapper(ByGlobalNav); MainContentArea = new WebElementWrapper(ByMainContentArea); AppTitle = new WebElementWrapper(ByAppTitle); //new DriverCommands(Driver).GetScreenshotAndPageSource(); //move to the header GlobalAppHeader.Wait(3); GlobalAppHeader.LocationOnScreenOnceScrolledIntoView = dummyPoint; point = GlobalAppHeader.LocationOnScreenOnceScrolledIntoView; GlobalAppHeader.Location = dummyPoint; point = GlobalAppHeader.Location; if (this.TestConfiguration.BrowserName != BrowserType.SAFARI) { GlobalAppHeader.MoveToElement(); } //new DriverCommands(Driver).GetScreenshotAndPageSource(); //move to the global nav GlobalNav.Wait(3); GlobalNav.LocationOnScreenOnceScrolledIntoView = dummyPoint; point = GlobalNav.LocationOnScreenOnceScrolledIntoView; GlobalNav.Location = dummyPoint; point = GlobalNav.Location; if (this.TestConfiguration.BrowserName != BrowserType.SAFARI) { GlobalNav.MoveToElement(); } //new DriverCommands(Driver).GetScreenshotAndPageSource(); //move to the main content area MainContentArea.Wait(3); MainContentArea.LocationOnScreenOnceScrolledIntoView = dummyPoint; point = MainContentArea.LocationOnScreenOnceScrolledIntoView; MainContentArea.Location = dummyPoint; point = MainContentArea.Location; if (this.TestConfiguration.BrowserName != BrowserType.SAFARI) { MainContentArea.MoveToElement(); } try { AppTitle.Wait(3); if (this.TestConfiguration.BrowserName != BrowserType.SAFARI) { AppTitle.MoveToElement(); } AppTitle.Click(); } catch (Exception ex) { //new DriverCommands(Driver).GetScreenshotAndPageSource(); //click on main content area MainContentArea.Click(); } } catch (Exception e) { throw new Exception("\nInnerException:\n" + e.InnerException + "\nStackTrace:\n" + e.StackTrace, e); } }