Skip to content

add fix for 'No Such Window' error - #394

Merged
just-be-dev merged 3 commits into
robotframework:masterfrom
divfor:Fix-NoSuchWindowException
May 19, 2015
Merged

just-be-dev merged 3 commits into
robotframework:masterfrom
divfor:Fix-NoSuchWindowException

Conversation

@divfor

@divfor divfor commented May 12, 2015

Copy link
Copy Markdown
Contributor

reason:
from 6.4 secotion in http://www.w3.org/TR/webdriver/, it says:
Once the window has closed, future commands must return a status code of
no such window until a new window is selected for receiving commands.
how to fix:

  1. let close_window() automaticly switches to prevoius window;
  2. capture NoSuchWindowException when select_window() /
    _select_matching()/get_current_window_handle()

reason:
from 6.4 secotion in http://www.w3.org/TR/webdriver/, it says:
Once the window has closed, future commands must return a status code of
no such window until a new window is selected for receiving commands.
how to fix:
1. let close_window() automaticly switches to prevoius window;
2. capture NoSuchWindowException when select_window() /
_select_matching()/get_current_window_handle()
@just-be-dev

Copy link
Copy Markdown
Contributor

I also need you to write some tests and update the changelog.

@divfor

divfor commented May 12, 2015

Copy link
Copy Markdown
Contributor Author

should I put the test case in /test/acceptance/open_and_close.txt?

@just-be-dev

Copy link
Copy Markdown
Contributor

Yeah, that sounds good to me.

@divfor

divfor commented May 13, 2015

Copy link
Copy Markdown
Contributor Author

It is very useful to surface window handle to users that want to have the 'correct way' - comparing window handle sets, to switch window. If we do this way, the fix here for 'Close Window' is not required. instead, my new proposal is to update 'Select Window' and add 2 keywords:

Close Window And Switch To | locator=None

This will close current window and then switch to window if locator is given. locator can be name, title, url, handle, ..., the same as 'Select Window' requires.

${previous_window}= | Select Window | locator=None

This will switch to window matching locator and return previous window's handle. locator can be name, title, url, handle of target window, or a handle list to exclude in order to find new window. If locator is 'self', only return current window handle.

${window_list}= | List Windows

This will return a list of all opened window handles in same session not assuming its order.

Above changes should not impact existing usage of 'Close Window' and 'Select Window', and can offer the strict 'correct way' for using handle to switch window.

example 1:
A user should save main window handle in the beginning if required:

Open Browser 
${main_window}= | Select Window | self

A user can switch to correct window like below:

${all_old_windows}= | List Windows
Click Link | xxx | # or any other action that generates a new window
${parent_window}= | Select Window | ${all_old_windows}
Close Window And Switch To | ${parent_window}

Additional proposal:
it is safe to think the first & top level browsing context, the root of tree-order of browsing contexts, will be at index[0] in list-order returned window handles. If a WD session has multiple top level browsing contexts, there will be multiple short lists joined together to form a single big list to return WD's local end, in this case the first top level browsing context will still be at index[0]. So, I think get_window_handles()[0] is safe to switch to 'main' window in current ff/gc/ie browsers. of course, it is not official defined. however, there are still many protocol gaps that are not defined:)

So an additional question is, should we also offer a express way to select the last-position indexed window as new window without the need to comparing with old window set? I guess this will be correct in 99% cases.

${parent_window}= | Select Window | new | #use window list instead 'new' to exclude them if disordered

Keywords right after keyword 'Close Windwo' will fail due to
NoSuchWinowExecption:
1. keyword 'Select Window' with named argument
'name=xxx'/'title=xxx'/'url=xxx', fixed _select_matching() as it calls
get_current_window_handle()
2. keyword 'Get Window Ids/Names/Titles', will fail on
NoSuchWinowExecption, fixed _get_window_infos() as it calls
get_current_window_handle()

Also reversed close_window() (not switching to prevoius window)
@divfor

divfor commented May 14, 2015

Copy link
Copy Markdown
Contributor Author

Anyway this PR should focus on NoSuchWindowException fixing. I raised another PR #395 for improve selecting new window with handles.

I reversed the change for 'Close Window' and only deal with this exception in _get_window_infos() and _select_matching().

I test the PR against my real web server and it works well. however I did not add test code to acceptance test as I can not get its test server started smoothly to pass testing -- tried activepython2.7.8 with chrome/fireforx on win8.1 and winxp...

@just-be-dev

Copy link
Copy Markdown
Contributor

Run python run_tests.py python firefox from the tests directory to run the acceptance tests. I'll need you to add some tests and update the changelog before I can merge.

@divfor

divfor commented May 15, 2015

Copy link
Copy Markdown
Contributor Author

Added two test cases and tested that they reproduce the issues and verify the fix.
Added changelog.

@just-be-dev

Copy link
Copy Markdown
Contributor

Okay, I'm back from vacation so I have a bit of time to review this. I might take a little time though, because I want to test this out myself before merging.

@just-be-dev

Copy link
Copy Markdown
Contributor

Hey @divfor, this looks good to me. I've tested it, verified the failures on master, and verified the working solution. I'm going to go ahead and merge this.

Thanks for your contribution!

just-be-dev added a commit that referenced this pull request May 19, 2015
@just-be-dev
just-be-dev merged commit 7664b8d into robotframework:master May 19, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants