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
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?
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.
[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."
);
}
}
@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
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?
Correct, the right method is GetExctractedValue().
@Ryan, please let us know if you need further assistance.
Regards,
Boyan Boev
Telerik by Progress