如何从基类中复制RequestSpecification的实例?

问题描述 投票:0回答:1

在我的基础上,我通过提供基础URI和头等来创建请求规范。

RequestSpecification base = given().baseUri( " http://xyz/" )
                                   .port( 8080 )
                                   .header( "Content-Type", "application/json" );

而在我的子 classB 我复制了基础实例,并在子类中添加了路径参数。

RequestSpecification classB= base.given()
classB.pathParam("name", "abc" );

但当我试图将基类复制到另一个子类(不需要路径参数)时,它却抛出异常,因为路径参数的数量无效。预期为1,但实际为0。

在更新路径参数时,在 ClassB有什么办法可以复制基类对象而不被更新.您的意见将非常感激!

java rest-assured
1个回答
0
投票

而不是 "应用..."。

RequestSpecification classB = base.given();
classB.pathParam("name", "abc" );

尝试。

RequestSpecification classB = given().spec(base);

这里是 spec(RequestSpecification requestSpecification) 添加来自预定义RequestSpecification对象的数据。

检查 文件

© www.soinside.com 2019 - 2024. All rights reserved.