gpt4 book ai didi

testing - 在 Soap-UI 中使用 groovy 脚本检索项目的环境列表

转载 作者:行者123 更新时间:2023-11-28 21:31:55 24 4
gpt4 key购买 nike

在 SoapUI 中,我想向用户显示一个对话框,以便在执行测试运行程序时从项目中选择一个环境。

我为 ProjectRunListener.beforeRun 添加了一个事件监听器。目前,当该事件触发时,我有一个自定义库,它根据提供的 projectRunner 执行以下操作:

public static void SetEndpoints(ProjectRunner projectRunner, Logger log = null){
if (projectRunner == null) {
_Log(log, "Parameter 'projectRunner' cannot be null.");
throw new Exception();
}

if (_RunOnce(projectRunner, "SetEndpoints")){
_Log(log, "Begin - Util.SetEndpoints (Project)");

def project = (Project)projectRunner.getProject();
_SetEndpointsForTestSuites(project.getTestSuiteList(), log);

_Log(log, "End - Util.SetEndpoints (Project - ${project.name})");
}
}

public static void SetEndpoints(TestSuiteRunner testSuiteRunner, Logger log = null){
if (testSuiteRunner == null) {
_Log(log, "Parameter 'testSuiteRunner' cannot be null.");
throw new Exception();
}

if (_RunOnce(testSuiteRunner, "SetEndpoints")){
_Log(log, "Begin - Util.SetEndpoints (TestSuite)");

def testSuite = (TestSuite)testSuiteRunner.getTestSuite();
_SetEndpointsForTestSuites([testSuite], log);

_Log(log, "End - Util.SetEndpoints (TestSuite - ${testSuite.name})");
}
}

public static void SetEndpoints(TestCaseRunner testCaseRunner, Logger log = null){
if (testCaseRunner == null) {
_Log(log, "Parameter 'testCaseRunner' cannot be null.");
throw new Exception();
}

if (_RunOnce(testCaseRunner, "SetEndpoints")){
_Log(log, "Begin - Util.SetEndpoints (TestCase)");

def testCase = (TestCase)testCaseRunner.getTestCase();
_SetEndpointsForTestCases([testCase], log);

_Log(log, "End - Util.SetEndpoints (TestCase - ${testCase.name})");
}
}

private static void _SetEndpointsForProject(Project project, Logger log = null){

_SetEndpointsForTestCases(project.getTestSuiteList(), log);
}

private static void _SetEndpointsForTestSuites(List<TestSuite> testSuites, Logger log = null){
def testCases = [] as List<TestCase>;
testSuites.each{
testCases.addAll(it.getTestCaseList() as List<TestCase>);
};

_SetEndpointsForTestCases(testCases, log);
}

private static void _SetEndpointsForTestCases(List<TestCase> testCases, Logger log = null){
// Get all test request steps
//def testSteps = testCase.getTestStepList();
def testSteps = [] as List<HttpRequestTestStep>;
testCases.each {
testSteps.addAll(it.getTestStepsOfType(RestTestRequestStep.class) as List<HttpRequestTestStep>);
}

// Loop across test request steps
def stepMap = [:]
testSteps.each {
Interface iface = it.getInterface();
if (stepMap[iface.name] == null){

List<String> endpointList = Arrays.asList(iface.getEndpoints()) as List<String>;
if ((endpointList != null) && (endpointList.size() > 0)) {
def selection = JOptionPane.showInputDialog(null, "Select an endpoint:",
iface.name, JOptionPane.QUESTION_MESSAGE, null,
endpointList as String[], endpointList[0]).toString();

if (selection == null){
stepMap.put(iface.name, "IGNORE");
_Log(log, "User cancelled endpoint selection for interface ${iface.name}");
}
else {
stepMap.put(iface.name, selection);
_Log(log, "User selected endpoint '${selection}' for interface ${iface.name}");
}
}
}

// Set endpoint
if (stepMap[iface.name] != "IGNORE"){
it.getHttpRequest().setEndpoint(stepMap[iface.name]);
}
}
}

private static boolean _RunOnce(TestRunner runner, String methodName){
def context = runner.getRunContext();
if (context.getProperty(methodName) != null)
return false;

context.setProperty(methodName, methodName);
return true;
}

private static void _Log(Logger log, Object message){
if (log != null){
log.info message;
}
}

脚本,当从项目、TestSuite 或 TestCase 中获得 TestRunner 时,它将找到要执行的每个测试请求步骤的所有接口(interface),并询问用户以选择用于该测试用例的端点。它只会为每个接口(interface)查询用户一次并且它不会查询用户是否已经执行(它可以通过在运行上下文中放置一个标志来确定它会检查)。

在事件中:ProjectRunListener.beforeRun 我称之为:

Util.SetEndpoints(projectRunner, log);

在事件中:TestSuiteRunListener.beforeRunTestRunListener.beforeRun我称之为:

Util.SetEndpoints(testRunner, log);

因此,无论用户在哪个级别启动测试运行器,他/她仍然会看到对话框,为每个使用的接口(interface)选择端点。

我相信这可以使用环境选择以更好的方式完成。我在 API 中看到我能够在项目级别设置环境,这可能会将所有接口(interface)端点设置为给定事件环境的适当值。但是,我看不到我们可以获得所有可用环境列表的方法。 API 中的 Project 对象有 .setActiveEnvironment(),但没有提及获取环境列表的任何内容。

给定一个项目对象,有没有人知道获取所有已配置环境列表的方法

最佳答案

根据 API documentation ,看来以下内容应该适合您:

  • getEnvironmentList()List<com.eviware.soapui.model.environment.Environment> 中找到
  • getEnvironmentNames()
  • getEnvironmentAt(int index)getEnvironmentByName(String envName)在发现 com.eviware.soapui.model.environment.Environment

不确定您正在查看的 API 指南,但我认为这些都对您正在处理的内容有效。请注意,这是一项 PRO 功能,所以也许这就是您找不到它的原因(如果您正在查看免费版本)。

关于testing - 在 Soap-UI 中使用 groovy 脚本检索项目的环境列表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17456886/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com