Home > Mobile >  java.lang.IllegalArgumentException: Base URI cannot be null
java.lang.IllegalArgumentException: Base URI cannot be null

Time:12-12

The loginApi method does not see the baseUrl, which is in the config file and throws an exception: java.lang.IllegalArgumentException: Base URI cannot be null. But if BaseUrl is in the class itself and not in the configuration file, then the method is executed and BaseUrl does not return 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();
    }
}

class Base

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;
    }
}

Config.properties

BaseUrl=working url

Test

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

CodePudding user response:

Because you create instance api before BUrl has value, then BaseUrl = null.

Quick fix:

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