Using Default Parameter Values in Automated E2E Test Scripts with Ruby
Using Ruby default parameter in your E2E test scripts can make your scripts more readable.
2 min readDec 27, 2024
Non-Medium-Members: Read this article free on Substack.
Below is an example of a typical user login test implemented using Selenium WebDriver in Ruby.
it "User Login OK" do
driver.find_element(:id, "username").sendkeys("whenwise")
driver.find_element(:id, "password").sendkeys("test01")
driver.find_element(:input, "//input[@value='Sign in']").click
#...
end
Obviously, we are going to use these three test steps often in other tests. Following the Maintainable Automated Test Design, make it a reusable function (by invoking a “Extract Function” refactoring, which TestWise can do).
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
it "User Login OK" do
login("whenwise", "test01")
#...
end
it "User Login OK failed with a wrong password" do
login("whenwise", "tryluck")
#...
end
it "Other User Login OK" do
login("buildwise", "test01")
#...
end
it "Another User Login OK" do
login("testwise"…