PF 4.0 Selenium Tests - waitUntilAjaxRequestCompletes broken

UI Components for JSF
Post Reply
derrjukg
Posts: 1
Joined: 07 Oct 2013, 11:18

07 Oct 2013, 12:01

Hello

I'm running PF 4.0 with MyFaces 2.1.12 on a JBoss 7.2.0.

In my Selenium web tests I usually want to wait until my Ajax requests complete before making assertions. For this, I've been using the waitUntilAjaxRequestCompletes from the PF showcase.
This worked fine on 3.5, but after the upgrade to 4.0 waitUntilAjaxRequestCompletes returns immediately, causing my tests to fail.

Looking at the function I figured it's using $.active to figure if any requests are still running. To look at this value, I ran the following from my chromium and Firefox console:

Code: Select all

setInterval( 
  function(){ 
    console.log($.active) 
  }, 
  2
)
When doing nothing, this fills my console with 0's, as no requests are running. Then I tried interacting with an Ajax element (I tested an asynchronous dialog and a DataTable filter).
On PF3.5, the setInterval outputs some 1's into my console
On PF4.0, the setInterval outputs no 1's at all, which obviously makes the waitUntilAjaxRequestCompletes function return immediately.

Do you have an idea how to get the wait working again? Or is there a different approach, apart from Thread.sleep?

Thanks for your time.

drodil
Posts: 5
Joined: 30 Sep 2013, 14:17

07 Oct 2013, 13:38

We are facing exactly the same problem. Also global Ajax Event Handlers (http://api.jquery.com/category/ajax/glo ... -handlers/) from custom javascript are not working anymore. Wondering if using 'selenium.browserbot.getCurrentWindow().$.active==0' can help with the problem.. Doubt it but worth trying.

twinj
Posts: 6
Joined: 18 Oct 2013, 03:50

18 Oct 2013, 04:00

I can recreate this issue - prior versions of PF return the $.active 1 during ajax calls whereas 0 is returned from PF 4. I understand the JQuery used has changed to 1.10 maybe the problem lies there? I am also using selenium driven tests using the Geb framework. The wait call is fundamentally the same.

twinj
Posts: 6
Joined: 18 Oct 2013, 03:50

21 Oct 2013, 01:00

Temporary solution:

Run this on each page before any ajax calls!

Code: Select all

$.ajaxPrefilter(function( options ) {    options.global = true;});
Hope it works for you.

Tekener
Posts: 4
Joined: 18 Oct 2013, 11:38

29 Oct 2013, 09:43

twinj wrote:Temporary solution:

Run this on each page before any ajax calls!

Code: Select all

$.ajaxPrefilter(function( options ) {    options.global = true;});
Hope it works for you.
It worked like a charm - Thank you!

User avatar
Oleg
Expert Member
Posts: 3805
Joined: 02 Oct 2009, 09:41
Location: Germany, Black Forest

29 Oct 2013, 12:47

We are facing exactly the same problem. Also global Ajax Event Handlers (http://api.jquery.com/category/ajax/glo ... -handlers/) from custom javascript are not working anymore.
That's true. PrimeFaces has an own global AJAX Event Handler now. Don't use this one from jQuery. You can look into blockUI.js to see how the new global AJAX Event Handler works.
PrimeFaces Cookbook (2. edition): http://ova2.github.io/primefaces-cookbook/ Learning Angular UI Development with PrimeNG: https://github.com/ova2/angular-develop ... th-primeng Blog: https://medium.com/@OlegVaraksin

twinj
Posts: 6
Joined: 18 Oct 2013, 03:50

04 Feb 2014, 06:30

A more suitable function for testing.

Code: Select all

return ! window.PrimeFaces.ajax.Queue.isEmpty();

sbb_user
Posts: 1
Joined: 31 Mar 2014, 11:27

21 Aug 2014, 11:16

Hi guys,

I run into the same problem... Could you please guide me where should I put this code in my Unit-Test?

Code: Select all

$.ajaxPrefilter(function( options ) {    options.global = true;});

twinj
Posts: 6
Joined: 18 Oct 2013, 03:50

12 Sep 2014, 02:14

sbb_user wrote:Hi guys,

I run into the same problem... Could you please guide me where should I put this code in my Unit-Test?

Code: Select all

$.ajaxPrefilter(function( options ) {    options.global = true;});
Don't. It is not the best fix for this problem.

Use this javascript to test and if you need to wait wrap it in a loop.

Code: Select all

function PFAjaxActive() {
    return ! window.PrimeFaces.ajax.Queue.isEmpty();
}
I do not use selenium directly so please refer to the link below to run javascripts

http://www.mkyong.com/selenium/how-to-e ... webdriver/

Post Reply

Return to “PrimeFaces”

  • Information
  • Who is online

    Users browsing this forum: No registered users and 66 guests