Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package task4;
- import org.apache.http.HttpResponse;
- import org.apache.http.ParseException;
- import org.apache.http.client.methods.HttpGet;
- import org.apache.http.impl.client.CloseableHttpClient;
- import org.apache.http.impl.client.HttpClients;
- import org.apache.http.util.EntityUtils;
- import org.testng.Assert;
- import org.testng.annotations.AfterMethod;
- import org.testng.annotations.BeforeMethod;
- import org.testng.annotations.Test;
- import java.io.IOException;
- public class TestNgTask {
- private CloseableHttpClient httpClient;
- @BeforeMethod
- public void setHttpClient() {
- httpClient = HttpClients.createDefault();
- }
- @AfterMethod(alwaysRun = true)
- public void tearDownClient() throws IOException {
- httpClient.close();
- }
- @Test
- public void firstTest() throws IOException, ParseException {
- HttpGet httpGet = new HttpGet("https://translate.google.com.ua/?hl=uk");
- HttpResponse response = httpClient.execute(httpGet);
- Assert.assertEquals(response.getStatusLine().getStatusCode(), 200, "Status code was not 200");
- Assert.assertTrue(response.getFirstHeader("Content-Type").getValue().contains("text/html"), "text/html content type was not detected");
- String textHtml = EntityUtils.toString(response.getEntity());
- System.out.println(textHtml);
- Assert.assertTrue(textHtml.contains("translate"), "element not found ");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement