pabot ::是否可以在并行pabot过程中使用相同的值集?

时间:2016-06-28 16:31:55

标签: python-2.7 robotframework

我有一些机器人框架测试,我正在尝试使用pabot(pabot.pabotlib)并行化这些测试。因为pabot需要valuesset.dat并且我只有1个值集(凭证),我想在多个进程中同时使用它,是否可以在多个过程中使用相同的值集。

实施例。 ;可以这样做吗?

test.robot

pabot --pabotlib --resourcefile valueset.dat test.robot

valueset.dat

public class ScopeContext<TArg,TRet>{

    public dynamic Scope {get;set;}

    public Func<TArg,TRet> Expression;

    public ScopeContext(string exp){
        TypeRegistry tr = new TypeRegistry();
        tr.RegisterSymbole("scope",Scope);

        Expression = (new CompiledExpression<TRet>(exp)
        {
            TypeRegistry = tr
        }).ScopeCompile<TArg>();
    }

}

// usage

ScopeContext<object,object> f = 
     new ScopeContext<object,object>("scope.Count");


// you can now change scope dynamically...
f.Scope = new List<int>();

var result = f.Expression(null);

pabot call

{{1}}

1 个答案:

答案 0 :(得分:0)

假设您必须进行1次登录并使用该数据与Pabot进行多次测试。

  1. 使用Python文件将Pabot作为子进程启动(例如,run_my_tests.py)

  2. 在该文件中,创建一个执行设置的功能。可以像你希望的那样精心制作。确保它创建所有必要的数据。该数据可以放入字典或列表中。

  3. 腌制数据。这会将对象保留在文件中。

  4. 在run_my_tests.py中,将pabot参数设置为包含pabot本身的列表。例如:

    pabot_command = ['pabot',' - processes','10',' - variable','TEST_ENV:dev']

  5. 确保pabot_command包含'--variablefile',后跟'variables.py'。这是每个Robot线程将调用的文件。
  6. 在run_my_tests.py所在的目录中创建variables.py文件。
  7. 在variables.py文件中,放置与此类似的代码:

    import pickle
    
    def get_variables(): 
    with open("auth_data.pkl", 'rb') as auth_data_file:
        cookies = pickle.load(auth_data_file)
    variables = {"AUTH_COOKIES": cookies}
    return variables
    
  8. 这将从pickle文件中读取您保存的数据并将其传递给线程。每个线程都会调用此文件一次,从一个中心位置提取数据。 get_variables()是Robot Framework中按惯例命名的函数,它为Robot运行

    设置变量