Geb测试通过Chrome,但通过PhantomJS失败 [英] Geb tests pass with Chrome, fail with PhantomJS

查看:87
本文介绍了Geb测试通过Chrome,但通过PhantomJS失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我注意到,某些Geb功能测试在Chrome上通过了,但在PhantomJS上却保持了所有其他变量不变的情况下失败了.这种情况大多发生在具有某种异步活动的页面上-一次调用$(selector).click()会触发事件处理程序,该事件处理程序将更新DOM,并且DOM更新需要在调用$(anotherSelector).click()之前完成.

I have noticed that some Geb functional tests pass with Chrome but fail with PhantomJS, holding all other variables constant. This happens mostly with pages that have some kind of asynchronous activity - one call to $(selector).click() triggers an event handler that updates the DOM, and the DOM updates need to complete before calling $(anotherSelector).click().

我可以通过积极地使用waitFor使PhantomJS测试再次通过,但我不明白为什么PhantomJS GhostDriver而不是Chrome驱动程序会要求这样做.

I can make the PhantomJS tests pass again by aggressively using waitFor but I don't understand why this would be required with the PhantomJS GhostDriver and not the Chrome driver.

不幸的是,我还无法构造一个最小的测试用例,但仍与我的应用程序隔离.

Unfortunately I haven't been able to construct a minimal test case yet isolated from my application.

推荐答案

我唯一拥有的建议是始终确保测试中围绕异步活动的任何操作均受waitFor语句保护.您可以避免以下问题:一个驱动程序足够快地完成异步活动,然后您的测试才尝试访问页面中的新元素/修改过的元素,而其他驱动程序则不能.当您开始在通常较慢的CI上运行测试时,在异步活动周围不使用waitFor也会使您感到痛苦,因为它们会在被测试页面中看到更多与异步性相关的失败.

The only advice I can have is to always make sure that any actions in your tests around asynchronous activities are guarded with waitFor statements. You will avoid problems where one driver is quick enough to finish the asynchronous activity before your test tries to access the new/modified element in your page but other isn't. Not using waitFor around asynchronous activities will also bite you when you start running your tests on CI where they are usually slower and you'll see more failures related to asynchronicity in tested pages.

我也不会考虑使用waitFor来保护测试中的每个异步活动都具有攻击性.您必须记住,waitFor会定期轮询条件,并在条件满足后立即继续-因此,如果您的浏览器运行速度很快,并且页面在waitFor首次轮询之前得到更新,那么您不会受到速度的影响-明智的做法是,但如果不是这样,则可以保证重试以查看是否已完成该异步操作并且该条件已得到满足.我发现激进的方法是使用30毫秒这样的高超时,而绝对不需要这些超时-这只是意味着,如果您的测试失败,它将花费很长时间.

I also wouldn't consider using waitFor to guard every asynchronous activity in your test as being aggressive. You have to remember that waitFor periodically polls the condition and continues as soon as the condition is fulfilled - so if your browser is quick and the page gets updated before waitFor polls for the first time then you're not penalized speed-wise at all but if it's not then you have a guarantee that there will be a retry to see if the asynch action has finished and the condition was fulfilled. What I find aggressive is using ridiculously high timeouts like 30s where they definitely aren't needed - it just means that if your test fail it will take very long time for it to happen.

这篇关于Geb测试通过Chrome,但通过PhantomJS失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆