java.lang.Object
net.serenitybdd.screenplay.playwright.interactions.WaitForDownload
All Implemented Interfaces:
net.serenitybdd.core.SkipNested, net.serenitybdd.screenplay.Performable

public class WaitForDownload extends Object implements net.serenitybdd.screenplay.Performable
Wait for a file download while performing an action that triggers it.

Sample usage:

     // Wait for download while clicking a link
     actor.attemptsTo(
         WaitForDownload.whilePerforming(Click.on("#download-btn"))
             .andSaveAs("downloaded-file.pdf")
     );

     // Wait for download and save to specific path
     actor.attemptsTo(
         WaitForDownload.whilePerforming(Click.on(DOWNLOAD_LINK))
             .andSaveTo(Paths.get("downloads/report.xlsx"))
     );

     // Just wait for download without saving
     actor.attemptsTo(
         WaitForDownload.whilePerforming(Click.on("#export-btn"))
     );
 

After performing this interaction, you can use DownloadedFile to query information about the most recent download.

See Also:
  • Method Details

    • whilePerforming

      public static WaitForDownload whilePerforming(net.serenitybdd.screenplay.Performable action)
      Wait for a download while performing the specified action.
      Parameters:
      action - The action that triggers the download (e.g., clicking a download button)
    • andSaveAs

      public WaitForDownload andSaveAs(String filename)
      Save the downloaded file with the specified filename in the default downloads directory.
      Parameters:
      filename - The filename to save as
    • andSaveTo

      public WaitForDownload andSaveTo(Path path)
      Save the downloaded file to the specified path.
      Parameters:
      path - The full path where the file should be saved
    • withTimeout

      public WaitForDownload withTimeout(double timeoutMs)
      Set a custom timeout for waiting for the download.
      Parameters:
      timeoutMs - Timeout in milliseconds
    • performAs

      public <T extends net.serenitybdd.screenplay.Actor> void performAs(T actor)
      Specified by:
      performAs in interface net.serenitybdd.screenplay.Performable
    • getLastDownloadKey

      public static String getLastDownloadKey()
      Get the key used to store the last download in actor's memory.