【问题标题】:In Watin, how to wait until a form has been processed by the server?在 Watin 中,如何等待服务器处理完表单?
【发布时间】:2011-09-22 19:11:52
【问题描述】:

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

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

【问题讨论】:

    标签: c# jquery ajax watin


    【解决方案1】:

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

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

    【讨论】:

    • 我做了一些类似于你概述的事情。完成后向元素添加了一个属性,我等待 Watin。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-06-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-05-05
    • 2022-01-15
    相关资源
    最近更新 更多