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

Verify if a numeric value exists in a text block

2 Answers 186 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Hussam
Top achievements
Rank 1
Hussam asked on 02 Dec 2016, 09:09 AM

Hi,

 

When recording a test, i highlight Element, and i want to verify if there is any numbers in the text block. How can i do this? I only found, i can look for the exact number.

 

 

Thanks

2 Answers, 1 is accepted

Sort by
0
Aaron
Top achievements
Rank 1
answered on 02 Dec 2016, 04:02 PM

You would more than likely have to use an extract step on the element, and then use a coded step with C#/VB to be able to check if it is a valid number. Something *similar* to below should work, you'd definitely need to change parts of it to meet your requirements.

And this will ONLY check if the "value" in that textblock is a number. This implementation WILL NOT pass if this field contains any letters or anything like that. (i.e. it'll only pass if the textblock contains a value like "0.0" or "0" or "1.354232" or "23435").

 

[CodedStep(@"Check if textblock element contains a number.")]

void CheckNumber()

{

    string value = GetExtractedValue("NameOfExtractedVariable");
    double garbage = 0.0;
    bool isNumber = false;

 

    isNumber = Double.TryParse(value, out garbage);

 

    Assert.IsTrue(isNumber, "The textblock element does not contain a number.");

}

0
Elena
Telerik team
answered on 06 Dec 2016, 04:16 PM
Hi Hussam,

Please let me know if the suggested solution works for you as well. 

@Aaron: Great thanks for your cooperation! I really appreciate it! 

Regards,
Elena Tsvetkova
Telerik by Progress
 
The New Release of Telerik Test Studio Is Here! Download, install,
and send us your feedback!
Tags
General Discussions
Asked by
Hussam
Top achievements
Rank 1
Answers by
Aaron
Top achievements
Rank 1
Elena
Telerik team
Share this question
or