This is a migrated thread and some comments may be shown as answers.

Message count test and verification

10 Answers 122 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Ryan
Top achievements
Rank 1
Ryan asked on 28 Sep 2016, 01:33 PM

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>

10 Answers, 1 is accepted

Sort by
0
Aaron
Top achievements
Rank 1
answered on 30 Sep 2016, 03:41 PM
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?
0
Ryan
Top achievements
Rank 1
answered on 30 Sep 2016, 05:07 PM
I'd be curious to try this out.  Not sure where to begin.
0
Aaron
Top achievements
Rank 1
answered on 30 Sep 2016, 07:22 PM

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.

0
Ryan
Top achievements
Rank 1
answered on 03 Oct 2016, 12:55 PM
I cannot access that site on my work network.  Can you copy and paste in to here?
0
Aaron
Top achievements
Rank 1
answered on 03 Oct 2016, 12:57 PM
[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.");
    }
}
0
Boyan Boev
Telerik team
answered on 03 Oct 2016, 12:59 PM
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!
0
Ryan
Top achievements
Rank 1
answered on 03 Oct 2016, 01:01 PM
Aaron, this is awesome.  Going to give it a try now.  Thanks for your help.
0
Ryan
Top achievements
Rank 1
answered on 03 Oct 2016, 02:00 PM

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?

0
Aaron
Top achievements
Rank 1
answered on 03 Oct 2016, 02:05 PM
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.
0
Boyan Boev
Telerik team
answered on 05 Oct 2016, 08:15 AM
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!
Tags
General Discussions
Asked by
Ryan
Top achievements
Rank 1
Answers by
Aaron
Top achievements
Rank 1
Ryan
Top achievements
Rank 1
Boyan Boev
Telerik team
Share this question
or