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
1=== modified file 'src/sst/actions.py'
2--- src/sst/actions.py 2011-10-06 19:48:04 +0000
3+++ src/sst/actions.py 2011-10-07 20:56:35 +0000
4@@ -71,7 +71,7 @@
5 'take_screenshot', 'debug', 'get_page_source', 'simulate_keys',
6 'is_displayed', 'element_click', 'get_element_by_xpath',
7 'get_elements_by_xpath', 'switch_to_window', 'switch_to_frame',
8- 'alert_accept', 'alert_dismiss']
9+ 'alert_accept', 'alert_dismiss',]
10
11
12 browser = None
13@@ -903,20 +903,32 @@
14 return browser.page_source
15
16
17-def switch_to_window(window_name=None):
18+def switch_to_window(window_name=None, index=None):
19 """
20 Switch focus to the specified window.
21
22 if no window is given, switch focus to the default window."""
23- if window_name is None:
24+ if window_name is None and index is None:
25 _print('Switching to default window')
26 browser.switch_to_window('')
27- else:
28+ elif window_name is not None:
29 try:
30+ _print('Switching to ' + window_name + ' window')
31 browser.switch_to_window(window_name)
32 except NoSuchWindowException:
33 msg = 'Could not find window: %r' % window_name
34 _raise(msg)
35+ else:
36+ try:
37+ window_list = browser.window_handles
38+ if len(window_list) <= index:
39+ msg = 'Index of %r is greater than the number of available windows.' % index
40+ _raise(msg)
41+ _print('Switching to ' + window_list[index] + ' window')
42+ browser.switch_to_window(window_list[index])
43+ except NoSuchWindowException:
44+ msg = 'Could not find window: %r' % window_list[index]
45+ _raise(msg)
46
47
48 def switch_to_frame(index_or_name=None):
49
50=== modified file 'src/sst/selftests/switch_to_window.py'
51--- src/sst/selftests/switch_to_window.py 2011-09-25 20:01:09 +0000
52+++ src/sst/selftests/switch_to_window.py 2011-10-07 20:56:35 +0000
53@@ -5,7 +5,7 @@
54 link_click('popup_link')
55
56 # switch to new window/tab
57-switch_to_window('_NEW_WINDOW')
58+switch_to_window(window_name='_NEW_WINDOW')
59 title_is('Popup Window')
60
61 # switch back to default/main window/tab
62@@ -21,7 +21,15 @@
63 text_is(elem, 'Popup text here')
64
65 # switch back to default/main window/tab
66-switch_to_window('')
67+switch_to_window(window_name='')
68+title_is('The Page Title')
69+
70+# switch to new window/tab using index
71+switch_to_window(index=1)
72+title_is('Popup Window')
73+
74+# switch back to default/main window using index
75+switch_to_window(index=0)
76 title_is('The Page Title')
77
78 # fails when the window name does not exist
79@@ -30,5 +38,8 @@
80 # fails when the window name does not exist
81 fails(switch_to_window, 'not_a_window')
82
83+# fails when the window index does not exist
84+fails(switch_to_window, index=2)
85+
86 # verify we are still back on main window
87 title_is('The Page Title')

Subscribers

People subscribed via source and target branches