This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private Predicate<Fluent> ajaxCallCompleted = new Predicate<Fluent>() { | |
@Override | |
public boolean apply(Fluent fluent) { | |
return (Boolean) ((JavascriptExecutor) getDriver()).executeScript("return (window.jQuery != null) && (jQuery.active === 0);"); | |
} | |
} | |
private static final String URL = "https://resttesttest.com/"; | |
private static final String SUCCESS_TEXT = "HTTP 200 OK"; | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Test | |
public void downloadNoSelenium() throws URISyntaxException, IOException { | |
Request request = new Request(); | |
String linkToCheck = "http://www.developsense.com/courses/RapidSoftwareTesting.pdf"; | |
request.setURIToCheck(linkToCheck); | |
assertThat(request.getHTTPStatusCodeFromResponse()).isEqualTo(SC_OK); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Request { | |
private URI linkToCheck; | |
private WebDriver driver; | |
Request() { | |
} | |
void setURIToCheck(String linkToCheck) throws URISyntaxException { | |
this.linkToCheck = new URI(linkToCheck); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class FileDownloadTest extends FluentTestNg { | |
private static final String FILE_TO_DL_SELECTOR = "ul li a"; | |
private static final String URL = "http://www.developsense.com"; | |
@Test | |
public void statusCode200() throws IOException, URISyntaxException { | |
Request request = prepareRequest(); | |
assertThat(request.getHTTPStatusCodeFromResponse()).isEqualTo(SC_OK); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Request(WebDriver driver) { | |
this.driver = driver; | |
} | |
private void addCookies(BasicHttpContext httpContext) { | |
BasicCookieStore cookies = getCurrentDriverCookies(driver.manage().getCookies()); | |
httpContext.setAttribute(HttpClientContext.COOKIE_STORE, cookies); | |
} | |
private BasicCookieStore getCurrentDriverCookies(Set<Cookie> cookies) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Test | |
public void getDownload() throws Exception { | |
Request request = prepareRequest(); | |
File downloadedFile = request.downloadFile(); | |
assertThat(downloadedFile).isNotNull(); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File downloadFile() throws Exception { | |
File downloadedFile = File.createTempFile("download", ".tmp"); | |
HttpResponse fileToDownload = getHttpResponse(); | |
FileUtils.copyInputStreamToFile(fileToDownload.getEntity().getContent(), downloadedFile); | |
return downloadedFile; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private static final String EXPECTED_MD5 = "c3fb273e2843808968d68120121f2c74"; | |
@Test | |
public void getDownloadPlusMd5() throws Exception { | |
Request request = prepareRequest(); | |
File downloadedFile = request.downloadFile(); | |
assertThat(calculateMd5(downloadedFile)).isEqualTo(EXPECTED_MD5); | |
} | |
private String calculateMd5(File downloadedFile) throws IOException { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import org.apache.commons.io.FileUtils; | |
import org.apache.http.HttpResponse; | |
import org.apache.http.client.HttpClient; | |
import org.apache.http.client.methods.HttpGet; | |
import org.apache.http.client.methods.HttpRequestBase; | |
import org.apache.http.client.protocol.HttpClientContext; | |
import org.apache.http.impl.client.BasicCookieStore; | |
import org.apache.http.impl.client.HttpClientBuilder; | |
import org.apache.http.impl.client.LaxRedirectStrategy; | |
import org.apache.http.impl.cookie.BasicClientCookie; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import org.testng.annotations.Test; | |
import java.io.IOException; | |
import java.net.URISyntaxException; | |
import static org.apache.http.HttpStatus.SC_OK; | |
import static org.assertj.core.api.Assertions.assertThat; | |
public class DownloadNoSelenium { | |
@Test |