Merge lp:~jaboing/selenium-simple-test/sst-window_index into lp:selenium-simple-test

Proposed by Julien Funk
Status: Merged
Merge reported by: Corey Goldberg
Merged at revision: not available
Proposed branch: lp:~jaboing/selenium-simple-test/sst-window_index
Merge into: lp:selenium-simple-test
Diff against target: 87 lines (+29/-6)
2 files modified
src/sst/actions.py (+16/-4)
src/sst/selftests/switch_to_window.py (+13/-2)
To merge this branch: bzr merge lp:~jaboing/selenium-simple-test/sst-window_index
Reviewer Review Type Date Requested Status
Corey Goldberg (community) Approve
Review via email: mp+78668@code.launchpad.net

Commit message

New index functionality for switch_to_window and new tests

Description of the change

Added index functionality to switch_to_window and updated / added tests

To post a comment you must log in.
Revision history for this message
Corey Goldberg (coreygoldberg) wrote :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'src/sst/actions.py'
--- src/sst/actions.py 2011-10-06 19:48:04 +0000
+++ src/sst/actions.py 2011-10-07 20:56:35 +0000
@@ -71,7 +71,7 @@
71 'take_screenshot', 'debug', 'get_page_source', 'simulate_keys',71 'take_screenshot', 'debug', 'get_page_source', 'simulate_keys',
72 'is_displayed', 'element_click', 'get_element_by_xpath',72 'is_displayed', 'element_click', 'get_element_by_xpath',
73 'get_elements_by_xpath', 'switch_to_window', 'switch_to_frame',73 'get_elements_by_xpath', 'switch_to_window', 'switch_to_frame',
74 'alert_accept', 'alert_dismiss']74 'alert_accept', 'alert_dismiss',]
7575
7676
77browser = None77browser = None
@@ -903,20 +903,32 @@
903 return browser.page_source903 return browser.page_source
904904
905905
906def switch_to_window(window_name=None):906def switch_to_window(window_name=None, index=None):
907 """907 """
908 Switch focus to the specified window.908 Switch focus to the specified window.
909909
910 if no window is given, switch focus to the default window."""910 if no window is given, switch focus to the default window."""
911 if window_name is None:911 if window_name is None and index is None:
912 _print('Switching to default window')912 _print('Switching to default window')
913 browser.switch_to_window('')913 browser.switch_to_window('')
914 else:914 elif window_name is not None:
915 try:915 try:
916 _print('Switching to ' + window_name + ' window')
916 browser.switch_to_window(window_name)917 browser.switch_to_window(window_name)
917 except NoSuchWindowException:918 except NoSuchWindowException:
918 msg = 'Could not find window: %r' % window_name919 msg = 'Could not find window: %r' % window_name
919 _raise(msg)920 _raise(msg)
921 else:
922 try:
923 window_list = browser.window_handles
924 if len(window_list) <= index:
925 msg = 'Index of %r is greater than the number of available windows.' % index
926 _raise(msg)
927 _print('Switching to ' + window_list[index] + ' window')
928 browser.switch_to_window(window_list[index])
929 except NoSuchWindowException:
930 msg = 'Could not find window: %r' % window_list[index]
931 _raise(msg)
920932
921933
922def switch_to_frame(index_or_name=None):934def switch_to_frame(index_or_name=None):
923935
=== modified file 'src/sst/selftests/switch_to_window.py'
--- src/sst/selftests/switch_to_window.py 2011-09-25 20:01:09 +0000
+++ src/sst/selftests/switch_to_window.py 2011-10-07 20:56:35 +0000
@@ -5,7 +5,7 @@
5link_click('popup_link')5link_click('popup_link')
66
7# switch to new window/tab7# switch to new window/tab
8switch_to_window('_NEW_WINDOW')8switch_to_window(window_name='_NEW_WINDOW')
9title_is('Popup Window')9title_is('Popup Window')
1010
11# switch back to default/main window/tab11# switch back to default/main window/tab
@@ -21,7 +21,15 @@
21text_is(elem, 'Popup text here')21text_is(elem, 'Popup text here')
2222
23# switch back to default/main window/tab23# switch back to default/main window/tab
24switch_to_window('')24switch_to_window(window_name='')
25title_is('The Page Title')
26
27# switch to new window/tab using index
28switch_to_window(index=1)
29title_is('Popup Window')
30
31# switch back to default/main window using index
32switch_to_window(index=0)
25title_is('The Page Title')33title_is('The Page Title')
2634
27# fails when the window name does not exist35# fails when the window name does not exist
@@ -30,5 +38,8 @@
30# fails when the window name does not exist38# fails when the window name does not exist
31fails(switch_to_window, 'not_a_window')39fails(switch_to_window, 'not_a_window')
3240
41# fails when the window index does not exist
42fails(switch_to_window, index=2)
43
33# verify we are still back on main window44# verify we are still back on main window
34title_is('The Page Title')45title_is('The Page Title')

Subscribers

People subscribed via source and target branches