【发布时间】:2022-01-15 22:08:35
【问题描述】:
loginApi方法看不到baseUrl,在config文件中 并抛出异常:java.lang.IllegalArgumentException: Base URI cannot be null。 但是如果BaseUrl在类本身而不是在配置文件中,则执行该方法并且BaseUrl不会返回null
public class Api extends Base {
public void loginAPI(String username, String password) {
Response response = RestAssured.given().log().all().
contentType("application/x-www-form-urlencoded").
given().
param("username", username).
param("password", password).
baseUri(BaseUrl).basePath("/manager/login/").
when().post().
then().extract().response();
}
}
类基础
public class Base {
static public String BUrl;
String BaseUrl = BUrl;
public static String baseUrl(){
if (alternativeBaseUrl_1 != null){
BUrl = alternativeBaseUrl_1;
}else {
BUrl = ConfigProperties.getTestProperty("BaseUrl");
}
return BUrl;
}
}
配置属性
BaseUrl=working url
测试
@Test
public void test1(){
staticBasePage.openPage(baseUrl());
api.loginAPI(ConfigProperties.getTestProperty("LoginRoot"),ConfigProperties.getTestProperty("PasswordRoot"));
}
【问题讨论】:
标签: java selenium rest-assured qa