Capture the two window handles for use #8

Merged
merged 1 commit into from May 21, 2012

Projects

None yet

2 participants

@zacc
Contributor
zacc commented May 16, 2012

Capture the two window handles while looping through them to find the browserID window.

Make the signin use window handle rather than the zls window name. This is required because OperaDriver overwrites the window.name and thus it can not be targeted reliably.

@davehunt davehunt and 1 other commented on an outdated diff May 16, 2012
pages/webdriver/base.py
@@ -12,8 +12,13 @@ class Base(object):
def __init__(self, selenium, timeout=60):
self.selenium = selenium
self.timeout = timeout
- if selenium.title != self._page_title:
- for handle in selenium.window_handles:
- selenium.switch_to_window(handle)
- if selenium.title == self._page_title:
- break
+
+ handle_list = selenium.window_handles
+
+ for handle in handle_list:
+ selenium.switch_to_window(handle)
+ if selenium.title == self._page_title:
+ self.bid_window_handle = handle
+ handle_list.remove(handle)
+ self.main_window_handle = handle_list[0]
davehunt
davehunt May 16, 2012 Member

Why are you removing the popup window handle? Also, why not set self.main_window_handle outside the for loop?

zacc
zacc May 16, 2012 Contributor

There are two windows in the handle_list (disregarding a case where there might be more than 2 windows open but we haven't had this yet) so I remove the one that I know is the popup window and then I am left with the main window's handle.

I can't think of another way to do it aside from passing in the main window's handle before clicking the 'Personas' button on whatever the main site is. Which would certainly be a safer way to know exactly what the main window handle is but it would make the bidpom integration a bit painful.

zacc
zacc May 16, 2012 Contributor

erm yes, that would be far better :)

zacc
zacc May 16, 2012 Contributor

Actually that doesn't really help because the existing logic is there to protect against assuming the popup window is the top one. if I put in current_window_handle before that loop then I make that assumption aswell.

I am thinking now that I should add a comment in here for future users.

davehunt
davehunt May 16, 2012 Member

Not sure I follow you? Before you switch to the popup you store the handle, then use that to switch back. There's no assumptions here afaict.

zacc
zacc May 16, 2012 Contributor

Gotcha now.. fixed it up.

@davehunt davehunt and 1 other commented on an outdated diff May 16, 2012
pages/webdriver/sign_in.py
@@ -55,7 +55,7 @@ def click_next(self):
def click_sign_in(self):
"""Clicks the 'Sign In' button."""
self.selenium.find_element(*self._sign_in_locator).click()
- self.selenium.switch_to_window('')
+ self.selenium.switch_to_window(self.main_window_handle)
davehunt
davehunt May 16, 2012 Member

Could we add a method to the base page that returns to the main window? That way we can make main_window_handle private.

zacc
zacc May 16, 2012 Contributor

Yes let's do that.

Member

I wasn't able to replicate the issue with Opera (I was getting earlier unrelated issues), but I like this improvement, and it runs fine with Firefox, so let's get it merged. @zacc could you please rebase so that this is a single commit. Thanks.

Zac Capture the two window handles for use
move switch_to_main_window into a separate method of base.py

change to use current_window_handle

fix muppetry
35db833
Contributor
zacc commented May 21, 2012

Squashed the commit history.

Member

Thanks @zacc

@davehunt davehunt merged commit 29318f8 into mozilla:master May 21, 2012
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment