【问题标题】:java.lang.IllegalArgumentException: Base URI cannot be nulljava.lang.IllegalArgumentException:基本 URI 不能为空
【发布时间】: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


    【解决方案1】:

    因为您在BUrl 有值之前创建实例api,所以BaseUrl = null。

    快速修复:

    @Test
    public void test1(){
        staticBasePage.openPage(baseUrl());
        new Api().loginAPI(ConfigProperties.getTestProperty("LoginRoot"),ConfigProperties.getTestProperty("PasswordRoot"));
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多