2011-09-22 56 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