question

itest-user avatar image
itest-user asked itest-user posted

Analysis Rule

I am a new itest user. Could some one please let me know how I can do the following in itest

I have a show command output, which could return Router , Switch, port#.  I want to pass the test case if either one of them is present. Is there any way I can OR the output or should I create multiple analysis rules.

Thanks

iTest
10 |950

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

itest-user avatar image
itest-user answered itest-user posted

Thanks for the replies!Here is a more detailed description of the problem

the command "show ip ....." would give the output as

Vlan    ports
----    -----
   1    Gi1/0/11(dynamic),Routerport
   2    fa0/6(dynamic), Routerport ,Switchport
   3    Routerport
   5    Routerport

Suppose I want to pass the test case if the vlan have atleast one port(fa0/6) in it or a Routerport or a switch port . I am not sure how to set the analysis rule for this.should I parse the output in a different variable and OR it? Any other  way.

1 comment
10 |950

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

itest-user avatar image itest-user commented ·

Hi Paul,

Thanks. I sent my question before I saw your file. This is what I have been looking for.

0 Likes 0 ·
KumarS avatar image
KumarS answered KumarS posted

iTest analysis rules can assert on any expression. So if your data is stored in a variable called "foo", you can use any expression like:

 

$foo == "Router" || $foo == "Switch" || $foo == "port#"

 

as your assertion and appropriate create actions for "when true" and "when false" sections of the analysis rule.

1 comment
10 |950

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

PaulD avatar image PaulD commented ·

I'm not sure whether you mean that these words might appear anywhere in the response, and if any of them appear, you want to pass the test?

 

If this is the case, then you might consider adding a rule that uses a regex to look for any of these. 

 

So add an analysis rule using a "contains" extractor.  In its properties (at the bottom of the editor), you should change the match type to "regular expression".  The regular expression to use is:

 

(Router|Switch|port#)

 

(This looks for a match against any of three different values anywhere in the response.) 

 

The "contains" extractor will return "1" if it finds a match and "0" otherwise.  So you want your assertion to be $value == 1.  Then you can fill in the actions you want for "when true" and "when false".

 

You can do most of this through the Analysis Rule Wizard if you want -- however the wizard won't allow you to set the match type to "regular expression", so you'd have to do that part in the properties of the extractor after the wizard ends.

 

I'm attaching a simple test case that shows how this works.

0 Likes 0 ·

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.