在RFT中添加文件检查点

来源:互联网 发布:数据库审计系统排名 编辑:程序博客网 时间:2024/05/02 20:52

不像Testcomplete,在QTP和RFT中都没有提供文件检查点,但是在RFT中可以利用VpUtil和VpManual来方便地创建一个文件检查点。例如下面代码所示:

 

 

    public void testMain(Object[] args)

    {

        vpManual("Test1", "The rain in GZ").performTest();

        vpManual("Test2", "The rain in GZ","The rain in SZ").performTest();

       

        fileContentsTest("Test3","D://1.txt","D://2.txt");

    }

 

    protected byte[] getRawFileContents(File file)

    {

        byte[] result = null;

        if ( file != null && file.exists() )

        {

            FileInputStream input = null;

            try

            {

                // Read in the specified file ...

                input = new FileInputStream(file);

                result =  new byte[(int)file.length()];

                int bytesRead = 0;

                int offset = 0;

                final int length = result.length;

                while ( bytesRead != -1 && offset < length )

                {

                    bytesRead = input.read(result, offset, length-offset);

                    if ( bytesRead >= 0 )

                        // bytesRead == -1 when end-of-file is reached

                        offset += bytesRead;

                }

                input.close();

            }

            catch ( IOException ioexc )

            {

                throw new FileSupportException(ioexc.getClass().getName()+": "+ioexc.getMessage());

            }

        }

        else

            throw new FileSupportException("Invalid file specification: "+file);

        return result;

    }

   

    protected String getFileContents(File file)

    {

        byte[] result = getRawFileContents(file);

        return ( result != null ? new String(result) : null );

    }

   

    private File getFile(String fileName)

    {

        File file = new File(fileName);

        if ( !file.exists() )

        {

            file = new File((String)getOption(IOptionName.DATASTORE), fileName);

            if ( !file.exists() )

                throw new FileSupportException("Invalid file name specified to fileContentsTest: "+fileName);

        }

        return file;

    }

   

    public boolean fileContentsTest(String vpName, String expected, String actual)

    {

        return fileContentsTest(vpName, getFile(expected), getFile(actual));

    }

   

    public boolean fileContentsTest(String vpName, File expected, File actual)

    {

        ITestData dataExp = VpUtil.getTestData(getFileContents(expected));

        ITestData dataAct = VpUtil.getTestData(getFileContents(actual));

        return vpManual(vpName, dataExp, dataAct).performTest();

    }

   

 

 

 

关于VpUtil的getTestData方法的使用和VpManual的使用在RFT的帮助文档中有描述:

 vpManual

使用vpManual可以在脚本中插入检查点。

 

Constructs a manual verification point object. Manual verification points require that the user supply any necessary data before performTest can be executed.

This verification point form has several unique characteristics:

·         This verification point must be inserted by a script developer. It is not a record-time capability. The data is managed directly by the script developer and is not extracted from a TestObject in the way that static or dynamic verification points can automatically create the data.

·         If a baseline version of the data does not already exist from a previous playback, the actual data is used to create a baseline for subsequent script executions. The performTest method logs an informational message only (not pass or fail) when constructing a baseline file.

·         As the baseline is not created until the first time the script is executed, if you are using ClearCase change management, you should run the script before checking it in. If you check the script in before running it, this verification point baseline will not be checked in.

·         If a baseline exists, the actual data is compared to the initial baseline of the data when the performTest method is executed.

·         performTest persists the supplied data regardless of the outcome of the test. Therefore, it must be an object based on the Value class that can be persisted and compared.

·         The script developer is responsible for supplying a script-relative unique name for any single instance of these verification points. Reusing a verification point name commonly causes false negative results to occur because the incorrect data is tested.

 

VpUtil

VpUtil对象中的getTestData方法用于为检查点获取所需的测试数据。

 

Provides a default set of utility methods that can be used to create interesting data objects. The primary usage for this class is in conjunction with vpManual verification points.

 

 

 

原创粉丝点击