예제 #1
0
        /// <summary>
        /// Returns true if the text is found under the first column of the table
        /// </summary>
        /// <param name="tableBodyElem">The table element</param>
        /// <param name="tableElemBodyBy">The tbody element within the table as it exists in it's By type</param>
        /// <param name="expectedText">The text you expect to be under the first column of your table</param>
        /// <param name="tagNameThatTextExistsWithin">Inspect your table's cell to determine what type of element the text exists within. Then send the tag name to this parameter</param>
        /// <param name="FirstBtn">Enter "null" if your table does NOT contain Previous and Next button. If it does contain these buttons, then pass the First button element first, and then the Next button element. For example, pass "Bys.CBDLearnerPage.TableFirstBtn"</param>
        /// <param name="NextBtn">Enter "null" if your table does NOT contain Previous and Next button. If it does contain these buttons, then pass the First button element first, and then the Next button element. For example, pass "Bys.CBDLearnerPage.TableFirstBtn"</param>
        /// <returns></returns>
        public static bool Grid_ContainsRecord(IWebDriver browser, IWebElement tableElem, By tableElemBodyBy, string expectedText, string tagNameThatTextExistsWithin, By FirstBtn = null, By NextBtn = null)
        {
            browser.WaitForElement(tableElemBodyBy, TimeSpan.FromSeconds(180), ElementCriteria.HasText, ElementCriteria.IsEnabled, ElementCriteria.IsEnabled);

            // If the table does not contain first, next, previous and last buttons. Or if the table does contains them,
            // but there are not enough records to have multiple pages, then we only need to check one page of results
            if (FirstBtn == null || !browser.Exists(NextBtn, ElementCriteria.IsVisible))
            {
                if (Grid_CellTextFound(tableElem, tagNameThatTextExistsWithin, expectedText))
                {
                    return(true);
                }
                else
                {
                    return(false);
                }
            }

            // If the table has First, Previous, Next and Last buttons. And if those buttons are visible and enabled (The class attribute would equal "first cdisabled" if
            // it was disabled), then click the First button to go to the first listing of records
            if (browser.Exists(FirstBtn, ElementCriteria.IsVisible, ElementCriteria.AttributeValue("class", "first")))
            {
                browser.FindElement(FirstBtn).Click();
                Thread.Sleep(2000);      // TODO: Implement logic for dynamic wait instead of sleep
                                         // Check to see if the cell is found on the first page of results
                if (Grid_CellTextFound(tableElem, tagNameThatTextExistsWithin, expectedText))
                {
                    return(true);
                }
            }

            if (Grid_CellTextFound(tableElem, tagNameThatTextExistsWithin, expectedText))
            {
                return(true);
            }

            // If code reaches here, the cell text was not found yet, and so we should click the next button if there is one and
            // try to find the cell text on the next page, and continue until there are no pages left
            if (browser.Exists(NextBtn, ElementCriteria.IsVisible))
            {
                while (browser.Exists(NextBtn, ElementCriteria.AttributeValue("class", "next"))) // While the next button is not disabled
                {
                    browser.FindElement(NextBtn).Click();                                        // Click the next button
                    Thread.Sleep(2000);                                                          // TODO: Implement logic for dynamic wait instead of sleep

                    if (Grid_CellTextFound(tableElem, tagNameThatTextExistsWithin, expectedText))
                    {
                        return(true);
                    }
                }
            }

            return(false);
        }
예제 #2
0
 /// <summary>
 /// If you add an activity which gives you credits, this method can be called to wait for a user-specified label on your application
 /// to get updated with those credits after that activity was added. Once an activity is submitted, a record gets put into a windows service
 /// queue, and then waits for that service to push the activity through, because of this, we need to wait in our code. Note that there
 /// is not database flag to check instead of just randomly refreshing every couple of seconds. Right now, we will refresh every 4 seconds,
 /// 30 times. If your application ever takes longer than that, then increase the For loop below
 /// </summary>
 /// <param name="Page">The page to refresh</param>
 /// <param name="creditLabelBy">the label which stores the amount of credits that you are waiting to be refreshed</param>
 /// <param name="amountOfCredits">The amount of credits that will show when the windows service is complete</param>
 public static void WaitForCreditsToBeApplied(Page Page, By creditLabelBy, string amountOfCredits)
 {
     for (int i = 1; i < 400; i++)
     {
         Thread.Sleep(3000);
         Page.RefreshPage(true);
         try
         {
             Page.WaitForElement(creditLabelBy, TimeSpan.FromMilliseconds(0100), ElementCriteria.AttributeValue("innerText", amountOfCredits));
             break;
         }
         catch
         {
             continue;
         }
     }
     // Adding one more refresh just in case. I noticed that even when we wait for 1 label to get these credits, other labels may
     // still not be updated. So I am adding 1 more refresh maybe because the other labels need it. Monitor going forward
     Page.RefreshPage(true);
 }
 /// <summary>
 /// If you add an activity which gives you credits, this method can be called to wait for a user-specified label on your application
 /// to get updated with those credits after that activity was added. Once an activity is submitted, a record gets put into a windows service
 /// queue, and then waits for that service to push the activity through, because of this, we need to wait in our code. Note that there
 /// is not database flag to check instead of just randomly refreshing every couple of seconds. Right now, we will refresh every 4 seconds,
 /// 30 times. If your application ever takes longer than that, then increase the For loop below
 /// </summary>
 /// <param name="Page">The page to refresh</param>
 /// <param name="creditLabelBy">the label which stores the amount of credits that you are waiting to be refreshed</param>
 /// <param name="amountOfCredits">The amount of credits that will show when the windows service is complete</param>
 public static void WaitForCreditsToBeApplied(Page Page, By creditLabelBy, string amountOfCredits)
 {
     for (int i = 1; i < 400; i++)
     {
         Thread.Sleep(3000);
         Page.RefreshPage(true);
         try
         {
             Page.WaitForElement(creditLabelBy, TimeSpan.FromMilliseconds(0100), ElementCriteria.AttributeValue("innerText", amountOfCredits));
             break;
         }
         catch
         {
             continue;
         }
     }
 }