ARaja avatar image
ARaja Suspended asked ericnute edited

Can iTest read a text file?

I have a text file that I would like to read in iTest. This file contains a list of telnet commands. For example, 


show version



show clock

show ip traffic

show snmp



How can I read this file and parse the output as a list of commands that I can use in a telnet session?

10 |950

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

AdeelM avatar image
AdeelM answered AdeelM posted

Hello ARaja,


iTest has a step called ReadFile. To create a ReadFile step, insert a new step in your test case and change the action to "ReadFile". In the description field you can now provide the path of your file. See the screenshot below.


When iTest reads this file, its contents will be displayed as step response.


Message Edited by AdeelM on 09-02-2008 10:39 PM

readfile.JPG (48.3 KiB)
10 |950

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

ARaja avatar image ARaja commented ·

Thank you for your reply. This is useful.


How can I parse out each command and send it to my telnet session?

0 Likes 0 ·
AdeelM avatar image AdeelM ARaja commented ·



You will need to do two things:


1. You will develop an analysis rule for the ReadFile step. This will be a regular expression that extracts each line from the response (see screenshot for regex). The regex match will be stored in a variable, in the screenshot this variable is called 'commands'. The same regex will have multiple matches in the response. iTest will store all matches as a list. When the analysis rule completes, the variable 'commands' contains {"show version" "ena" "password" ... }


2. You will need a foreach loop that iterates through the 'commands' list. The syntax for foreach is "single_command $commands" where each time through the loop a single item from the 'commands' list is stored in the loop variable 'single_command'. The 'single_command' variable is then used to send the command to the telnet session. See screenshot, step 5.1.


0 Likes 0 ·
readfile2.JPG (77.1 KiB)
davefarley avatar image
davefarley answered davefarley posted



Is it possible to extend this to work for a scenario I would like to test below:


I have two text files, one with a list of commands:


interface loopback 0

ip address <ip_address>

no shut


And one with a list of variables:




Am I able to read the first file and substitute <ip_address> with the global variable I have previously read from the second file? The idea is that we would like to produce a range of config files for different router types, but a single parameter file containing all our variables that are applicable to all routers.

10 |950

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

RoryL avatar image RoryL commented ·

An alternative approach could be to use parameter files to support these variable substitution requirements. A parameter file is able to include other parameter files. So you could create a separate top level parameter file for each router config, and include a common parameter file which contains all of your common variables.


Then for the parameter 'ip_address', the command line would be changed to replace <ip_address> with [param ip_address].

0 Likes 0 ·
ramarb avatar image ramarb RoryL commented ·

To manipulate the files as you required is attached here. I have used 'regsub' to modify the file. It's quite self explanatory, if you need any clarification on this, please let me know.

However, I bank on parameter file usage for this case as specified by RoryL.

0 Likes 0 · (1.5 KiB)
davefarley avatar image davefarley ramarb commented ·

Thank you RoryL and ramarb for your speedy responses. I think parameter files could be the way forward, but I am not having much luck getting it to work. How can I get the first parameter file to reference the second?


i.e. First parameter file:


line1 = interface loopback 0

line2 = ip address [SUT_IP_ADDRESS]

line3 = no shut


Second parameter file:






enter each command in turn from first parameter file, but where a [xxx] is found, substitute value from second parameter file


I can get the procedure to enter each line in turn, but it is not substituting the [SUT_IP_ADDRESS] from the second parameter file.

0 Likes 0 ·
RoryL avatar image RoryL davefarley commented ·

Hi Dave,


To specify an included parameter file (a .ffpt document) from another parameter file you will need to open the top level parameter file with the ParameterFile editor (for example double click on an existing parameter file in iTest explorer view or create a new parameter file from the menu with File/New/ParameterFile), and select the Include tab. Then click on add and browse to the parameter file that you want to include.


However parameter values are just plain text so you can't reference nested parameter values using:

value1 = my [param value2]


To clarify my previous suggestion - you can read a text file with your list of commands (as you suggested) and these commands can support run time parameter substitution by using the syntax [param param_name]. When you run the test case within iTest you can then specify a top level global parameter file (using the context menu in iTest explorer), or if you run the test case from itestcli then use the -p <paramFile> argument. After you have done this then you should be able to run the same test case with different device parameters by changing the top level (global) parameter file.


You only need to add an include parameter file to the top level parameter file if you want to group your parameters into specific and common parameters.


Alternatively, if changing the top level (global) parameter file for different devices is not convenient then, you could create a separate top level test case for each device target. Each top level test case can use its own test case parameters to specify a device address and can call a common test case (using a single exec step to "run" the test case or "call" another test case procedure) to execute your test.



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.