Oh, I get it now. Yeah, this is a problem with LTAF right now.
One work around is to use the new popup window support to have your pages run in their own window instead of inside LTAF's frame. You can accomplish this by writting something like this in your test code:
[WebTestMethod]
public void AutomaticPopup()
{
// navigate to some page so that you can run scripts
HtmlPage p = new HtmlPage("SomeRandomPageInYourSite.htm");
// execute a script that opens a new window that loads your real site
p.ExecuteScript("function openWindow() { window.open('../TheRealPage.htm'); return true;} openWindow();");
// get the popupwindow and automate against it.
HtmlPage newPage = p.GetPopupWindow(1);
Assert.AreEqual("This is the page", newPage.Elements.Find("body", 0).GetInnerText());
}
Although I verified that this works, it is far from optimal because you don't want each test to open a new window. However, if this approach works for you, one thing that we could do is add a feature to LTAF where all your tests run on the new window. What
this would do is before start running any tests, it will automatically create a popup window by the technique that I showed here, and all your tests will run against that window instead (the test code will look the same).
farmas
Participant
1164 Points
259 Posts
Microsoft
Re: Using LTAF to automate a page with frames.
Apr 20, 2009 06:37 PM|LINK
Oh, I get it now. Yeah, this is a problem with LTAF right now.
One work around is to use the new popup window support to have your pages run in their own window instead of inside LTAF's frame. You can accomplish this by writting something like this in your test code:
[WebTestMethod] public void AutomaticPopup() { // navigate to some page so that you can run scripts HtmlPage p = new HtmlPage("SomeRandomPageInYourSite.htm"); // execute a script that opens a new window that loads your real site p.ExecuteScript("function openWindow() { window.open('../TheRealPage.htm'); return true;} openWindow();"); // get the popupwindow and automate against it. HtmlPage newPage = p.GetPopupWindow(1); Assert.AreEqual("This is the page", newPage.Elements.Find("body", 0).GetInnerText()); }Although I verified that this works, it is far from optimal because you don't want each test to open a new window. However, if this approach works for you, one thing that we could do is add a feature to LTAF where all your tests run on the new window. What this would do is before start running any tests, it will automatically create a popup window by the technique that I showed here, and all your tests will run against that window instead (the test code will look the same).
Let me know what you think,
Federico