Commit aa509f88 authored by 马博's avatar 马博

restassert 升级

加响应超时时间
parent 8e9ed3ec
...@@ -65,7 +65,7 @@ ...@@ -65,7 +65,7 @@
<dependency> <dependency>
<groupId>io.rest-assured</groupId> <groupId>io.rest-assured</groupId>
<artifactId>rest-assured</artifactId> <artifactId>rest-assured</artifactId>
<version>3.0.3</version> <version>3.3.0</version>
<scope>test</scope> <scope>test</scope>
</dependency> </dependency>
......
package base; package base;
import io.restassured.RestAssured;
import org.apache.http.client.params.ClientPNames;
import org.apache.http.params.CoreConnectionPNames;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.testng.AbstractTestNGSpringContextTests; import org.springframework.test.context.testng.AbstractTestNGSpringContextTests;
...@@ -8,6 +11,9 @@ import org.testng.annotations.BeforeSuite; ...@@ -8,6 +11,9 @@ import org.testng.annotations.BeforeSuite;
import javax.annotation.PostConstruct; import javax.annotation.PostConstruct;
import static io.restassured.RestAssured.config;
import static io.restassured.config.HttpClientConfig.httpClientConfig;
/** /**
* Created by mabo on 2018/9/20 * Created by mabo on 2018/9/20
*/ */
...@@ -25,6 +31,11 @@ public class DuibaBase extends AbstractTestNGSpringContextTestsDuiba { ...@@ -25,6 +31,11 @@ public class DuibaBase extends AbstractTestNGSpringContextTestsDuiba {
logger.info("--------------------DuibaBase.setUp() Tests"); logger.info("--------------------DuibaBase.setUp() Tests");
//只初始化一次 //只初始化一次
jdbc.initDataSource(); jdbc.initDataSource();
//设置接口响应超时时间
RestAssured.config = RestAssured.config().httpClient(httpClientConfig()
.setParam(ClientPNames.CONN_MANAGER_TIMEOUT, Long.valueOf(5000)) // HttpConnectionManager connection return time
.setParam(CoreConnectionPNames.CONNECTION_TIMEOUT, 5000) // Remote host connection time
.setParam(CoreConnectionPNames.SO_TIMEOUT, 10000));// Remote host response time
} }
......
...@@ -18,10 +18,16 @@ public class CheckTemplet extends DuibaBase { ...@@ -18,10 +18,16 @@ public class CheckTemplet extends DuibaBase {
@BeforeSuite @BeforeSuite
public void setTemplet() throws Exception { public void setTemplet() throws Exception {
logger.info("------------------------setTemplet()"); try{
this.setVirtual(); logger.info("------------------------setTemplet()");
Thread.sleep(1000); this.setVirtual();
this.setQb(); Thread.sleep(1000);
this.setQb();
}catch (Exception e){
e.printStackTrace();
}
} }
public void setVirtual() throws Exception { public void setVirtual() throws Exception {
......
...@@ -332,8 +332,8 @@ public class 自有新优惠券_兑换限制测试 extends CheckTemplet{ ...@@ -332,8 +332,8 @@ public class 自有新优惠券_兑换限制测试 extends CheckTemplet{
case 3: case 3:
// Assert.assertEquals(response.jsonPath().getString("message"),"已结束","校验日期兑换限制失败"); // Assert.assertEquals(response.jsonPath().getString("message"),"已结束","校验日期兑换限制失败");
Assert.assertTrue(message.contains("已结束"),"校验日期兑换限制失败"); Assert.assertTrue(message.contains("限2019-03-27至2019-03-27日期内兑换"),"校验日期兑换限制失败");
Assert.assertEquals(exchangeText,"已结束","校验马上兑换按钮状态失败"); Assert.assertEquals(exchangeText,"限2019-03-27至2019-03-27日期内兑换","校验马上兑换按钮状态失败");
logger.info("校验实物日期兑换限制已结束成功"); logger.info("校验实物日期兑换限制已结束成功");
break; break;
......
...@@ -3,7 +3,10 @@ package http.cases.ExchangeTest.自有_商品兑换限制; ...@@ -3,7 +3,10 @@ package http.cases.ExchangeTest.自有_商品兑换限制;
import http.cases.ExchangeTest.CheckTemplet; import http.cases.ExchangeTest.CheckTemplet;
import http.service.Authorization; import http.service.Authorization;
import http.service.app.MobileService; import http.service.app.MobileService;
import io.restassured.RestAssured;
import io.restassured.response.Response; import io.restassured.response.Response;
import org.apache.http.client.params.ClientPNames;
import org.apache.http.params.CoreConnectionPNames;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.testng.Assert; import org.testng.Assert;
import org.testng.annotations.BeforeMethod; import org.testng.annotations.BeforeMethod;
...@@ -14,6 +17,11 @@ import utils.MatcherString; ...@@ -14,6 +17,11 @@ import utils.MatcherString;
import java.lang.reflect.Method; import java.lang.reflect.Method;
import java.sql.SQLException; import java.sql.SQLException;
import static io.restassured.RestAssured.config;
import static io.restassured.RestAssured.given;
import static io.restassured.config.HttpClientConfig.httpClientConfig;
import static io.restassured.config.RestAssuredConfig.newConfig;
/** /**
* Created by mabo on 2019/3/26 * Created by mabo on 2019/3/26
*/ */
...@@ -47,6 +55,12 @@ public class 自有新卡密_兑换限制测试 extends CheckTemplet { ...@@ -47,6 +55,12 @@ public class 自有新卡密_兑换限制测试 extends CheckTemplet {
} }
// @Test
// public void test(){
//
// Response response = given().get("http://localhost:1112/sql/test");
// response.prettyPrint();
// }
@DataProvider @DataProvider
public Object[][] providerMethod(Method method) { public Object[][] providerMethod(Method method) {
......
...@@ -317,8 +317,8 @@ public class 自有新虚拟商品_充值_兑换限制 extends CheckTemplet{ ...@@ -317,8 +317,8 @@ public class 自有新虚拟商品_充值_兑换限制 extends CheckTemplet{
case 1: case 1:
// Assert.assertEquals(response.jsonPath().getString("message"),"请在限定时间内兑换哦(13)","校验日期兑换限制失败"); // Assert.assertEquals(response.jsonPath().getString("message"),"请在限定时间内兑换哦(13)","校验日期兑换限制失败");
Assert.assertTrue(message.contains("限2019-03-28至2032-04-30日期内兑换"),"校验日期兑换限制失败"); Assert.assertTrue(message.contains("限2030-03-29至2032-04-29日期内兑换"),"校验日期兑换限制失败");
Assert.assertEquals(exchangeText,"限2019-03-28至2032-04-30日期内兑换","校验马上兑换按钮状态失败"); Assert.assertEquals(exchangeText,"限2030-03-29至2032-04-29日期内兑换","校验马上兑换按钮状态失败");
logger.info("校验实物日期兑换限制未开始成功"); logger.info("校验实物日期兑换限制未开始成功");
break; break;
...@@ -331,8 +331,8 @@ public class 自有新虚拟商品_充值_兑换限制 extends CheckTemplet{ ...@@ -331,8 +331,8 @@ public class 自有新虚拟商品_充值_兑换限制 extends CheckTemplet{
case 3: case 3:
// Assert.assertEquals(response.jsonPath().getString("message"),"已结束","校验日期兑换限制失败"); // Assert.assertEquals(response.jsonPath().getString("message"),"已结束","校验日期兑换限制失败");
Assert.assertTrue(message.contains("已结束"),"校验日期兑换限制失败"); Assert.assertTrue(message.contains("限2019-03-27至2019-03-27日期内兑换"),"校验日期兑换限制失败");
Assert.assertEquals(exchangeText,"已结束","校验马上兑换按钮状态失败"); Assert.assertEquals(exchangeText,"限2019-03-27至2019-03-27日期内兑换","校验马上兑换按钮状态失败");
logger.info("校验实物日期兑换限制已结束成功"); logger.info("校验实物日期兑换限制已结束成功");
break; break;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment