Forum Discussion

DAustermeier's avatar
DAustermeier
Occasional Contributor
7 years ago
Solved

Use wildcards in If...Then statement

Hi there,

I want to do check if an object property is beginning with "0 MIL". If it does I'd like to do some operations and if it doesn't I'd like to do sth. else.


Therefore I tried to use a wildcard (*) in the If...Then statement. My Keyword test compares an object property as Value 1 (e.g. "0 MIL, 10 PCE") with a constant String as Value 2 (0 MIL*).

The expected result of my example would be that Testcomplete executes everything assingned to the If...Then statement, but the test never enters the If...Then part.

What am I doing wrong? or is there another way to handle this issue?

Regards,
David

  • What you could do in your keyword test is, before your If... then, do a "Call Object Method" on aqObject.  Select the method "CompareProperty" (https://support.smartbear.com/testcomplete/docs/reference/program-objects/aqobject/compareproperty.html).  In the first parameter, select Object property and pass in the property that you want to check.  In the second parameter, enter the integer 8 (for "cmpStartsWith").  Third parameter, set to your 0 MIL you're looking for.  Fourth parameter set to boolean "true" for case sentitivity.  Fifth parameter set to 0 so no message is posted to the log.

     

    Now, in your If... then, you use "Last Operation Result" for the first half of the if... then and use "true" for the second half.  The result of all this is that your keyword test will first run the method to see if your property string starts with the characters 0 MIL.  It will return either true or false.  If it returns true, your If... then logic will trigger the condition and execute your conditional block.

3 Replies

  • tristaanogre's avatar
    tristaanogre
    Esteemed Contributor

    What you could do in your keyword test is, before your If... then, do a "Call Object Method" on aqObject.  Select the method "CompareProperty" (https://support.smartbear.com/testcomplete/docs/reference/program-objects/aqobject/compareproperty.html).  In the first parameter, select Object property and pass in the property that you want to check.  In the second parameter, enter the integer 8 (for "cmpStartsWith").  Third parameter, set to your 0 MIL you're looking for.  Fourth parameter set to boolean "true" for case sentitivity.  Fifth parameter set to 0 so no message is posted to the log.

     

    Now, in your If... then, you use "Last Operation Result" for the first half of the if... then and use "true" for the second half.  The result of all this is that your keyword test will first run the method to see if your property string starts with the characters 0 MIL.  It will return either true or false.  If it returns true, your If... then logic will trigger the condition and execute your conditional block.

  • baxatob's avatar
    baxatob
    Community Hero

    No, you can't use a wildcard as a part of the constant value, because it will be recognized literally. 

     

    As a workaround you can map your element in the Name Mapping using a wildcard for dynamic property. 

    Then you can use the following model:

     

    IF NameMapping.yourElement.Exists
        THEN doSomething