Skip to content

Commit

Permalink
Integration tests - switch_window method
Browse files Browse the repository at this point in the history
I added the switch_window method to pageobject, so that it can be
used by all pages.
The method switches focus between the webdriver windows.
Args:
- window_name: The name of the window to switch to.
- window_index: The index of the window handle to switch to.
If the method is called without arguments it switches to the
last window in the driver window_handles list.
In case only one window exists nothing effectively happens.
Usage:
page.switch_window('_new')
page.switch_window(2)
page.switch_window()

The motivation of writing it was to prevent the inconsistencies
encountered lately, and the common use of a deprecated similar method.
It is not meant for handling pop-ups.

I also modified test_dashboard_help_redirectionת so it now uses
the switch_window method.

Partially implements blueprint: selenium-integration-testing
Closes-Bug: #1354824

Change-Id: Ic90accc37af292994656e1b65ad5c8527b50aaed
  • Loading branch information
dkorn committed Nov 27, 2014
1 parent ec012c6 commit bc5dbdc
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 4 deletions.
25 changes: 25 additions & 0 deletions openstack_dashboard/test/integration_tests/pages/pageobject.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,31 @@ def get_url_current_page(self):
def close_window(self):
return self.driver.close()

def switch_window(self, window_name=None, window_index=None):
"""Switches focus between the webdriver windows.
Args:
- window_name: The name of the window to switch to.
- window_index: The index of the window handle to switch to.
If the method is called without arguments it switches to the
last window in the driver window_handles list.
In case only one window exists nothing effectively happens.
Usage:
page.switch_window('_new')
page.switch_window(2)
page.switch_window()
"""

if window_name is not None and window_index is not None:
raise ValueError("switch_window receives the window's name or "
"the window's index, not both.")
if window_name is not None:
self.driver.switch_to.window(window_name)
elif window_index is not None:
self.driver.switch_to.window(
self.driver.window_handles[window_index])
else:
self.driver.switch_to.window(self.driver.window_handles[-1])

def return_to_previous_page(self):
self.driver.back()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,11 @@ def test_dashboard_help_redirection(self):
"""Verifies Help link redirects to the right URL."""

self.home_pg.go_to_help_page()
for handle in self.driver.window_handles:
self.driver.switch_to_window(handle)
self.home_pg.switch_window()

self.assertEqual(self.conf.dashboard.help_url,
self.driver.current_url,
"help link did not redirect to the right URL")

self.driver.close()
for handle in self.driver.window_handles:
self.driver.switch_to_window(handle)
self.home_pg.switch_window()

0 comments on commit bc5dbdc

Please sign in to comment.