Learning Objectives
Review
Xpath locator
Select an option in a dropdown list
Multiple test cases in one test script file
Two test execution modes (test script vs test case)
Test execution side-effect
Comment
Move shared steps to a `before(…)` execution hook.
Debugging tip to keep the browser open temporarily in test script execution mode.
Test Case 09
After implementing Test Case 09, ensure both tests (oneway and return) pass in this test script file.
Tasks
Task 1. Click the ‘Return’ radio button and select dates from dropdown lists.
There are no new concepts here; refer to Session #08.
Don’t copy-n-paste previous code. Instead, type (using snippets) to familiarise yourself with Selenium syntax.
Task 2. Make the two tests pass.
There are two select-flight (one-way and return) tests in the same test script. Each test runs fine on its own. But when running the test script, the second test fails (which is quite common).
The cause is, of course, the execution side effect. But wait, if your test script is like the above, it has a design flaw: each test case has user sign-in steps.
When you manually test it, usually, you don’t do sign-out and then sign-in for the second test. One logged-in user can perform two bookings within one user session. From a testing perspective (focusing on flight selection), it is faster to perform within one user session.
Move the user login statements (in two test cases) into
before(:all)
block.
Run the test script again. It still fails.
What happened? The most logical way is to find out what is in the browser window. However, the browser window is closed.
Keep reading with a 7-day free trial
Subscribe to AgileWay’s Test Automation & Continuous Testing Blog to keep reading this post and get 7 days of free access to the full post archives.