19 Refactoring: Introduce Page Object
To use a page object from a pre-defined page class
Learning Objectives
Review: Use the defined functions in the test helper
Refactoring - Introduce Page Object
Review: Extract to Page Function
Test Data
Site: https://travel.agileway.net
Test Project: download here (or your existing one), and open in TestWise.
The test script (before refactoring): `passenger_spec.rb
`
it "User can enter passenger details" do
# TODO 1: sign in
# TODO 2: select oneway trip from Sydney to New York
# TODO 3: extract following into PassengerPage
driver.find_element(:name, "passengerFirstName").send_keys("Bob")
driver.find_element(:name, "passengerLastName").send_keys("Tester")
driver.find_element(:xpath, "//input[@value='Next']").click
expect(driver.find_element(:name, "holder_name")["value"]).to eq("Bob Tester")
end
Tasks
Task 1. Sign in using the function defined in the helper
Type ‘si
’ followed by “Ctrl + Space”, TestWise will list the helper functions for you to select.
In this case, press “Up”/"Down” keys to highlight the `sign_in(username, password)
`, then press the Enter key. Type in the arguments.
sign_in("agileway", "testwise")
Run this individual test case.
You will see “log in successfully”.
Task 2. Introduce Page Object: flight_page
Type “ep
” followed by a Tab key.
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.