The Agile Way

The Agile Way

Share this post

The Agile Way
The Agile Way
#47: Print An Invoice (File Download)
Selenium Training Workbook

#47: Print An Invoice (File Download)

Test File Download and Verify in Selenium WebDriver

Courtney Zhan's avatar
Courtney Zhan
Oct 05, 2024
∙ Paid
1

Share this post

The Agile Way
The Agile Way
#47: Print An Invoice (File Download)
Share

Learning Objectives

  • Design reliable automated tests that are user aware.

  • Customize the Chrome browser to save downloaded files into a specified folder

  • Verify a File Exists

  • Awareness of execution side effects: the file already exists

  • Review: "#{variable}/..."

Test Case #47

Test design

  • Login (business): physio@biz.com (password: test01 )

  • Create an invoice (See Exercise #46)

  • Click the “Print” link, wait up to 5 seconds, and then check the PDF file is generated.

Obviously, the focus of this exercise is to check the downloaded file. It appears very simple during manual testing. However, in test automation, we need to consider the following:

  1. How to verify a file exists?
    This is easy: use code.

  2. To be able to do the above step, two pieces of information are required:
    - the file name, in this case, invoice_C000002.pdf
    - the path of the Chrome download folder. This will depend on who you logged in and on which platform. For example, /Users/courtney/downloads is mine (on macOS).

  3. The hardcoded folder path can be problematic in a software team where all team members utilize the automated tests. Ideally, we would like the path of the Chrome download folder to be static.

  4. We can set the download folder path when starting a Chrome browser in Selenium scripts.

  5. The file might already exist before the test execution.
    After running the test once, the file would be created. So on the second runu, depending on the operating system, the behaviour will be different. For example, on macOS, a suffix (1) (image below) will be added.
    How shall we solve it? By deleting the file in the test script before clicking the ‘Print” button.

Tasks

I suggest doing this exercise step by step. Check the downloaded file first, such as /Users/ME/invoice_C000002.pdf. If this part is working, add the dynamic part.

Task 1. Verify a file exists

Keep reading with a 7-day free trial

Subscribe to The Agile Way to keep reading this post and get 7 days of free access to the full post archives.

Already a paid subscriber? Sign in
© 2025 Zhimin Zhan
Privacy ∙ Terms ∙ Collection notice
Start writingGet the app
Substack is the home for great culture

Share