Member-only story
Extend Function Behaviour with Optional Parameters in Automated E2E Scripts
Without breaking existing test scripts
In the article “Using Default Parameter Values in Automated E2E Test Scripts with Ruby,” I discussed how to leverage function default parameter values in E2E test scripts. Here, I will showcase a specific (and simple) technique for extending functions that my father taught me — one that is both practical and frequently used.
In E2E scripting, following Maintainable Automated Test Design, we define reusable helper functions and page functions (in POM).
These two functional test design patterns are applicable to nearly any programming language; here, I demonstrate them using the Ruby language.
1. Reusable helper functions
Example:
def login(username, password)
driver.find_element(:id, "username").sendkeys(username)
driver.find_element(:id, "password").sendkeys(password)
driver.find_element(:input, "//input[@value='Sign in']").click
end
2. Page Functions (in page object model)
Example:
it "User can enter passenger details" do
sign_in("agileway", "testwise")
flight_page = FlightPage.new(driver)…