Rational Functional Tester - How can I get scripts called from a parent script to use the parent's data pool?

北城余情 提交于 2019-12-04 15:54:27

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...

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());
        }
    }
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!