Skip to content

Instantly share code, notes, and snippets.

@jerclarke
Created March 8, 2024 16:28

Revisions

  1. jerclarke renamed this gist Mar 8, 2024. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  2. jerclarke created this gist Mar 8, 2024.
    42 changes: 42 additions & 0 deletions gistfile1.txt
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,42 @@
    <?php

    # Helper methods to add to the acceptance tester class ($I)

    /**
    * Run this before submitting a form/clicking link when we want to check the page reloaded later
    *
    * Sets a JS var that we can check later to know that the page
    * has reloaded
    *
    * @param AcceptanceTester $I
    * @return void
    */
    public function gvAmOnPageBeforeReload(\AcceptanceTester $I) {

    $I->waitForJS('return document.oldPage = "yes"');
    }

    /**
    * Run this after submitting form/clicking link to confirm page has reloaded
    *
    * @param AcceptanceTester $I
    * @return void
    */
    public function gvAmOnPageAfterReload(\AcceptanceTester $I) {

    $I->waitForJS('return document.oldPage !== "yes"');
    }

    # Example usage in a test helper method:

    public function _gvUserProfileUpdateEmail(AcceptanceTester $I, string $email) {

    $I->fillField(['name' => 'email'], $email);
    $I->scrollTo("#wpfooter");

    $I->gvAmOnPageBeforeReload($I);
    $I->click('Update User');
    $I->gvAmOnPageAfterReload($I);

    $I->seeInField('email', $email);
    }