2011-01-13 2 views
0

私は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)のためバティストする

+1

コードを正しくフォーマットできますか? –

+0

コードが再フォーマットされました –

答えて

1

おかげポインタ。

//は、すべての作業は、ローカルホスト上で実行される場合にのみ動作します楽しみのために今の名前として

 FileDownloadHandler handler = new FileDownloadHandler("MeterUsageReport_Large_Iframe.xls"); 

     // add a watcher to look for the save file local 

     ie.AddDialogHandler(handler); 

     //Do not close dialog boxes immediately 

     ie.DialogWatcher.CloseUnhandledDialogs = false; 

     //create a single use instance that will be easily cleaned up and avoid having windows open after we are done with them 

     using (new UseDialogOnce(ie.DialogWatcher, handler)) 

     { 
      //Now click export 

      frame.Link(Find.ById("rvReport_ctl01_ctl05_ctl01")).ClickNoWait(); 

      //Grab hold of the poup dialog and download the file    
      handler.WaitUntilFileDownloadDialogIsHandled(30); 
      handler.WaitUntilDownloadCompleted(35); 
     } 

保存ハンドルとファイルを設定します。 ローカルではないサーバーにアクセスする必要がある場合は、 を使用します。2)ダウンロードしたファイルとIframeのスクリプトを許可するために、信頼できるサイトのセキュリティを編集する必要があります。 * a)open IE * b)ツール - >インターネットオプション * c)[セキュリティ]タブ。 * d)「信頼できるサイト」が強調表示されていることを確認してください * e)カスタムレベルをクリックし、すべての.Netおよび.Net依存コンポーネントが有効に設定されていることを確認します。 * f)すべてのアクティブXコンポーネントを有効またはプロンプトにする * g)すべてのダウンロードを有効にする * h).Netフレームワークセットアップを有効にする * i)Webブラウザコントロールのスクリプトを有効にする * j)アドレスまたはステータスなしでウィンドウを開くことを許可するバー。 * k)Iframeからプログラムまたはファイルを起動できます。 * l)スクリプトの下のすべてが有効またはプロンプトに設定されています。 * localhostは "低い"セキュリティ領域として扱われるため、localhost上で実行されるテストではこれらの変更は必要ありません。 * http://support.microsoft.com/kb/174360

関連する問題