Coming from testGenerateCoupons, this line that waits for the batch to finish:

    $this->getSession()->wait(180000, 'jQuery("#updateprogress").length === 0');

The error:

Drupal\Tests\commerce_promotion\FunctionalJavascript\CouponTest::testGenerateCoupons
    Zumba\GastonJS\Exception\JavascriptError: One or more errors were raised in
    the Javascript code on the page.
                If you don't care about these errors, you can ignore them
    by
                setting js_errors: false in your Poltergeist configuration (see
    documentation for details).
    ReferenceError: Can't find variable: jQuery
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

bojanz created an issue. See original summary.

bojanz’s picture

According to lendude, we need to replace that line with $this->checkForMetaRefresh();

EDIT: Even though core uses it, it didn't work here. Also tried to replace the whole form submit with:

$this->submitForm(['quantity' => (string) $coupon_quantity], t('Generate'));

cause submitForm() calls checkForMetaRefresh() internally, but no change. The last HTML output I see is the batch itself, all next assertions fail.

mglaman’s picture

Per ReferenceError: Can't find variable: jQuery is part of the problem invalid library definitions?

lisastreeter’s picture

Sorry about the bad line in the coupon test code. FunctionalJavascript tests aren't currently working for me, so I can't try this. But maybe something like this could work:

$this->assertSession()->waitForElement('xpath', '//table/tbody/tr/td');

I see it being used in core FunctionalJavascript tests for testing Ajax. Not sure if it could work for batches.

Lendude’s picture

I think (ok, know) we are lacking javascript + batch coverage in core, so there might not be a known way of handling this currently.

The simplest thing I see here, is just not making these tests javascript tests. They are not testing anything javascripty anyway. When converted to a browsertest, checkForMetaRefresh() works as advertised (well locally for me anyway).

Status: Needs review » Needs work

The last submitted patch, 5: 2952849-5.patch, failed testing. View results

mglaman’s picture

Status: Needs work » Needs review
mglaman’s picture

Seems solid, ran a bunch of custom tests.

Lendude’s picture

Bit of a clean up, removes an unused use and move the test to the Functional dir since it's no longer a javascript test.

  • bojanz committed 2e6f969 on 8.x-2.x authored by Lendude
    Issue #2952849 by Lendude: Random test fail in Drupal\Tests\...
bojanz’s picture

Status: Needs review » Fixed

Thank you! Greatly appreciated.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.

juampynr’s picture

I experienced this kind of errors a few months ago with JavaScript tests. When I tried to do the same test with https://www.drupal.org/project/drupalextension, it worked consistently. Perhaps it's worth it to give that a go.