私はWatiNを使用してウェブサイトをテストしています。 Iframeに「レポート」が表示されるページの1つに、このIフレーム内にレポートをダウンロードして保存するリンクがあります。しかし、リンクに到達する唯一の方法はframe.Link(...)を使うことです。ポップアップは開いた直後に閉じます。フレームから開いたポップアップを保持するにはどうすればよいですか?
//以下のコードスニペットは、作成したグラフボタン
ie.Button(Find.ById( "ctl00_ctl00_ContentPlaceHolder1_TopBoxContentPlaceHolder_btnCreateGraphを"))をクリックします)(クリックしてください。
//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);
私はフレームの代わりに、すなわちie.Divがすべて存在する理由を使用しようとしました。 フレームを使用すると、ポップアップウィンドウがすぐに開閉します。 私が使用している場合、つまりリンクが見つかりませんでした。 リンクを手動でクリックすると、テストが「リンクを見つけようとしている」の間にファイルが正しくダウンロードされます。 フレームを持っていない別のページを使用するようにコードを変更しましたが、私はまだ同じ問題をダウンロードポップアップが瞬時に閉じます。
[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()
うまくいけば、いくつかのいずれかは、私が間違ってやっているものを私に伝えることができます。 「:WebTest.CommandLine.WatiNConsoleWebAndDB.TestForMeterDataExport M」 に失敗しました:エラーHRESULT E_FAILから返ってきた。ここ
プログラムは多分それは のTestCaseを助けるハンドルを見つけることができないとき、私は取得エラーですありがとうCOMコンポーネントを呼び出します。 System.Runtime.InteropServices.COMException(0x80004005):エラーHRESULT E_FAILがCOMコンポーネントの呼び出しから返されました。 WatiN.Core.WaitForCompleteBase.DoWaitでWatiN.Core.Native.InternetExplorer.IEWaitForComplete.WaitForCompleteOrTimeout() でWatiN.Core.Native.InternetExplorer.IEBrowser.get_NativeDocument() でSHDocVw.IWebBrowser2.get_Document() で() WatiN.Core.Native.InternetExplorer.AttachToIeHelper.Findで(IEすなわち、SimpleTimerタイマー、ブールwaitForComplete)WatiN.Core.Native.InternetExplorer.AttachToIeHelper.FinishInitializationAndWaitForCompleteでWatiN.Core.DomContainer.WaitForComplete(IWAIT waitForComplete) (で (ブラウザタイプのタイプ、制約の制約、Int32タイムアウトのタイプ) WatiN.Core.Browser.AttachTo(タイプbrowserType、コンストレイン制約、Int32タイムアウト) straint制約)WatiN.Core.Browser.AttachTo [T](制約制約) ウェブ+ DB_test_app.cs(139,0)で :WebTest.CommandLine.WatiNConsoleWebAndDB.TestForMeterDataExport(AT)のためバティストする
コードを正しくフォーマットできますか? –
コードが再フォーマットされました –