Я тестирую сайт с помощью WatiN.На одной из страниц я получаю «отчет» в Iframe, в этом фрейме I есть ссылка для загрузки и сохранения отчета.Но поскольку единственный способ получить ссылку - использовать frame.Link (...), всплывающее окно закрывается сразу после открытия;Фрагмент кода ниже
// Нажмите кнопку создания графика
ie.Button (Find.ById ("ctl00_ctl00_ContentPlaceHolder1_TopBoxContentPlaceHolder_btnCreateGraph")). Click ();
//Lets export the data
ie.Div(Find.ById("colorbox"));
ie.Div(Find.ById("cboxContent"));
ie.Div(Find.ById("cboxLoadedContent"));
Thread.Sleep(1000);//Used to cover performance issues
Frame frame = ie.Frame(Find.ByName(frameNameRegex));
for (int Count = 0; Count < 10000000; Count++) {double nothing = (Count/12); }//Do nothing I just need a short pause
//SelectList waits for a postback which does not occur.
try
{
frame.SelectList(Find.ById("rvReport_ctl01_ctl05_ctl00")).SelectByValue("Excel");
}
catch (Exception)
{
//Do nothing
}
//Now click export
frame.Link(Find.ById("rvReport_ctl01_ctl05_ctl01")).ClickNoWait();
IE ieNewBrowserWindow = IE.AttachTo<IE>(Find.ByUrl(urlRegex));
fileDownloadHandler.WaitUntilFileDownloadDialogIsHandled(150);
fileDownloadHandler.WaitUntilDownloadCompleted(200);
1007попытался использовать ie вместо кадра, поэтому все эти ie .iviv присутствуют.если я использую рамку, всплывающее окно открывается и закрывается мгновенно.Если я использую, т.е. я получаю ссылку не найдена ошибка.Если я нажму на ссылку вручную, пока тест "пытается найти ссылку", файл будет загружен правильно.Я изменил код, чтобы использовать другую страницу, у которой нет фрейма, и у меня по-прежнему возникает та же проблема: всплывающее окно загрузки мгновенно закрывается.
[STAThread]
public void TestForMeterDataExport()
{
// Open a new Internet Explorer window and
// goto the website.
IE ie = new IE("https://<URL>", true);
FileDownloadHandler fileDownloadHandler = new FileDownloadHandler("C:\\Documents and Settings\\karnold\\Desktop\\MeterUsageReport_Large.xls");
Regex urlRegex = new Regex("<URL>\\?Mode=true&ReportID=[a-z A-Z 0-9]{30,33}&ControlID=[a-z A-Z 0-9]{30,33}&Culture=1033&UICulture=1033&ReportStack=1&OpType=Export&FileName=BuildingMeterDataReport&ContentDisposition=OnlyHtmlInline&Format=Excel");
//Find the Username text field and input the user ID
ie.TextField(Find.ByName("ctl00$ContentPlaceHolder1$txtUsername")).TypeText("<Name>");
//Find the Password text field and input the password
ie.TextField(Find.ByName("ctl00$ContentPlaceHolder1$txtPassword")).TypeText("PASS");
//Go ahead and login
ie.Button(Find.ByName("ctl00$ContentPlaceHolder1$butLogin")).Click();
//Let's use the Reports Tab
ie.Link(Find.ByUrl("https://<URL>")).Click();
// Let's get the meter data
ie.Link(Find.ByUrl("https://<URL>")).Click();
//Let's choose University of
ie.SelectList(Find.ById("ctl00_ctl00_ctl00_ContentPlaceHolder1_TopBoxContentPlaceHolder_TopBoxContentPlaceHolder_ucFacility_ddlFacility")).SelectByValue("5041");
//Set the date range for which we want to get data
ie.TextField(Find.ById("ctl00_ctl00_ctl00_ContentPlaceHolder1_TopBoxContentPlaceHolder_TopBoxContentPlaceHolder_DateRangePicker1_dpBeginDate_TextBox")).TypeText("12/09/10");
ie.TextField(Find.ById("ctl00_ctl00_ctl00_ContentPlaceHolder1_TopBoxContentPlaceHolder_TopBoxContentPlaceHolder_DateRangePicker1_dpEndDate_TextBox")).TypeText("12/10/10");
//Click the create report button
ie.Button(Find.ById("ctl00_ctl00_ctl00_ContentPlaceHolder1_TopBoxContentPlaceHolder_TopBoxContentPlaceHolder_btnSubmit")).ClickNoWait();
//Lets export the data
Thread.Sleep(2000);
//SelectList waits for a postback which does not occur.
try
{
ie.SelectList(Find.ById("ctl00_ctl00_ctl00_ContentPlaceHolder1_ContentAreaContentPlaceHolder_ContentAreaContentPlaceHolder_rvMain_ctl01_ctl05_ctl00")).SelectByValue("Excel");
}
catch (Exception)
{
ie.SelectList(Find.ById("ctl00_ctl00_ctl00_ContentPlaceHolder1_ContentAreaContentPlaceHolder_ContentAreaContentPlaceHolder_rvMain_ctl01_ctl05_ctl00")).FireEventNoWait("onchange");
//fire the postback event
}
//Now click export
ie.Link(Find.ById("ctl00_ctl00_ctl00_ContentPlaceHolder1_ContentAreaContentPlaceHolder_ContentAreaContentPlaceHolder_rvMain_ctl01_ctl05_ctl01")).ClickNoWait();
IE ieNewBrowserWindow = IE.AttachTo<IE>(Find.ByUrl(urlRegex));
fileDownloadHandler.WaitUntilFileDownloadDialogIsHandled(10);
fileDownloadHandler.WaitUntilDownloadCompleted(20);
}// close TestForMeterDataExport()
Надеюсь, некоторыеможно сказать мне, что я делаю не так.Спасибо
Вот ошибка, которую я получаю, когда программа не может найти дескриптор, возможно, она поможет TestCase 'M: WebTest.CommandLine.WatiNConsoleWebAndDB.TestForMeterDataExport' не удалось: ошибка HRESULT E_FAIL была возвращена извызов к компоненту COM.System.Runtime.InteropServices.COMException (0x80004005): Ошибка HRESULT E_FAIL была возвращена после вызова компонента COM.в SHDocVw.IWebBrowser2.get_Document () в WatiN.Core.Native.InternetExplorer.IEBrowser.get_NativeDocument () в WatiN.Core.Native.InternetExplorer.IEWaitForComplete.WaitForCompleteOrTitAWateW (WB)..DomContainer.WaitForComplete (IWait waitForComplete) в WatiN.Core.Native.InternetExplorer.AttachToIeHelper.FinishInitializationAndWaitForComplete (т.е.waitForComplete) в WatiN.Core.Browser.AttachTo (введите browserType, ограничение Constraint, Int32 timeout) в WatiN.Core.Browser.AttachTo (введите browserType, ограничение Constraint) в WatiN.Core.Browser.AttachTo [T] (ограничение)Web + DB_test_app.cs (139,0): на WebTest.CommandLine.WatiNConsoleWebAndDB.TestForMeterDataExport ()