When you write an end-to-end test that goes across multiple applications, you may need to keep multiple browser sessions active in the test flow and switch back and forth as needed.
For example, your test may require a login to Salesforce and completing a transaction. Subsequently, you may require to login into an Admin portal and approve the transaction completed in the first step. You then need to switch back to the Salesforce browser and verify if the transaction status is updated.
In this example, you need to keep multiple browser sessions active at the same time and switch between them.
Working with Browsers and Tabs
In an automation test, each independent Browser is handled by a driver. Once you create a Browser session, you may work with multiple tabs in the same browser. So, working with multiple browsers or tabs may involve this sequence.
- Step 1: Create required Browser sessions (driver sessions). When you invoke the browser in a Scenario (as part of the Init step), this is done automatically.
- Step 2: If you are working with multiple browser sessions, you can switch to the desired session before working on its tabs.
- Step 3: Work with different tabs by loading URLs or switching between tabs etc. Note that a browser pop-up emerging from an existing browser is still considered a tab in the same session.
Working with Browser Driver Sessions
You can establish a separate Driver Session for each independent browser window that you want to interact in your test. Such a session maintains its own session data. Note that multiple tabs can be part of a single driver session. Typically each driver session corresponds to an independent application window that you are accessing as part of your test flow.
ACCELQ provides the following Action logic commands to work with browser driver sessions.
Initialize new Driver session: This will invoke a new browser and assign a handle. You may either create this driver as "default" or with a given name. In general, when you are working with just one browser session in a test, you would simply create a "default" session by ignoring the session name parameter. This is done automatically when you invoke the browser in the Scenario.
Creating a driver session with a specific name provides an ability to refer to it during the test flow.
Switch to driver session: Switches the currently active browser handle to the named or default session you are interested in. Any subsequent browser-related commands now get executed against this driver session.
When you create multiple driver sessions, you can only communicate with one session at a time. You need to switch to the required session before executing logic on that browser.
Terminate driver session: When you no longer need a browser session, you may terminate it to free up system resources. By default, ACCELQ terminates all the driver sessions at the end of every test case (unless keep-alive flag is turned on during the Run).
Working with tabs/windows in a given Driver Session
Once a driver session is established, you may use the following set of commands to work with multiple tabs or windows that are part of a single driver session.
Load URL in tab: This will load the given URL in the browser's tab. You may choose to load the URL either in the currently active tab or create a new tab.
Switch to tab or window: This command helps you to switch between different tabs/windows within a driver session. You may switch based on tab index, URL, or title of the page.
Close browser tab: Closes either the current browser tab or a tab with a matching URL/title.
Note: Any logic related to creating or switching driver sessions may be most suitable to be marked as Init Actions. Learn more about Init Actions.