3

I'm building up a test in Geb (WebDriver) and need to submit a form which will create a file in response.

I am able to download the file (the Browser save it automatically to the disk), but I wand to check it in GEB.

  • I've tried withNewWindow(), but it only works on URIs??
  • I've tried downloadXXX(), but no luck either...

How can I download a file into a variable?

class CSVTest extends GebReportingTest 
    @Test
    void csvCreation() {
        to CSVExport

        // select entries / fill values
        selectAllEntries.value(true)

        //// 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
        submitButton.click()

        // NOT WORKING
        withNewWindow (submitButton.click()) {
            ...
        }

        // NOT WORKING
        def csv = download(submitButton.click())
    }
}
fmi
  • 163
  • 1
  • 7

1 Answers1

0

You won't be able to intercept the file downloaded by the browser after clicking a button that does a post in any way unfortunately.

You will have to synthesize a post request with the right content which is sent when using the form. While it is possible to do so using Geb's DownloadSupport class it will be complicated and clunky. You're better off using a library for which performing such requests is the main functionality, like for example REST-Assured.

erdi
  • 6,944
  • 18
  • 28