Method to test a successfully condition

3 posts, 1 answers
  1. Alex
    Alex avatar
    24 posts
    Member since:
    Aug 2010

    Posted 09 Dec 2010 Link to this post

    I'm having trouble figuring out a way to test if a successful message was received from my code. I know the code below is incorrect, I just can't seem to figure out a way to make it work.

    What I would like it to do is to wait 10 sec for the text 'Successful' to display and when it doesn't refresh the search and check again, repeat as necessary. I'm having trouble determining a way to test the successful condition.

    [CodedStep(@"Wait for Successful completion of processing")]
            public void CO_CBCOMP_AU_SA_EN_VerifyFunctionalityBlowup_CodedStep4()
            {
      
                HtmlSpan UserControl9921DBIREVIEWCOMPOSITEQUEUEReviewCompositeQueueListJobStatusSpan = Pages.UMDealerBusiness7.UserControl9921DBIREVIEWCOMPOSITEQUEUEReviewCompositeQueueListJobStatusSpan;
      
                int n = 0;
                while ( n < 1)
                {            
                UserControl9921DBIREVIEWCOMPOSITEQUEUEReviewCompositeQueueListJobStatusSpan.Wait.ForExists(10000);
                Wait.For<HtmlSpan>(c => c.AssertContent().TextContent(ArtOfTest.Common.StringCompareType.Contains, "Successful"), UserControl9921DBIREVIEWCOMPOSITEQUEUEReviewCompositeQueueListJobStatusSpan, 10000);
      
                if (UserControl9921DBIREVIEWCOMPOSITEQUEUEReviewCompositeQueueListJobStatusSpan = "Successful")
                {
                    n++;
                }
                else
                Actions.InvokeScript("javascript:__doPostBack('UserControl9921DBIREVIEWCOMPOSITEQUEUE$searchLinkButton','')");
                }
            }

  2. Answer
    Cody
    Admin
    Cody avatar
    3360 posts

    Posted 10 Dec 2010 Link to this post

    Hello Alex,

    Try this code instead:

    [CodedStep(@"Wait for Successful completion of processing")]
    public void CO_CBCOMP_AU_SA_EN_VerifyFunctionalityBlowup_CodedStep4()
    {
        int numTries = 10;
        HtmlSpan UserControl9921DBIREVIEWCOMPOSITEQUEUEReviewCompositeQueueListJobStatusSpan = Pages.UMDealerBusiness7.UserControl9921DBIREVIEWCOMPOSITEQUEUEReviewCompositeQueueListJobStatusSpan;
        int n = 0;
        while (n++ < numTries)
        {
            UserControl9921DBIREVIEWCOMPOSITEQUEUEReviewCompositeQueueListJobStatusSpan.Wait.ForExists(10000);
            try
            {
                Wait.For<HtmlSpan>(c => c.TextContent.Contains("Successful"), UserControl9921DBIREVIEWCOMPOSITEQUEUEReviewCompositeQueueListJobStatusSpan, 10000);
            }
            catch (TimeoutException)
            {
                Assert.AreNotEqual(n, numTries);
                Actions.InvokeScript("javascript:__doPostBack('UserControl9921DBIREVIEWCOMPOSITEQUEUE$searchLinkButton','')");
            }
        }
    }

    If any part of the code is unclear to you don't hesitate to ask about it.

    Regards,
    Cody
    the Telerik team
    Interested in Agile Testing? Check out Telerik TV for a recording of Automated Testing in the Agile Environment
  3. Alex
    Alex avatar
    24 posts
    Member since:
    Aug 2010

    Posted 16 Dec 2010 Link to this post

    Hi Cody,

    It works perfectly, Thank you for the support!
Back to Top