从Java运行SoapUI测试

时间:2016-10-24 07:00:01

标签: java rest soapui

我正在尝试从Java运行SoapUI测试。我在ReadyApi中准备了一个项目,它正在使用Rest服务和两个步骤。在第一步(groovy脚本)中,我设置了测试用例属性(从JSON加载值),第二步是Rest请求。如果我从ReadyApi提交请求,一切进展顺利,我得到了正确的答复。

但如果我尝试从Java执行此测试用例,我会得到以下响应:

  

08:23:03,028 DEBUG [HttpClientSupport $ SoapUIHttpClient]尝试1执行请求   08:23:03,029 DEBUG [SoapUIMultiThreadedHttpConnectionManager $ SoapUIDefaultClientConnection]发送请求:POST / Process / op / execute HTTP / 1.1   08:23:04,391 DEBUG [SoapUIMultiThreadedHttpConnectionManager $ SoapUIDefaultClientConnection]接收响应:HTTP / 1.1 401未经授权   08:23:04,396 DEBUG [HttpClientSupport $ SoapUIHttpClient]连接可以无限期保持活动   08:23:04,396 DEBUG [HttpClientSupport $ SoapUIHttpClient]目标请求的身份验证   08:23:04,398 DEBUG [HttpClientSupport $ SoapUIHttpClient]已处理授权质询   08:23:04,399 DEBUG [HttpClientSupport $ SoapUIHttpClient]认证范围:BASIC @endpointAddress:443   08:23:04,399 INFO [HttpAuthenticationRequestFilter $ UPDCredentialsProvider] endpointAddress:443需要使用领域'null'进行身份验证   08:23:04,400 DEBUG [HttpClientSupport $ SoapUIHttpClient]发现凭证   08:23:04,403 DEBUG [HttpClientSupport $ SoapUIHttpClient]尝试2执行请求   08:23:04,403 DEBUG [SoapUIMultiThreadedHttpConnectionManager $ SoapUIDefaultClientConnection]发送请求:POST / Process / op / execute HTTP / 1.1   08:23:09,061 DEBUG [SoapUIMultiThreadedHttpConnectionManager $ SoapUIDefaultClientConnection]接收响应:HTTP / 1.1 400错误请求   08:23:09,062 DEBUG [HttpClientSupport $ SoapUIHttpClient]连接可以无限期保持活跃   08:23:41,067 DEBUG [SoapUIMultiThreadedHttpConnectionManager $ SoapUIDefaultClientConnection]连接已关闭

我的Java代码:

List<TestSuite> testSuiteList = new ArrayList<TestSuite>();
    List<TestCase> testCaseList = new ArrayList<TestCase>();

    SoapUI.setSoapUICore(new StandaloneSoapUICore(true));

    TestRunner testRunner = null;
    try {
        WsdlProject project = new WsdlProject("C:/Users/User/soapui - projects/rest-soapui-project.xml");
        testSuiteList = project.getTestSuiteList();
        Map<String,TestProperty> propertyMap;

        for (int i = 0; i < testSuiteList.size(); i++) {
            testSuiteName = testSuiteList.get(i).getName();

            System.out.println(testSuiteName);
            testCaseList = testSuiteList.get(i).getTestCaseList();
        }
        for (int i = 0; i < testCaseList.size(); i++) {
           testCaseName = testCaseList.get(i).getName();
            propertyMap = testCaseList.get(i).getProperties();
            for (Map.Entry<String, TestProperty> entry :
                    propertyMap.entrySet()) {
                String key = entry.getKey();
                TestProperty value = entry.getValue();
                System.out.println(key);
                System.out.println(entry.getValue().getValue());

            }
        }
        testRunner = project.getTestSuiteByName(testSuiteName).getTestCaseByName(testCaseName).run( new PropertiesMap(),false);

    } catch (XmlException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    } catch (SoapUIException e) {
        e.printStackTrace();
    }

0 个答案:

没有答案