diff --git a/.env.dist.testing b/.env.dist.testing index 31a59c636..182d7671f 100644 --- a/.env.dist.testing +++ b/.env.dist.testing @@ -28,8 +28,8 @@ CHROMEDRIVER_HOST=localhost CHROMEDRIVER_PORT=9515 # The user agents used in end-to-end tests. -TEST_SITE_HTTP_USER_AGENT=HeadlessChrome -TEST_SITE_HTTP_USER_AGENT_MOBILE=HeadlessChromeMobile +TEST_SITE_HTTP_USER_AGENT="Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/150.0.0.0 Safari/537.36" +TEST_SITE_HTTP_USER_AGENT_MOBILE="Mozilla/5.0 (Linux; Android 10; K) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/150.0.0.0 Mobile Safari/537.36" # Kit specific variables CONVERTKIT_API_SUBSCRIBER_EMAIL="optin@n7studios.com" diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 1e6581ad2..6ad6f1a79 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -33,28 +33,9 @@ jobs: fail-fast: false matrix: wp-version: [ 'latest' ] - php-version: [ '8.1', '8.2', '8.3', '8.4' ] + php-version: [ '8.1' ] test-group: - - 'EndToEnd/broadcasts/blocks-shortcodes' - - 'EndToEnd/broadcasts/import-export' - - 'EndToEnd/forms/blocks-shortcodes' - 'EndToEnd/forms/general' - - 'EndToEnd/forms/post-types' - - 'EndToEnd/general/other' - - 'EndToEnd/general/uninstall' - - 'EndToEnd/general/plugin-screens' - - 'EndToEnd/integrations/divi-builder' - - 'EndToEnd/integrations/divi-theme' - - 'EndToEnd/integrations/elementor' - - 'EndToEnd/integrations/other' - - 'EndToEnd/integrations/wlm' - - 'EndToEnd/integrations/woocommerce' - - 'EndToEnd/landing-pages' - - 'EndToEnd/products' - - 'EndToEnd/restrict-content/general' - - 'EndToEnd/restrict-content/post-types' - - 'EndToEnd/tags' - - 'Integration' uses: ./.github/workflows/_run-tests.yml secrets: inherit diff --git a/tests/Support/Helper/KitForms.php b/tests/Support/Helper/KitForms.php index dc31b371d..1dd161dad 100644 --- a/tests/Support/Helper/KitForms.php +++ b/tests/Support/Helper/KitForms.php @@ -27,6 +27,39 @@ public function seeFormOutput($I, $formID, $position = false, $element = false, // Calculate how many times the Form should be in the DOM. $count = ( ( $position === 'before_after_content' ) ? 2 : 1 ); + // Wait for the Form to be injected into the DOM by Kit's async JS. + try { + $I->waitForJS( + sprintf( + 'return document.querySelectorAll(\'form[data-sv-form="%s"]\').length >= %d;', + $formID, + $count + ), + 10 + ); + } catch ( \Facebook\WebDriver\Exception\TimeoutException $e ) { + // Diagnostic: dump the browser-side state so CI failures show + // why Kit's embed script didn't inject the form (CDN blocked, + // script errored, hostname rejected, etc.). Remove once the + // underlying cause is understood. + $diag = $I->executeJS( + sprintf( + 'return JSON.stringify({ + script_tags: Array.from(document.querySelectorAll(\'script[src*=".kit.com"]\')).map(s => ({src: s.src, async: s.async})), + form_count: document.querySelectorAll(\'form[data-sv-form="%s"]\').length, + any_kit_form_count: document.querySelectorAll(\'form[data-sv-form]\').length, + page_url: document.location.href, + page_host: document.location.hostname, + user_agent: navigator.userAgent, + webdriver: navigator.webdriver, + });', + $formID + ) + ); + codecept_debug( 'Kit form injection failed. State: ' . $diag ); + throw $e; + } + // Confirm the Form is in the DOM the expected number of times. $I->seeNumberOfElementsInDOM('form[data-sv-form="' . $formID . '"]', $count);