在Watin中,如何等待服务器处理完表单?

发布于 2024-12-05 16:00:14 字数 337 浏览 0 评论 0原文

我正在视图中通过 JavaScript 向服务器提交表单,以便启动服务器端作业。视图通过调用 JavaScript 回调来检测作业是否已完成。服务器和客户端之间 JavaScript 通信的确切细节应该超出此问题的范围(我认为),但如果您需要更多详细信息,请告诉我。如果有帮助的话,我正在使用类似 Comet 的 SignalR 库,而不是标准的 Ajax。

现在,我想在 Watin (2.1.0) 中测试这个视图。如何让 Watin 等待服务器端作业完成处理?当它检测到作业已完成时,我是否应该更新视图中的属性?

I'm submitting a form to my server via JavaScript in the view, in order to start a server-side job. The view detects that the job has finished by a JavaScript callback being called. The exact details of the JavaScript communication between server and client should be outside of the scope of this problem (I think), but let me know if you need more details. If it helps, I am using the Comet-like SignalR library, rather than standard Ajax.

Now, I want to test this view in Watin (2.1.0). How can I make Watin wait until the server-side job has finished processing? Should I perhaps update an attribute in the view when it detects the job has finished?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

不忘初心 2024-12-12 16:00:15

取决于你的 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

无论如何,这只是一些提示。这几乎总是很痛苦,所以不要向我展示你的实际代码;)

Depends how your js and html code looks. It's not that simple. Try to use WaitUntil... methods.

Let's say that after job has finished new div elements with id foo appears. To wait for that use this code:

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

But sometimes it's not that simple. Let's say, that after job has finished, the content of the table changes, ie. old rows are removed, and new rows appears. If so:

//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

Anyhow, this is just some tips. It's almost always a pain, so don't show me your actual code ;)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文