Skip to content

Selenium extension for Java which provides KPIs of file downloads.

License

Notifications You must be signed in to change notification settings

AutomatedOwl/selenium-download-kpi

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

22 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

selenium-download-kpi

Selenium extension for Java which provides KPIs of file download. Currently, the library supports Chromedriver. It would allow you:

  • To define your download folder both globally and locally in one code line.
  • Given a file name, web element and timeout, you would be able to download a file and verify its success.
  • Logging the download bandwidth in Mbps and attaching it to Allure report.
  • Assertion of download bandwidth, where you define a numeric threshold for passing/failing the test.

Setting up your test

To easily define your download folder, create a new instance of SeleniumDownloadKPI object, with the download folder path supplied as String parameter.

After initialization of SeleniumDownloadKPI object, and before initializing your Chromedriver object, use generateDownloadFolderCapability() method to get ChromeOptions object which contains your download folder, then pass it to Chromedriver constructor.

    private SeleniumDownloadKPI seleniumDownloadKPI;

    @BeforeEach
    void setUpTest() {
        seleniumDownloadKPI =
             new SeleniumDownloadKPI("/tmp/downloads");
        ChromeOptions chromeOptions =
                seleniumDownloadKPI.generateDownloadFolderCapability();
        driver = new ChromeDriver(chromeOptions);
    }

Example of file download with bandwidth attachment:

The method fileDownloadKPI() receives three parameters:

WebElement object: adamInternetPage.getFileDownloadLink() returns a WebElement of download link.

String object: "SpeedTest_16MB.dat" describes the file name which intended to be downloaded.

boolean deleteFile: Indicates whether to delete or keep the file after the download finishes.

The method would perform a download using a default timeout of five minutes, and would also throw an exception in case of unsuccessful download.

    @Test
    void downloadAttachTest() throws InterruptedException {
        adamInternetPage.navigateToPage(driver);
        seleniumDownloadKPI.fileDownloadKPI(
                adamInternetPage.getFileDownloadLink(), "SpeedTest_16MB.dat", true);
        waitBeforeClosingBrowser();
    }

Example of file download with bandwidth attachment (custom timeout):

Alternative variation of fileDownloadKPI() method. The method would act exactly the same as described above, just with a custom download timeout of one minute passed as third argument (in milliseconds).

    @Test
    void downloadAttachCustomTimeoutTest() throws InterruptedException {
        adamInternetPage.navigateToPage(driver);
        seleniumDownloadKPI.fileDownloadKPI(
                adamInternetPage.getFileDownloadLink(),
                "SpeedTest_16MB.dat", 60000, true);
        waitBeforeClosingBrowser();
    }

Example of file download with attachment and assertion:

The method fileDownloadAssertKPI() receives four parameters:

WebElement object: adamInternetPage.getFileDownloadLink() returns WebElement of download link.

String object: "SpeedTest_16MB.dat" describes the file name which intended to be downloaded.

Long value '5' is the Mbps threshold for the file download. If the download bandwidth would be less than 5Mbps, exception would be thrown.

boolean deleteFile: Indicates whether to delete or keep the file after the download finishes.

It also uses a default download timeout of five minutes.

    @Test
    void downloadAssertTest() throws InterruptedException {
        adamInternetPage.navigateToPage(driver);
        seleniumDownloadKPI.fileDownloadAssertKPI(
                adamInternetPage.getFileDownloadLink(),
                "SpeedTest_16MB.dat", 5, true);
        waitBeforeClosingBrowser();
    }

Example of file download with attachment and assertion (custom timeout):

Alternative variation of fileDownloadAssertKPI() method. The method would act exactly the same as described above, just with a custom download timeout of one minute passed as fourth argument (in milliseconds).

    @Test
    void downloadAssertTest() throws InterruptedException {
        adamInternetPage.navigateToPage(driver);
        seleniumDownloadKPI.fileDownloadAssertKPI(
                 adamInternetPage.getFileDownloadLink(),
                 "SpeedTest_16MB.dat", 5, 60000, true);
        waitBeforeClosingBrowser();
    }

Sanpshot of file download with bandwidth attachment in Allure report:

Bandwidth Attachment

Sanpshot of bandwidth exception:

Bandwidth Exception

Sanpshot of bandwidth logging:

Bandwidth Logging

Maven repository

<dependency>
  <groupId>com.github.automatedowl</groupId>
  <artifactId>selenium-download-kpi</artifactId>
  <version>1.0.3</version>
</dependency>