我有一些机器人框架测试,我正在尝试使用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}}
答案 0 :(得分:0)
假设您必须进行1次登录并使用该数据与Pabot进行多次测试。
使用Python文件将Pabot作为子进程启动(例如,run_my_tests.py)
在该文件中,创建一个执行设置的功能。可以像你希望的那样精心制作。确保它创建所有必要的数据。该数据可以放入字典或列表中。
腌制数据。这会将对象保留在文件中。
在run_my_tests.py中,将pabot参数设置为包含pabot本身的列表。例如:
pabot_command = ['pabot',' - processes','10',' - variable','TEST_ENV:dev']
在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
这将从pickle文件中读取您保存的数据并将其传递给线程。每个线程都会调用此文件一次,从一个中心位置提取数据。 get_variables()是Robot Framework中按惯例命名的函数,它为Robot运行
设置变量