How to upload a file using a form using GEB

I am building a test in Geb (WebDriver) and have to submit a form that will create a file in response.

I can download the file (the browser automatically saves it to disk), but I checked his wand at GEB .

  • I tried withNewWindow () but it only works with URIs.
  • I tried downloadXXX () but no luck ...

How do I load a file into a variable?

class CSVTest extends GebReportingTest 
    void csvCreation() {
        to CSVExport

        // select entries / fill values

        //// this will do a post
        //// the server will render a file and deliver it back as a result of the submit
        // CORRECTLY downloads the file

        // NOT WORKING
        withNewWindow ( {

        // NOT WORKING
        def csv = download(



source to share

1 answer

You will not be able to intercept the file loaded by the browser after clicking the button that makes the message in any way, unfortunately.

You will need to synthesize the post request with the desired content that is sent when using the form. While this can be done using the Geb class DownloadSupport

, it will be complex and awkward. You are better off using a library for which making such requests is the core functionality, such as REST-Assured .



All Articles