question

vani avatar image
vani asked ericnute edited

How to prepare Custom XPath query for the given scenario

Hi, I am new to iTest as well as XPath. I have a response map for the command ls -lrt | tail -20 with a sample as follows:

 

-rw-rw-rw-   1 xyz   wis        13151 Nov  9 04:30 abc.gen
-rw-rw-rw-   1 xyz  wis         4521 Nov  9 04:45 abc.gen
-rw-rw-rw-   1 xyz   wis           31 Nov  9 05:00 abc.gen
-rw-rw-rw-   1 xyz   wis           31 Nov  9 05:15 abc.gen
-rw-rw-rw-   1 xyz   wis           31 Nov  9 05:30 abc.gen
-rw-rw-rw-   1 xyz   wis           31 Nov  9 05:45 abc.gen
-rw-rw-rw-   1 xyz   wis           31 Nov  9 06:00 abc.gen
-rw-rw-rw-   1 xyz   wis           31 Nov  9 06:15 abc.gen
-rw-rw-rw-   1 xyz   wis           31 Nov  9 06:30 abc.gen
-rw-rw-rw-   1 xyz   wis           31 Nov  9 06:45 abc.gen
-rw-rw-rw-   1 xyz   wis           31 Nov  9 07:00 abc.gen
-rw-rw-rw-   1 xyz   wis           31 Nov  9 07:15 abc.gen
-rw-rw-rw-   1 xyz   wis           31 Nov  9 07:30 abc.gen
-rw-rw-rw-   1 xyz   wis           31 Nov  9 07:45 abc.gen
-rw-rw-rw-   1 xyz   wis           31 Nov  9 08:00 abc.gen
-rw-rw-rw-   1 xyz   wis           31 Nov  9 08:15 abc.gen
-rw-rw-rw-   1 xyz   wis           31 Nov  9 08:30 abc.gen
-rw-rw-rw-   1 xyz   wis           31 Nov  9 08:45 abc.gen
-rw-rw-rw-   1 xyz   wis           31 Nov  9 09:00 abc.gen
-rw-rw-rw-   1 xyz   wis           31 Nov  9 09:15 abc.gen

 

Here the column with '31' values is the file size. I want to create an Analysis rule for this step such that even if one of the values in the size colum is greater than 31, then the test should pass. If all are equal to 31 then the test should fail.

 

Note: They would never be lower than 31 as it is the default size of this file and some of them can be of 31 size.

 

Please advice.

iTestresponse mapxpath
10 |950

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

ramarb avatar image
ramarb answered ramarb posted

Earlier, I thought of using xpathEval straight. But, auto-response does not give me the list of files' size. It may be due to the complexity of response.

2 comments
10 |950

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

vani avatar image vani commented ·

Hi, I am not sure if I am running your test case the right way, but it gives me the error " Pattern pattern1 did not match response." And the Error Log shows an "Unhandled Event Loop Exception"

0 Likes 0 ·
ramarb avatar image ramarb vani commented ·

The error shows as response you get from machine is different from the response map file. Can you confirm this?

 

By the way, make sure you did the below things:

 

Go to Step Properties of your step "ls -lrt | tail -20 "

 - Provide 'Expected Response' as response map file.

 - Store Response value as 'data'

My test case runs correctly without any errors. You can go through it once.

If you still could not nail this, do attach your test case here.

0 Likes 0 ·
ramarb avatar image
ramarb answered ramarb posted

I have used pattern response map in this case.

Find attached test case and response map. Keep the test case in your project and provide correct response map path in the test case.

 

Quickly to summarize,

 

1. Created a pattern response to get list of all files' size.

2. Passing the file size in a loop to compare them.

3. If any pass/fail criteria hits, the test goes to be break (just introduced 'break')

4. When all files are of same size, you will get a note.

 

Please let me know If you need more details.


fileCompare.zip (2.5 KiB)
5 comments
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 ·

Note that you shouldn't even need to do the looping, as iTest's analysis engine will do that for you automatically if the analysis extracts multiple values.  You'll see in the properties of the analysis rule that you can control what should happen when multiple values are extracted.

 

In this case, you would need to modify the analysis rule with a query that will extract all of the values in that column at once.

0 Likes 0 ·
KumarS avatar image KumarS PaulD commented ·

I did this using a block map and a simple analysis rule. Have a look. Look at the properties of "assert" step. I changed the default in the combo "When multiple matches" to "True if all true".

 

Save both files in the same directory of a project and then run "ls.fftc".

 

 

0 Likes 0 ·
ls.ffrm (191.7 KiB)
ls.fftc (4.6 KiB)
vani avatar image vani KumarS commented ·

Thanks KumarS! The block mapping scenario worked for me perfectly. I was also able to apply other analysis rules for data and month checking in the same way. Thanks a lot !

 

PaulD, thanks for replying. Are you reffering to the Processor Properties (- "When multiple matches:") for assert statement which KumarS had mentioned?

 

ramarb, I tried to incorporate your solution as well but couldn't get it to work. Maybe as I am not too good at debugging iTest as of now :-) , but thanks to you too for providing a solution.

0 Likes 0 ·
PaulD avatar image PaulD vani commented ·

Yes.  I was referring to "when multiple matches..."

0 Likes 0 ·
vani avatar image vani PaulD commented ·

Thanks!

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.