- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic to the Top
- Bookmark
- Subscribe
- Printer Friendly Page
Can iTest read a text file?
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
09-02-2008 09:03 PM
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
en
password
show clock
show ip traffic
show snmpexit
How can I read this file and parse the output as a list of commands that I can use in a telnet session?
Solved! Go to Solution.
Re: Can iTest read a text file?
[ Edited ]- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
09-02-2008 10:22 PM - last edited on 09-02-2008 10:39 PM
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.
Re: Can iTest read a text file?
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
09-02-2008 10:41 PM
Thank you for your reply. This is useful.
How can I parse out each command and send it to my telnet session?
Re: Can iTest read a text file?
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
09-02-2008 11:09 PM
ARaja,
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.
Re: Can iTest read a text file?
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
01-20-2009 09:37 AM
Hi,
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> 255.255.255.255
no shut
And one with a list of variables:
ip_address 10.10.10.1
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.
Re: Can iTest read a text file?
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
01-20-2009 02:30 PM
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].
Re: Can iTest read a text file?
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
01-20-2009 09:10 PM
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.
Re: Can iTest read a text file?
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
01-21-2009 06:00 AM
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] 255.255.255.255
line3 = no shut
Second parameter file:
SUT_IP_ADDRESS = 10.10.10.1
Procedure:
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.
Re: Can iTest read a text file?
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
01-21-2009 01:46 PM
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.
Rory
