-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #357 from dn0000001/header-support-file-download
Add support to add header when downloading files
- Loading branch information
Showing
8 changed files
with
185 additions
and
34 deletions.
There are no files selected for viewing
67 changes: 67 additions & 0 deletions
67
...ts/src/main/java/com/automation/common/ui/app/pageObjects/FileExamplesOtherFilesPage.java
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
package com.automation.common.ui.app.pageObjects; | ||
|
||
import com.lazerycode.selenium.filedownloader.FileDownloader; | ||
import com.taf.automation.ui.support.PageObjectV2; | ||
import com.taf.automation.ui.support.TestContext; | ||
import com.taf.automation.ui.support.util.AssertJUtil; | ||
import com.thoughtworks.xstream.annotations.XStreamOmitField; | ||
import org.apache.http.HttpStatus; | ||
import org.openqa.selenium.support.FindBy; | ||
import ui.auto.core.components.WebComponent; | ||
|
||
import java.io.File; | ||
|
||
/** | ||
* This the Other Files page on the site <a href="https://file-examples.com/">File Examples</a> | ||
*/ | ||
@SuppressWarnings("java:S3252") | ||
public class FileExamplesOtherFilesPage extends PageObjectV2 { | ||
private static final String LINK_HTTP_STATUS = "Link HTTP Status"; | ||
|
||
@XStreamOmitField | ||
@FindBy(css = "[download$='.csv']") | ||
private WebComponent downloadSampleCsvFile; | ||
|
||
public FileExamplesOtherFilesPage() { | ||
super(); | ||
} | ||
|
||
public FileExamplesOtherFilesPage(TestContext context) { | ||
super(context); | ||
} | ||
|
||
/** | ||
* Perform download of the CSV file using an element | ||
* | ||
* @return the CSV file that was saved to a temporary file which needs to be deleted after | ||
*/ | ||
public File performDownloadOfCsvFileUsingElement() { | ||
FileDownloader downloader = new FileDownloader(getDriver()); | ||
downloader.withURISpecifiedInAnchorElement(downloadSampleCsvFile.getCoreElement()); | ||
|
||
// This is unnecessary and only for testing purposes | ||
int status = downloader.getLinkHTTPStatus(); | ||
AssertJUtil.assertThat(status).as(LINK_HTTP_STATUS).isEqualTo(HttpStatus.SC_OK); | ||
|
||
// For testing purposes, we are setting the suffix | ||
return downloader.downloadFile(".csv"); | ||
} | ||
|
||
/** | ||
* Perform download of the CSV file using a URL | ||
* | ||
* @return the CSV file that was saved to a temporary file which needs to be deleted after | ||
*/ | ||
public File performDownloadOfCsvFileUsingUri() { | ||
FileDownloader downloader = new FileDownloader(getDriver()); | ||
downloader.withURI(downloadSampleCsvFile.getAttribute("href")); | ||
|
||
// This is unnecessary and only for testing purposes | ||
int status = downloader.getLinkHTTPStatus(); | ||
AssertJUtil.assertThat(status).as(LINK_HTTP_STATUS).isEqualTo(HttpStatus.SC_OK); | ||
|
||
// For testing purposes, we are setting the both the prefix & suffix | ||
return downloader.downloadFile("auto-", ".csv"); | ||
} | ||
|
||
} |
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
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
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
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
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
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
24 changes: 24 additions & 0 deletions
24
taf/src/main/java/com/taf/automation/api/clients/FileDownloaderClient.java
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package com.taf.automation.api.clients; | ||
|
||
import com.taf.automation.api.ParametersType; | ||
import com.taf.automation.api.ReturnType; | ||
import com.taf.automation.ui.support.TestProperties; | ||
import org.apache.http.impl.client.CloseableHttpClient; | ||
|
||
/** | ||
* Wrapper class to provide a CloseableHttpClient for use in the FileDownloader class without exposing it to all classes | ||
*/ | ||
public class FileDownloaderClient { | ||
private static final String URL = "https://www.google.com"; // Any valid url | ||
private static final int TIMEOUT = TestProperties.getInstance().getApiTimeout(); | ||
private final ApiClient apiClient; | ||
|
||
public FileDownloaderClient() { | ||
apiClient = new ApiClient(ParametersType.GENERAL, ReturnType.GENERAL, URL, null, null, TIMEOUT, TIMEOUT); | ||
} | ||
|
||
public CloseableHttpClient getClient() { | ||
return apiClient.getClient(); | ||
} | ||
|
||
} |