简体   繁体   English

如何让WebDriver等到Sencha AJAX调用完成?

[英]How to have WebDriver wait until Sencha AJAX call is complete?

I have a page I am testing with Selenium WebDriver. 我有一个用Selenium WebDriver测试的页面。

The underlying page uses the Sencha JavaScript library. 底层页面使用Sencha JavaScript库。 I have an issue where during my test, I enter a value in a field, then there is an AJAX call that validates that field. 我有一个问题,在我的测试中,我在一个字段中输入一个值,然后有一个AJAX调用验证该字段。 If it is valid, nothing on the page changes. 如果有效,则页面上的任何内容都不会更改。 The field would get highlighted in red if the value was invalid. 如果值无效,该字段将以红色突出显示。

The problem is that my script tries to leave the page before this call is complete. 问题是我的脚本在此调用完成之前尝试离开页面。 I know I could just have it wait an explicit amount of time, but that is rarely a good idea. 我知道我可以让它等待一段时间,但这不是一个好主意。

Currently, I have these options set for my driver (this is Java. timeout is 120): 目前,我为我的驱动程序设置了这些选项(这是Java。超时为120):

int timeout = 120;
driver.manage().timeouts().implicitlyWait(timeout, TimeUnit.SECONDS);
driver.manage().timeouts().setScriptTimeout(timeout, TimeUnit.SECONDS);
driver.manage().timeouts().pageLoadTimeout(timeout, TimeUnit.SECONDS);

I know I can wait for jQuery AJAX calls more or less like this: 我知道我可以或多或少地等待jQuery AJAX调用:

JavascriptExecutor executer = (JavascriptExecutor) driver;
Boolean jqueryDone = (Boolean) executer.executeScript("return jQuery.active == 0");

and wrap a Wait around that condition. 并包裹等待那个条件。

Is there an equivalent check I can make against Sencha/ExtJS? 我可以对Sencha / ExtJS进行同等检查吗?

Ah ha! 啊哈! Found it. 找到了。 To wait until an AJAX call is complete when the site uses ExtJS check the following javascript function: 要等到网站使用ExtJS时AJAX调用完成,请检查以下javascript函数:

return Ext.Ajax.isLoading();

It will be false when all AJAX calls have finished. 所有AJAX调用完成后都将为false。 So, then my code becomes: 那么,我的代码变成了:

JavascriptExecutor executer = (JavascriptExecutor) driver;
Boolean ajaxRunning = ((Boolean) executer.executeScript("return Ext.Ajax.isLoading();"));

Maybe pretty hacky, but maybe also worth consideration. 也许很hacky,但也许值得考虑。 You said, the only feedback the user gets is the mouse cursor changing to 'busy' state during the ajax request and then changing back to 'normal'. 你说,用户获得的唯一反馈是在ajax请求期间鼠标光标变为“忙”状态,然后再变回“正常”。

Maybe that's enough for testing. 也许这足以进行测试。 You can try to get the current pointer value using JavaScript and wait until it turns from auto , to wait (after initiating the request) and back to auto (when done) auto is default, maybe you have something different set by default. 您可以尝试使用JavaScript获取当前指针值,并等待它从auto变为wait (在启动请求之后)并返回auto (完成时)auto是默认值,也许你默认设置不同的东西。

You can retrieve the value with: 您可以使用以下方法检索值:

window.getComputedStyle(document.body).cursor

Example: http://jsfiddle.net/2fVDP/ 示例: http//jsfiddle.net/2fVDP/

Maybe it's not the whole body that gets the cursor style applied. 也许不是整个身体都应用了光标样式。 You have to adjust the dom node then. 你必须调整dom节点。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM