Advertisement
Guest User

Untitled

a guest
Mar 21st, 2018
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.44 KB | None | 0 0
  1. package task4;
  2.  
  3. import org.apache.http.HttpResponse;
  4. import org.apache.http.ParseException;
  5. import org.apache.http.client.methods.HttpGet;
  6. import org.apache.http.impl.client.CloseableHttpClient;
  7. import org.apache.http.impl.client.HttpClients;
  8. import org.apache.http.util.EntityUtils;
  9. import org.testng.Assert;
  10. import org.testng.annotations.AfterMethod;
  11. import org.testng.annotations.BeforeMethod;
  12. import org.testng.annotations.Test;
  13.  
  14. import java.io.IOException;
  15.  
  16. public class TestNgTask {
  17. private CloseableHttpClient httpClient;
  18.  
  19. @BeforeMethod
  20. public void setHttpClient() {
  21. httpClient = HttpClients.createDefault();
  22. }
  23.  
  24. @AfterMethod(alwaysRun = true)
  25. public void tearDownClient() throws IOException {
  26. httpClient.close();
  27. }
  28.  
  29. @Test
  30. public void firstTest() throws IOException, ParseException {
  31. HttpGet httpGet = new HttpGet("https://translate.google.com.ua/?hl=uk");
  32. HttpResponse response = httpClient.execute(httpGet);
  33. Assert.assertEquals(response.getStatusLine().getStatusCode(), 200, "Status code was not 200");
  34. Assert.assertTrue(response.getFirstHeader("Content-Type").getValue().contains("text/html"), "text/html content type was not detected");
  35. String textHtml = EntityUtils.toString(response.getEntity());
  36. System.out.println(textHtml);
  37. Assert.assertTrue(textHtml.contains("translate"), "element not found ");
  38. }
  39.  
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement