Message count test and verification

11 posts, 0 answers
  1. Ryan
    Ryan avatar
    11 posts
    Member since:
    Sep 2014

    Posted 28 Sep Link to this post

    I have the need to test an inbox message count and verify that when a message is read, the count is reduced by 1.  I am at a loss for how to accomplish this.  We use a class within a span to define the message count integer.  We are displaying it like "Inbox (10)" and after opening and reading an item, i want to verify that the count has been reduced by 1.

    Here is the span in use where the number in the ( ) is the message count.

    <span class="unreadNum ng-binding">(12)</span>

  2. Aaron
    Aaron avatar
    31 posts
    Member since:
    May 2016

    Posted 30 Sep in reply to Ryan Link to this post

    Not sure how interested you are in a coded solution, but before reading a message you could use an extract and store the value in a variable, and do the same thing after you read a message.

    For each of the extracts, parse through it and store just the number inside a variable. After that you could use a simple if statement to compare the two numbers and make sure one is less than the other?
  3. Ryan
    Ryan avatar
    11 posts
    Member since:
    Sep 2014

    Posted 30 Sep in reply to Aaron Link to this post

    I'd be curious to try this out.  Not sure where to begin.
  4. Aaron
    Aaron avatar
    31 posts
    Member since:
    May 2016

    Posted 30 Sep in reply to Ryan Link to this post

    http://pastebin.com/bQhEwKJH

    I can't guaruntee that the coded solution I just linked to would actually work, as I don't have any data or anything to test it against on my machine. However, the idea would be, create an "Extract" step on the element containing "(42)" or however many unread messages you have, proceed by opening your message to read it and change the number, and the perform an "Extract" step on the element that should now contain "(41)". After both extracts have been completed, you would use a "Coded" step using either the code I linked to, or some similar variation of it to do the same thing. I tried commenting what it was doing in code, however I'm not sure the extent of your programming knowledge. 

    Your project would have to be using C# for the code I just linked, however it could easily be converted to Visual Basic (VB) if that's what your project was using.

  5. Ryan
    Ryan avatar
    11 posts
    Member since:
    Sep 2014

    Posted 03 Oct in reply to Aaron Link to this post

    I cannot access that site on my work network.  Can you copy and paste in to here?
  6. Aaron
    Aaron avatar
    31 posts
    Member since:
    May 2016

    Posted 03 Oct in reply to Ryan Link to this post

    [CodedStep(@"Check if number of unread mail decreased by 1.")]
    void CodedStep_CheckForUnreadMailDecrease()
    {
        // These two variables will hold the values from the Extract steps. Replace the names between the ""
        //  with the actual names you entered into the Extract steps.
        string firstNumber = GetExtractedVariable("UnreadCountBefore").ToString();
        string secondNumber = GetExtractedVariable("UnreadCountAfter").ToString();
         
        // Creating the variables that will hold the numbers between the ().     
        int unreadCountBefore = 0;
        int unreadCountAfter = 0;
         
        // Attempt to convert the characters between () to integer variables.
        bool firstConvert = Int32.TryParse(firstNumber.Split('(', ')')[1], out unreadCountBefore);
        bool secondConvert = Int32.TryParse(secondNumber.Split('(', ')')[1], out unreadCountAfter);
                 
        // This will fail your test if the first convert failed.
        if (!firstConvert)
        {
            Assert.IsTrue(false, "The first extracted variable did not contain an integer between paranthesis.");
        }
        // This will fail your test if the second convert failed.
        else if (!secondConvert)
        {
            Assert.IsTrue(false, "The second extracted variable did not contain an integer between paranthesis.");
        }
        // This will fail your test if the "unreadCountBefore" integer is NOT 1 number greater than
        //  "unreadCountAfter".
        else if (!unreadCountBefore.Equals(unreadCountAfter + 1))
        {
            Assert.IsTrue(false, "The number of unread messages did not decrease after opening a message.");
        }
    }
  7. Boyan Boev
    Admin
    Boyan Boev avatar
    1045 posts

    Posted 03 Oct Link to this post

    Hi,

    @Aaron, thank you for sharing your knowledge with the community.

    @Ryan, what Aaron said is very useful information. You can create an extraction step against that span. The extraction variable will contain the number of the unread messages. Please note that the find logic of the element should not use the number since it constantly changes. 

    After that read the message and create another extraction of the same element. Then you can compare the extractions in a coded step. Here is how to get an extracted variable in code.

    Let me know if that helps.

    Regards,
    Boyan Boev
    Telerik by Progress
     
    The New Release of Telerik Test Studio Is Here! Download, install,
    and send us your feedback!
  8. Ryan
    Ryan avatar
    11 posts
    Member since:
    Sep 2014

    Posted 03 Oct in reply to Aaron Link to this post

    Aaron, this is awesome.  Going to give it a try now.  Thanks for your help.
  9. Ryan
    Ryan avatar
    11 posts
    Member since:
    Sep 2014

    Posted 03 Oct Link to this post

    I'm getting an error when trying to run this.

     

    c:\Program Files (x86)\Telerik\Test Studio\Bin\Test Studio Projects\TestProject1\WebTest.tstest.cs(53,26) : error CS0103: The name 'GetExtractedVariable' does not exist in the current context

    c:\Program Files (x86)\Telerik\Test Studio\Bin\Test Studio Projects\TestProject1\WebTest.tstest.cs(54,27) : error CS0103: The name 'GetExtractedVariable' does not exist in the current context

    Build Failed

     

    Any thoughts?

  10. Aaron
    Aaron avatar
    31 posts
    Member since:
    May 2016

    Posted 03 Oct in reply to Ryan Link to this post

    Yep. That's my fault. It looks like it should actually be "GetExtractedValue()" not "GetExtractedVariable()". Just change the "Variable" to "Value" and it should build.
  11. Boyan Boev
    Admin
    Boyan Boev avatar
    1045 posts

    Posted 05 Oct Link to this post

    Hi,

    Correct, the right method is GetExctractedValue().

    @Ryan, please let us know if you need further assistance.

    Regards,
    Boyan Boev
    Telerik by Progress
     
    The New Release of Telerik Test Studio Is Here! Download, install,
    and send us your feedback!
Back to Top