本文介绍了Rational Functional Tester - 如何获取从父脚本调用的脚本以使用父数据池?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对 Rational Functional Tester (Java) 还很陌生,但我有一大块空白.我有一个处于敏捷开发环境中的应用程序,因此一些屏幕会随着新界面的上线而变化.

I'm fairly new to Rational Functional Tester (Java) but I have one large blank. I have an application that is in an agile development environment so some of the screens can flux as new interfaces are brought online.

出于这个原因,我正在尝试模块化我的测试脚本.例如:我想要一个登录脚本、一个搜索脚本和一个注销脚本.

For this reason I'm trying to modularize my test scripts. For example: I would like to have a login script, a search script, and a logout script.

然后我会将它们拼接在一起(伪代码)

I would then stitch these together (pseudo code)

Call Script components.security.Login;
Call Script components.search.Search;
//verification point
Call Script components.security.Logout;

通过将测试脚本分解成离散的块(功能单元),我相信我能够更好地适应变化.如果登录脚本发生更改,我会为应用程序中的每个脚本修复或重新录制一次.

By breaking the testing script into discrete chunks (functional units) I believe that I would be better able to adapt to change. If the login script changed, I would fix or re-record it once for every script in the application.

然后我将该脚本称为TestSituation_001".它需要引用几个不同的数据池.在这种情况下,一个用户数据池(而不是一个超级用户数据池)和一个 TestSituation_001 数据池,或者可能还有其他一些数据池.验证点将使用情境数据池进行检查.

Then I would call that script, say, "TestSituation_001". It would have need to refer to several different data pools. In this instance a User datapool (instead of a superUser datapool) and a TestSituation_001 datapool, or possibly some other datapools as well. The verfication point would use the situational datapool for its check.

现在,这就是我在理想世界中的做法.目前困扰我的是,我似乎需要做一些完全不同的事情才能让子脚本继承父母.

Now, this is how I would do it in an ideal world. What is bothering me at the moment is that it appears that I would need to do something entirely different in order to get the child scripts to inherit the parents.

所以我的问题是:

  1. 为什么子脚本不直接继承调用脚本的数据池?
  2. 我怎样才能让他们这样做?
  3. 我是否对它的工作方式做出了错误的假设?
  4. 如果#3 为真,那我该如何做得更好?

作为旁注,我不介意破解一些 Java 来使其工作.

As a side note, I don't mind hacking the heck out of some Java to make it work.

谢谢!

推荐答案

我解决了自己的问题.对于那些好奇的人,请查看:

I solved my own problem. For those of you who are curious, check this out:

public abstract class MyTestHelper extends RationalTestScript
{

    protected void useParentDataPool() {
        if(this.getScriptCaller() != null) {
            IDatapool dp = this.getScriptCaller().getDatapool();
            IDatapoolIterator iterator = DatapoolFactory.get().open(dp, "");
            if(dp != null && iterator != null) {
                //if the datapool is not null, substitute it for the current data pool
                this.dpInitialization(dp, iterator);
            }
        }
    }

}

这也将使用相同的迭代器.狩猎愉快...

This will use the same iterator too. Happy hunting...

实际上,经过一番思考,我制作了一个方法,可以让任何给定的脚本都使用 Root 调用脚本的 DataPool.再次,祝有需要的人狩猎愉快……

Actually, after some reflection, I made a method that would make any given script use the Root calling script's DataPool. Again, happy hunting to those who need it...

/*
 * preconditions:  there is a parent caller
 * postconditions: the current script is now using the same datapool / datapool iterator as the root script
 */
protected void useRootDataPool() {
    //if there is no parent, then this wouldn't work so return with no result;
    if(this.getScriptCaller() == null) return;

    //assume that we're at the root node to start
    RationalTestScript root = this;
    while(root.getScriptCaller() != null) {
        root = root.getScriptCaller();
    }

    //if this node is the root node, no need to continue.  the default attached datapool will suffice.
    if(this.equals(root)) return;

    //get the root's data pool (which would be the parent's parent and so on to the topmost)
    IDatapool dp = root.getDatapool();
    if(dp != null) {
        //check to make sure that we're not trying to re-initialize with the same datapool (by name)
        //if we are, then leave
        if(dp.getName().equals(this.getDatapool().getName())) return;

        //this basically says "give me the iterator already associated to this pool"
        IDatapoolIterator iterator = DatapoolFactory.get().open(dp, "");
        //if we have an iterator AND a data pool (from above), then we can initialize
        if(iterator != null) {
            //this method is never supposed to be run, but this works just fine.
            this.dpInitialization(dp, iterator);
            //log information
            logInfo("Using data pool from root script: " + root.getScriptName());
        }
    }
}

这篇关于Rational Functional Tester - 如何获取从父脚本调用的脚本以使用父数据池?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-31 12:40