Эта ошибка происходит в строке restclient.get()
Помощь здесь
Я предоставил весь класс
Класс Restclient ->
Код: Выделить всё
public class Restclient {
// Hit get method
@SuppressWarnings("deprecation")
public void get(String url) throws IOException, ParseException, URISyntaxException {
HttpGet httpget = new HttpGet(url);
try (CloseableHttpClient httpClient = HttpClients.createDefault()) {
CloseableHttpResponse response = httpClient.execute(httpget);
System.out.println("Response status: " + response.getReasonPhrase());
int statuscode = response.getCode();
System.out.println("Status code : " + statuscode);
String responseString = EntityUtils.toString(response.getEntity(), "UTF-8");
JsonObject responseJson = JsonParser.parseString(responseString).getAsJsonObject();
System.out.println("Response from API : " + responseJson);
Header[] headerarray = response.getHeaders();
Map allheader = new HashMap();
for (Header header : headerarray) {
allheader.put(header.getName(), header.getValue());
}
System.out.println(allheader);
}
}
}
публичный класс BaseClass {
Код: Выделить всё
public Properties prop;
public BaseClass() {
try {
prop = new Properties();
FileInputStream ip = new FileInputStream("app/src/main/java/com/mypackage/config/config.properties");
prop.load(ip);
} catch (IOException e) {
e.printStackTrace();
}
}
публичный класс GetAPITest расширяет BaseClass {
Код: Выделить всё
BaseClass base;
String endpoint;
String apiurl;
String url;
Restclient restClient;
@BeforeMethod
public void setup() {
base = new BaseClass();
apiurl = prop.getProperty("url");
endpoint = prop.getProperty("endpoint");
url = apiurl + endpoint;
}
@Test
public void getAPITest() throws ParseException, IOException, URISyntaxException {
restClient = new Restclient();
restClient.get(url);
}
url = https://reqres.in/
конечная точка = api/users?page=1
Подробнее здесь: https://stackoverflow.com/questions/792 ... -specified