Collectives™ on Stack Overflow
Find centralized, trusted content and collaborate around the technologies you use most.
Learn more about Collectives
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
Learn more about Teams
I'm trying to use the Coded UI Test to control an web application (which I don't have soruce code for) to generate input data for my application (filling in a form etc).
At a certain point, the web app opens a new windows, and the process of filling in continues in this new browser windows. The trouble is that I cant seem to get the UI test code to "move" or discover that a new window is open. It searches for the next item in the old windows, and therefore does not find it.
Is there a way to "move focus" to the newly opened browser window?
Using VS 2010, IE9
This reply may be a little late but I've had some success with the following approach:
Inspired by a PluralSight course on Selenium with CodedUI, I created a class called Browser which features a public, static instance of the
BrowserWindow
object. In that class I have an Initialize() method which assigns my static BrowserWindow instance the value of
BrowserWindow.Launch("yourUrlHere")
. When I click on a link that opens in a new window and I have to "switch focus" to the new window, I just reassign my static BrowserWindow object the value of
BrowserWindow.Locate("windowTitleGoesHere")
. Now if I have to search for an element on the page with the browser window as my search context, I always have the correct browser window. When that window closes, I simply reassign my static BrowserWindow object back to the main window using the BrowserWindow.Locate("windowTitleGoesHere") method.
So, all you need:
1) keep track of open IE windows (you may find them by title, HWND etc.)
2) store these windows as a couple of
BrowserWindow
variables.
3) search for all the controls like that:
HtmlHyperLink hl = new HtmlHyperLink(window2);
// rest of specification
4) you get your controls in the window you need
You will need some changes to your tests if you use recorder (we write out tests and UIMaps from scratch because recorder generates low-quality code).
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.