Zombie.js pressButton Long Callback Delay [英] Zombie.js pressButton Long Callback Delay
问题描述
我一直试图通过使用一堆console.log来解决这个问题,但仍然无法弄清楚为什么这些加载时间太长。
I've been trying to figure this out by using a bunch of console.logs and still can't figure out why these load times are so long.
所以我在我的Mocha单元测试文件中的 beforeEach
中有以下代码。
So I have the following code in my beforeEach
in my Mocha unit test file.
browser.fill('email', 'test1@test.com');
browser.fill('password', 'testtest');
browser.pressButton('Login').then(function () {
console.log("#100 - "+ new Date().getTime());
done();
});
在这种情况下按下按钮会有一些重定向,最后会显示一个仪表板页面。在该html文件的底部,我有以下代码。
Pressing the button in this case will have a few redirects then finally display a dashboard page. At the bottom of that html file I have the following code.
<script>
$(document).ready(function () {
console.log("#200 - "+ new Date().getTime());
});
</script>
所以在运行测试后如果我在#100之后取值
减去 #200
之后的值总是大约5000-6000。因为#200
总是在#100
之前打印5-6秒。
So after running the tests if I take the value after #100
minus the value after #200
it's always about 5000-6000. Because #200
always gets printed before #100
by like 5-6 seconds.
我不明白为什么在加载页面后,Zombie.js需要额外的5-6秒才能调用该回调函数。
I don't understand why after loading the page it takes an additional 5-6 seconds about for Zombie.js to call that callback function.
Zombie.js在加载页面后是否有一些等待或延迟?还有什么可能导致页面加载和Zombie.js之间的5-6秒延迟调用该回调函数?
Does Zombie.js have some wait or delay that I'm missing after loading the page? What else could be causing this 5-6 second delay between the page loading and Zombie.js calling that callback function?
编辑我现在有同样的问题,但像50000ms。在我的所有测试中,这真的非常快。我仍然无法弄清楚为什么会发生这种情况。
EDIT I now have this same problem but with like a 50000ms. And that really adds up super quickly over all of my tests. I still can't figure out why this is happening.
编辑2
如果我将 browser.debug()
添加到我的测试中,它会在最后打印以下内容。它还会打印很多其他内容,但这种情况很快就会发生。我认为以下可能是问题所在。只是不确定它为什么这样做或如何解决它。
If I add browser.debug()
to my test it prints the following at the very end. It also prints a lot of other stuff but that happens overall pretty quickly. I think the following might be the problem. Just not sure why it's doing that or how to fix it.
zombie Fired setInterval every 5000ms +11ms
zombie Fired setInterval every 5000ms +5s
zombie Fired setInterval every 5000ms +5s
zombie Fired setInterval every 5000ms +5s
zombie Fired setInterval every 5000ms +5s
zombie Fired setInterval every 5000ms +5s
zombie Fired setInterval every 5000ms +5s
zombie Fired setInterval every 5000ms +5s
zombie Fired setInterval every 5000ms +5s
zombie Fired setInterval every 5000ms +5s
zombie Fired setInterval every 5000ms +5s
导致所有 zombie每隔5000ms触发setInterval的原因是什么
以及如何修复它以使其不需要55000ms +?
What is causing all of the zombie Fired setInterval every 5000ms
and how do I fix it to make it not take 55000ms+?
编辑3
我还在单元测试开始时添加了以下代码。
I also added the following code at the beginning of the unit test.
browser.addListener("setInterval",function (a,b) {
console.log("a: "+a);
console.log("b: "+b);
});
打印每个 zombie Fired setInterval每5000ms + 5s
由于该监听器,它还会打印以下内容。
After printing each zombie Fired setInterval every 5000ms +5s
it also prints the following because of that listener.
a: function (){var b,c,d;if(b=window.location.href,b!==h){try{d=JSON.stringify({action:"ping",sid:a.utils.getSessionID(),muid:a.utils.getMerchantID(),referrer:h,url:b,title:document.title}),e.contentWindow.postMessage(d,"*")}catch(f){c=f}return h=b}}
b: 5000
a
和 zombie Fired setInterval每隔5000毫米
后,> b 相同。它在这11次之间根本没有变化。
a
and b
are the same after each one of those 11 zombie Fired setInterval every 5000ms
. It doesn't change at all between those 11 times.
我认为这个功能在某种程度上会有所帮助,但我仍然不明白为什么会发生这种情况或如何修复它完全没有。
I thought that function would help in someway but I still don't understand why this is happening or how to fix it at all.
推荐答案
Zombie在触发回调之前加载所有资源并处理所有事件。不要使用 pressButton ,请尝试直接提交表单并使用等待并使用终结器回调,该回调将在每个事件后调用。这应该会告诉你导致延迟的原因:
Zombie loads all resources and processes all events before triggering the callback. Instead of using pressButton, try submitting the form directly and using wait with a terminator callback which will be called after each event. This should show you what's causing the delay:
browser.document.forms[0].submit();
browser.wait(function(){
//called after each event
}, function() {
//all events processed
});
来自API文档:
browser.wait(回调)
browser.wait(终结者,回调)
处理队列中的所有事件并在完成后调用回调。
Process all events in the queue and calls the callback when done.
您可以使用秒表单在处理所有
事件之前传递控件。终结符可以是数字,在这种情况下,处理许多事件
。它可以是函数,在每个事件之后调用;当函数返回值false时,
处理停止。
You can use the second form to pass control before processing all events. The terminator can be a number, in which case that many events are processed. It can be a function, which is called after each event; processing stops when the function returns the value false.
这篇关于Zombie.js pressButton Long Callback Delay的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!