我正在创建一个从SoapUI运行的常规脚本,以通过VSTS api在VSTS中创建测试计划,但是在执行该脚本时却遇到了HTTP400错误。虽然在SoapUI的REST步骤中使用相同的标头成功运行了相同的请求。
最初,我在授权时出错,但是现在解决了。 看来我传递请求正文的方式不正确
import groovyx.net.http.HTTPBuilder
import static groovyx.net.http.ContentType.JSON
import org.apache.commons.codec.binary.Base64;
import com.eviware.soapui.support.types.StringToStringMap
import org.apache.http.client.methods.HttpPost;
import java.io.File;
import java.io.IOException;
import groovy.json.JsonBuilder
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.mime.MultipartEntity;
import org.apache.http.entity.mime.content.FileBody;
import org.apache.http.entity.mime.content.StringBody;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.util.EntityUtils;
import static groovyx.net.http.Method.*;
import groovyx.net.http.*
import static groovyx.net.http.ContentType.*
import static groovyx.net.http.Method.*
import org.apache.http.HttpResponse;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.protocol.HTTP;
import org.apache.commons.httpclient.methods.PostMethod;
import org.apache.http.entity.StringEntity;
import static groovy.json.JsonOutput.toJson;
HttpClient httpclient = new DefaultHttpClient();
def post = new HttpPost("https://dev.azure.com/xxx?api-version=1.0");
def jsonBody = [:]
// Test title
jsonBody.put("title", "Test title")
def http = new HTTPBuilder( 'https://dev.azure.com/xxx?api-version=1.0' )
post.addHeader("Authorization","Basic
Onvdfdsfgsdgdfhgfhgfhgfhjgfhtrhtrhtrhtrbvdfb=");
post.addHeader("Accept","application/json");
post.setEntity(jsonBody)
HttpResponse response = httpclient.execute(post);
预期结果:应在VSTS中使用提供的名称创建新的测试计划。
实际结果:获取错误:星期二1月15日17:03:14 IST 2019:INFO:HTTP / 1.1 400错误请求[缓存控制:无缓存,无存储,必须重新验证,语法:无缓存,内容长度:207,内容类型:application / json; charset = utf-8,到期时间:-1,P3P:CP =“ CAO DSP COR ADMa DEV CONo TELo CUR PSA PSD TAI IVDo我们的SAMI BUS DEM NAV STA UNI COM INT PHY ONL FIN PUR LOC CNT”,Set-Cookie:VstsSession =%7B%22PersistentSessionId%22%3A%22b53ba5ae-5940-4bc4-b464-24b72350fd09%22%2C%22PendingAuthenticationSessionId%22%3A%2200000000-0000-0000-0000-000000000000%22%2C%22CurrentAuthenticationSessionId%22%3A% 2200000000-0000-0000-0000-000000000000%22%7D; domain = .dev.azure.com; expires = Sun,2024年1月14日11:36:12 GMT;路径= /;安全; HttpOnly,X-TFS-ProcessId:ffde6ea4-0faa-4f90-b5d8-07ed687398f7,严格传输安全性:max-age = 31536000; includeSubDomains,ActivityId:3b96e21f-0539-4724-b31f-178b14072bb1,X-TFS-Session:3b96e21f-0539-4724-b31f-178b14072bb1,X-VSS-E2EID:3b96e21f-0539-4724-b31f-178b14072bb1,X-VSS-用户数据:3486938b-c20d-69ff-9eca-14d4011c8ebf:bmalviya @ xxx.com,X-框架选项:SAMEORIGIN,X-AspNet版本:4.0.30319,X-Powered-By:ASP.NET,X-Content-类型选项:nosniff,X-MSEdge-Ref:Ref A:BD9BB78BC2814FFD94BEE99ECAE98955 Ref B:BY3EDGE0205 Ref C:2019-01-15T11:36:12Z,Date:Tue,15 Jan 2019 11:36:11 GMT]
答案 0 :(得分:0)
如果您可以使其与常规的REST TestStep一起使用,我将以此为基础构建您的功能。
def result = testRunner.testCase.getTestStepByName("The Name Of Your Rest Request TestStep").run(testRunner, context)
然后您可能要检查测试步骤是否按预期执行。但这应该做到。 Groovy脚本TestStep将是TestCase Runner唯一激活的脚本,但是脚本将根据您的代码激活REST Request TestStep 0-N次。确保Groovy脚本可以根据需要即时修改Properties TestStep的值。
答案 1 :(得分:0)
我在套件中创建了4个新的测试步骤: 1:属性 2:Groovy测试步骤 3:2个HTTP请求方法测试步骤
在属性测试步骤中,我根据测试结果存储了2个标记的值,即PassFlag和FailFlag,其值为“ T”。 在常规测试步骤中,我从属性测试步骤中获取了值,一旦代码找到PassFlag的值为“ T”,它将移至测试步骤“ HTTP方法”,并通过详细信息将测试用例传递给“ HTTP方法”。无法通过测试用例的详细信息。下面是常规代码:
import com.eviware.soapui.support.*;
import com.jcraft.jsch.*
def groovyUtils = new com.eviware.soapui.support.GroovyUtils( context )
def myTestCase = testRunner.getTestCase()//myTestCase contains the test case
propTestStep = myTestCase.getTestStepByName("PassFailStatus") // get the Property
TestStep object
def testCase = testRunner.getTestCase()
def propTestStep = testCase.getTestStepByName("PassFailStatus")
def Passvalue = propTestStep.getPropertyValue("PassFlag").toString()
def Failvalue = propTestStep.getPropertyValue("FailFlag").toString()
if(Passvalue == "T"){
Thread.sleep(30000)
testRunner.gotoStep(testRunner.testCase.getTestStepIndexByName('PassTestCase'))
log.info("success")
}else{
testRunner.gotoStep(testRunner.testCase.getTestStepIndexByName('FailTestCase'))
log.info("Failure")
}