08 Select Oneway Flight
Introduce Xpath locator and drive a select list.
Learning Objectives
Clone an existing test script file
XPath Locator
Drive a Select (Combo) box in Selenium WebDriver
Review
enter TestWise debugging mode
work on individual test steps (one by one) in TestWise debugging mode
copy the working test steps over to complete the test script.
Test Case 08
After login (session #04), perform the four steps as shown in the task card. Ignore the selecting departing dates for now.
A reminder: perform manual testing first.
Test Design
First of all, this will be a new test script file, with two test cases. These two test cases are similar.
Start a new test script
Can copy over the previous login steps over.
Click the one-way radio button
Select a departure city
Select a destination city
Click the continue button
Assert the “ departure city to destination city
Tasks
Task 1. Clone an existing test script
Highlight the login script file (`07-login_spec.rb
’) and select “Refactor” → “Copy File …”.
In the “Copy File” dialog, enter the new file name, in this case, ‘08-select_flight_spec.rb
’.
You change change a different name. This is a test script file, must end with ‘
_spec.rb
’.Also, dont include space or special characters in a file name.
A new test script file ‘08-select_flight_spec.rb
’ will be created with the content from the ‘login_spec.rb
’.
Tip: After copy-n-paste, I immediately put my mind in alert mode. Why? I have been “lazy”. I must act quickly to change the copied code.
Update the “test group name” and “test case name” (as bolded below).
describe "Select Flights" do
include TestHelper
before(:all) do
# browser_type, site_url defined in test_helper.rb
@driver = Selenium::WebDriver.for(browser_type, browser_options)
driver.manage().window().resize_to(1280, 800)
driver.get("https://travel.agileway.net")
end
after(:all) do
driver.quit unless debugging?
end
it "User can select one way trip" do
driver.find_element(:id, "username").send_keys("agileway")
driver.find_element(:name, "password").send_keys("testwise")
driver.find_element(:name, "commit").click
expect(page_text).to include("Signed in!")
# ...
end
end
Also, I append “#…
” (comment) to remind me that the test case is incomplete.
Task 2. Start developing a new test case, one-way trip.
Repeat the process of how we did our login test:
Run the test case
(individual test execution mode)After the test execution completes, focus on the Chrome browser window
Prepare to inspect the control of the next operation, in this case, the “one-way radio button”.
(you did manual testing first, right?)
Task 3. Click the one-way radio button
Right-click the radio button, and get its HTML:
<input type="radio" name="tripType" value="oneway" onclick="$('#returnTrip').hide();">
There is no ID, seems a good case for the NAME locator.
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.