Class: Playwright::Download

Inherits:
PlaywrightApi show all
Defined in:
lib/playwright_api/download.rb

Overview

Download objects are dispatched by page via the [‘event: Page.download`] event.

All the downloaded files belonging to the browser context are deleted when the browser context is closed. All downloaded files are deleted when the browser closes.

Download event is emitted once the download starts. Download path becomes available once download completes:

“‘js const [ download ] = await Promise.all([

page.waitForEvent('download'), // wait for download to start
page.click('a')

]); // wait for download to complete const path = await download.path(); “‘

“‘python async async with page.expect_download() as download_info:

await page.click("a")

download = await download_info.value # waits for download to complete path = await download.path() “‘

“‘python sync with page.expect_download() as download_info:

page.click("a")

download = download_info.value # wait for download to complete path = download.path() “‘

> NOTE: Browser context must be created with the acceptDownloads set to true when user needs access to the downloaded content. If acceptDownloads is not set, download events are emitted, but the actual download is not performed and user has no access to the downloaded files.

Instance Method Summary collapse

Methods inherited from PlaywrightApi

#==, from_channel_owner, #initialize

Constructor Details

This class inherits a constructor from Playwright::PlaywrightApi

Instance Method Details

#create_read_streamObject

Returns readable stream for current download or null if download failed.

Raises:

  • (NotImplementedError)


41
42
43
# File 'lib/playwright_api/download.rb', line 41

def create_read_stream
  raise NotImplementedError.new('create_read_stream is not implemented yet.')
end

#deleteObject

Deletes the downloaded file.

Raises:

  • (NotImplementedError)


46
47
48
# File 'lib/playwright_api/download.rb', line 46

def delete
  raise NotImplementedError.new('delete is not implemented yet.')
end

#failureObject

Returns download error if any.

Raises:

  • (NotImplementedError)


51
52
53
# File 'lib/playwright_api/download.rb', line 51

def failure
  raise NotImplementedError.new('failure is not implemented yet.')
end

#pathObject

Returns path to the downloaded file in case of successful download.

Raises:

  • (NotImplementedError)


56
57
58
# File 'lib/playwright_api/download.rb', line 56

def path
  raise NotImplementedError.new('path is not implemented yet.')
end

#save_as(path) ⇒ Object

Saves the download to a user-specified path.

Raises:

  • (NotImplementedError)


61
62
63
# File 'lib/playwright_api/download.rb', line 61

def save_as(path)
  raise NotImplementedError.new('save_as is not implemented yet.')
end

#suggested_filenameObject

Returns suggested filename for this download. It is typically computed by the browser from the [Content-Disposition](developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Disposition) response header or the download attribute. See the spec on [whatwg](html.spec.whatwg.org/#downloading-resources). Different browsers can use different logic for computing it.

Raises:

  • (NotImplementedError)


69
70
71
# File 'lib/playwright_api/download.rb', line 69

def suggested_filename
  raise NotImplementedError.new('suggested_filename is not implemented yet.')
end

#urlObject

Returns downloaded url.

Raises:

  • (NotImplementedError)


74
75
76
# File 'lib/playwright_api/download.rb', line 74

def url
  raise NotImplementedError.new('url is not implemented yet.')
end