Web Test Automation Workbook #47: Print Invoice (file download)

Test File Download and verify in Selenium WebDriver

Zhimin Zhan
4 min readNov 11, 2022

--

This article is one of the “Web Test Automation Workbook” series (the complete training course will be on my Substack Newsletter), a set of bite-size exercises. (many coaching sessions are still not converted in writing yet, I publish the later ones for experienced automated testers)

Table of Contents:
· Learning Objectives
· Test Case #47
· Test design
· Tasks
Task 1. Verify a file exists
Task 2. To Verify a newly generated file safely
Task 3. Customize Chrome’s download path
Task 4. Ruby’s instance variables and the scope
· Full Test Script

Learning Objectives

  • Design reliable automated tests that are user aware.
  • Customize the Chrome browser to save downloaded files into a specified folder
  • Verify 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 (session #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 followings:

  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/zhimin/downloads is mine (on macOS).
  3. The 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…

--

--

Zhimin Zhan

Test automation & CT coach, author, speaker and award-winning software developer. Help teams succeed with Agile/DevOps by implementing real Continuous Testing.