質問

I am using Watin 2.1 to try to test file download and file open functionality for a website. This worked well in Internet Explorer 8, but since Internet Explorer 9 there is a yellow-white download bar at the bottom of the view instead of a popup dialog window.

I found this answer: https://stackoverflow.com/a/8532222/246622, which solves that problem, as long as the browser tab that I am interested in is on top. If there are other tabs that are on top, it cannot not find the download bar. The problem here is that these tests will open other tabs on top of the tab with the download bar, before the download starts.

So, how do I access the correct tab, or how do I switch the top/visible tab in internet explorer, or how do I get those other pages to open in other windows instead of in tabs in the same window, or how do I close those other tabs from my test application?

Here is the relevant piece of code:

Window windowMain = new Window(WatiN.Core.Native.Windows.NativeMethods.GetWindow(browser.hWnd, 5/*GW_CHILD*/)); // This gets the topmost browser tab.
System.Windows.Automation.TreeWalker trw = new System.Windows.Automation.TreeWalker(System.Windows.Automation.Condition.TrueCondition);
mainWindow = trw.GetParent(System.Windows.Automation.AutomationElement.FromHandle(browser.hWnd));
windowDialog = new Window(WatiN.Core.Native.Windows.NativeMethods.GetWindow(windowMain.Hwnd, 5));

I tried this:

var lowerWindow = new Window(WatiN.Core.Native.Windows.NativeMethods.GetWindow(aBrowserTab.Hwnd, 2/*GW_HWNDNEXT*/)); // This gets a next lower window.

I was then planning on identifying the correct tab using a regex with the title:

titleRegex.IsMatch(windowMain.ToplevelWindow.Title)

but this gets a lower window instead of a lower tab in the same window.

役に立ちましたか?

解決

I had a similar problem and after investigations similar to what you are trying I decided to try alternative routes. Also note that even if you do get it right like this, you'll have a lot of work to port your tests on other browsers and IE 10 is coming out fast.

  1. Do you really need to download the file from the browser? How about - read the URL that triggers the download and then do a WebRequest on that URL to retrieve your file?

  2. Look at using Coded UI - not the recorded tests but the generated ones. They are able to automate clicking on window apps as well as within the browser. Also note that development does seem to have stopped on waitn so it might make sense to move to something more reliable.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top