Friday, January 25, 2013

File Content Checkpoint - Regular Expressions / Parameters


File Content Checkpoint - Regular Expressions / Parameters

This is another post related to File Content Checkpoints (you can read the first one here). In this post we will look into regular expressions and test parameters or data tables while working with very simple examples of File Content Checkpoints.

First lets create File Content Checkpoint and use DataTable parameters in it.

We have two files Source and file_to_check.



Open a new test.

1. In the Data Table, in Global sheet, double click on column A, change its name to Var and add following values in the cells.



2. When you are in Action tab, go to Design (Menu)-> Checkpoint -> File Content Checkpoint. Source File for Checkpoint dialog opens.
3. Select file - 'Source' and click open.
4. File Content Checkpoint Properties dialog opens.



5. Click on line 2 and Click on Add Parameter to Line button [<p>].
6. Value Configuration Options dialog opens.
7. Click Parameter radio button, let DataTable be the default option. From Name choose Var and click OK.
8. Data Table parameter is added to second line.



9. Select file - 'file_to_check' in Comparison file path and click OK.
10. Run the test.

It will pass as you can see the below results:



Now lets change the first value in DataTable from '2012' to some gibrish value say 'AAAA'.
Delete below line from Action tab in the test:

FileContent("Source.txt").Check CheckPoint("Source.txt")

Run steps from 2 to 10 above, again.

It will fail the test and also show you under Captured Data that why it failed, as you can see the results below :



This time we will use regular expressions and create File Content Checkpoint.

Create two files as shown:



1. Open a new test.
2. Go to Action tab.
3. Go to Design (menu)-> Checkpoint -> File content checkpoint.
4. Select 'Source' file in Source File for Checkpoint dialog.
5. File Content Checkpoint Properties dialog opens.
6. Check the checkbox which is to the left of line 3 and also click on toggle button "Treat Line as Regular Expression / Plain text" and enter the regular expression (Match Any Email Address from a Specific Domain) as shown

(\W|^)[\w.+\-]{0,25}@(yahoo|hotmail|gmail)\.com(\W|$)



7. From the Comparison file path you can select 'File_to_check'.
8. Click OK to close the File Content Checkpoint Properties dialog.
9. Run the test. The test will pass as shown below:



In step 6 above, we clicked on toggle button "Treat Line as Regular Expression / Plain text" and ran the test. Now lets only check the checkbox and do not click the toggle button ("Treat Line as Regular Expression / Plain text"), so now it looks like :



Run the test. The test will fail, because this time it is not treating that line 3 as a Regular Expression. So do not forget to check that toggle button "Treat Line as Regular Expression / Plain text" if you are working with Regular Expressions..