2011-09-22 30 views
2

我在視圖中通過JavaScript提交表單到我的服務器,以啓動一個服務器端的工作。該視圖通過調用JavaScript回調來檢測作業已完成。服務器和客戶端之間的JavaScript通信的具體細節應該是外面這個問題(我認爲)的範圍,但讓我知道,如果你需要更多的細節。如果有幫助,我使用的是彗星般SignalR庫,而不是標準的AJAX。在Watin中,如何等待服務器處理完表單?

現在,我想測試在華廷這種觀點(2.1.0)。如何讓Watin等待服務器端作業完成處理?我應該在檢測到作業完成時更新視圖中的屬性嗎?

回答

3

取決於你的JS和HTML代碼的外觀。這並不簡單。嘗試使用WaitUntil...方法。

比方說,工作後已完成與ID foo出現新的div元素。要等待使用此代碼:

ie.Div("foo").WaitUntilExists(); 

但有時並非如此簡單。比方說,在工作完成後,表格的內容會發生變化,即。舊行被刪除,並出現新行。如果是這樣的話:

//Get cell reference 
var cell = ie.Table("bar").OwnTableRow(Find.First()).OwnTableCell(Find.First()); 
var cellRef = cell.GetJavascriptElementReference(); 

//Change text of that cell using javascript. jQuery could be used if it's used on that page 
//If you are 100% sure, that something will change, just assign cell.Text to text. If so, you don't even 
//need cellRef 
var text = "Dummy text or random or whatever"; 
ie.RunScript(cellRef + ".childNodes[0].nodeValue = '" + text + "'"); 

//TODO: 
//Do something here to fire ajax request 

//Wait until table will be updated, ie. wait until first cell will not contains assigned dummy text. 
//This could be done in many ways. 
ie.Table("bar").WaitUntil(t => t.OwnTableRow(Find.First()).OwnTableCell(Find.First()).Text != text); 
//or just: 
//cell.WaitUntil(c => c.Text != text), but maybe it will not work in your case 

無論如何,這只是一些提示。它幾乎總是一個痛苦,所以不要告訴我你的實際代碼;)

+0

我做了類似於你概述的內容。完成後向元素添加屬性,我等着Watin。 – aknuds1