question

ziqxu avatar image
ziqxu asked ziqxu posted

multiple match like '||' function in response

hi, I encounter a problem when I'm using itest,

 

after I execute a command in my Serial session, and there's an output, definitely,

 

then I'll check if the expected string is displayed in this output, but I want to verify string1, string2, and string3,

 

if any of them show in the serial command output, I'll pass this case.

 

So what I do was to add three analysis rule to this command to check the output in the sequence of string1check,string2check and string3check, and set the Assert Property of each Analysis Rule to be: True if any True.

 

But it seems, when, e.g. string2 didnot come out in this command output, it still fail the test.

 

I'm wondering how to do something like '||' in itest?

iTestresponse map
10 |950

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

mallikarjunarao avatar image
mallikarjunarao answered mallikarjunarao posted

Hi,

 

try use list to solve your problem

 

% set stringsResults [list "DTE" "Controllers" "S0/0"]
DTE Controllers S0/0
% set value "Controllers"
Controllers
% lsearch $stringResults $value
1

 

now you can use if condition

 

if [lsearch $stringResults $value] {
    puts "PASS: Expected: $value, Actual: $stringResults
else
   puts "FAIL: Expected: $value, Actual: $stringResults
}

 

 There many other options available for lsearch http://wiki.tcl.tk/1486

 

Thanks

Malli

10 |950

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

msandeep avatar image
msandeep answered msandeep posted

Hey,

 

Sorry the question is quite confusing for me..

 

If you wnat something like below:

 

"From one response you need to verify three string i.e. string1, string2 and string3. you want to pass the test case if any one of them matched."

 

Please correct me if I missed some thing...

 

So, to achieve the above add three analysis rule to the command in the following fashion:

 

analyze

   query query1()

      assert $value eq $string1

         if True

             PASS

            Skip_remaining_rules

 

analyze

   query query2()

      assert $value eq $string2

         if True

            PASS

            Skip_remaining_rules

 

analyze

   query query3()

      assert $value eq $string3

         if True

            PASS

        If Fail

             FAIL

 


NOTE: The query1() or query2() or query3() can be same or different as per your requirement. And for assert steps please ensure filed replacement is enabled if you want to substitute a variable in that point.

 

Please be posted how it goes. Also, if you still see some issue please share the test case and test report, we will try to make it out.

 

Thank You!

10 |950

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

rpenta avatar image
rpenta answered rpenta posted

Store the response of the each analysis rule in a seperate variable and then have a if  then else statments to either pass or fail the test case. 

 

example :

In analysis rule 

contains        valid

store              var1

 

similarly for other cases

 

if     $var1 == 1  || $var == 2 

      then

        analyze assert true

      else

        analyze assert false

 

Thanks

-Ravi

10 |950

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.