Automation framework using datapools

    技术2022-05-20  39

     

    Introduction

    In the IBM® Rational® Functional Tester tool, a datapool is a collection of related data records, which supplies data values to the variables in a test script during playback. The datapool can be used in various ways in the framework to make your process more efficient; when strategically used, this capability can help reduce the code size, and assist in furthering effective automation efforts.

    The data in the datapools can be changed anytime, without any need to modify your framework, which helps make your framework flexible for changes.

    Creating a datapool

    To start creating a datapool, right-click on your functional test project and select Add Test Datapool.

    Figure 1. Creating a datapool

    Now give your datapool a name.

    Figure 2. Naming the datapool

    Add columns (Variables) to the datapool by right-clicking the datapool pane.

    Figure 3. Adding columns to the datapool

     

    Add a record by right-clicking and selecting Add Record.

    Figure 4. Adding records to your datapool

    Finally, you should have a datapool with a column (variable) and a record.

    Figure 5. Final datapool

     

    How to read the datapool

    Below is the code to read the datapool.

    Listing 1. Code to read the datapool

    /** * Function to read the Data Pool * @param DpName : Path/Name of the DataPool relative to the Project which is to be read * @param ColumnName : Name of the Column which is to be read from DpName * @return Arraylist that contains all the records in the supplied column */ public ArrayList ReadDP(String DpName, String ColumnName) { ArrayList DpContent = new ArrayList(); java.io.File dpFile = new java.io.File( (String) getOption(IOptionName.DATASTORE), DpName); IDatapool dp = (IDatapool) dpFactory().load(dpFile, true); //Use default iterator class IDatapoolIterator dpIter = dpFactory().open(dp, null); //Use default equivalence class dpIter.dpInitialize(dp); dpIter.dpReset(); while (!dpIter.dpDone()) { // Insert actions using dpIter based references to the datapool //Get the current datapool record dpIter.dpCurrent(); //Get the String value at column index 0 in current record String str = dpIter.dpString(ColumnName); DpContent.add(str); //Move the pointer to next record dpIter.dpNext(); } dpFactory().close(dpIter); return DpContent; }

    By way of example, for the datapool created above you would pass the name/path of the datapool TestDatapool and the column Variable1 .

    How to map the datapool path

    To start mapping to your datapool path, right-click on the datapool and select properties.

    Figure 6. Datapool path

     

    As shown in the case above, the path for the TestDatapool will be /Project1/TestDatapool.rftdp

     

    How to use the datapools in your framework

    You can dynamically create the test suites to add or remove any testcase.

     

    Creating TestSuites

    There are two ways to create your testsuites:

    Calling independent testscripts (where one script is for one testcase)Calling the functions

    Test suite creation by calling independent test scripts

    Create a datapool "TestSuite" with Variables "TestCase", "TestScript" and "Execute".

    Here the TestCase is the name of the testcase to be executed.

    The TestScript is the call script value of the testcase (the one you get on right-click on a script and selecting insert as call script.)

    Execute shows if the testcase is to be executed or not.

     

    Figure 7. Sample TestSuite

    Now using the function ReadDP(String DpName, String ColumnName)

    Get the values for all these 3 columns in arraylists.

    Listing 2. Using the datapool to create a testsuite

     

    ArrayList TestCase = ReadDP("/Project1/TestSuite.rftdp","TestCase"); ArrayList TestScript = ReadDP("Project1/TestSuite.rftdp",TestScript); ArrayList Execute = ReadDP("Project1/TestSuite.rftdp",Execute);

     

    Use these ArrayList using the below code:

    String testcase,testscript,execute; For(int i=0;i< TestCase.size();i++) { testcase= (String)TestCase.get(i); testscript =(String) TestScript.get(i); execute =(String) Execute.get(i); //if execute is true If(execute.contentequals("true") { Callscript(testscript); System.out.println("Executing testcase "+ testcase); } }

     

    Test suite creation by calling functions

    Similarly, you can use the datapools by adding one more column Function name. Instead of calling the script, you will call that specific function.

    To Supply the test data, you can use datapools to supply the testdata to perform regression testing.

     

    Datapools in action – an example

    To test the login functionality for different users, you could have a Test Datapool "Login" with columns "UserName" and "Password".

     

    Figure 8. Sample Testdata  

     

    Read the UserName and Password in 2 Arraylist by using the function

    Listing 3. Example

    ArrayList UserName = ReadDP("/Project1/Login.rftdp","UserName"); ArrayList Password = ReadDP("/Project1/Login.rftdp","Password");

    Now you can use these two ArrayLists to perform the login recursively for the given User Id's and Passwords.

    For(int i=0;i< UserName.size();i++) { String uname ,pswd; uname = (String) UserName.get(i); pswd = (String) Password.get(i); //Perform your login functionality. }

     

    Working with the sample files

    Download the DWReadDatapool.zip file, which is the sample Rational Functional Tester project. Extract the zipped file to DWReadDatapool folder. Launch Rational Functional Tester, select File > Connect to a Functional Test Project, browse to the DWReadDatapool folder, and click Finish. The functional test project will open in Rational Functional Tester.

    Summary

    Now that you are able to create datapools using your Rational Functional Tester tool, you can leverage the Functional Tester solution's capability to supply data values to the variables in a test script during playback. The datapools that you have configured can be used in various ways in the framework to make your process more efficient; when strategically used, this capability can help reduce the code size, and assist in furthering effective automation efforts. Your process is positioned for change, with a flexible process that can adapt to your organization's growing needs.

    Visit the Rational Functional Tester page to learn more about creating automation frameworks, using the downloadable zip file to help your organization create datapools.

     

    you can visit the original article from url: http://www.ibm.com/developerworks/rational/library/10/automationframeworkusingdatapools/index.html?ca=dat-

     

     


    最新回复(0)