Commit 6a4673fb authored by Pierre Smeyers's avatar Pierre Smeyers
Browse files

feat: add hook scripts support

parent cd024ee1
Loading
Loading
Loading
Loading
+7 −0
Original line number Diff line number Diff line
@@ -86,3 +86,10 @@ export default defineConfig({
  },
});
```

### Hook scripts

The Playwright template supports _optional_ **hook scripts** from your project, located in the `$PLAYWRIGHT_PROJECT_DIR` directory to perform additional project-specific logic:

* `pre-playwright.sh` is executed **before** running Playwright,
* `post-playwright.sh` is executed **after** running Playwright (whichever the tests status).
+23 −1
Original line number Diff line number Diff line
@@ -346,6 +346,21 @@ stages:
    done
  }

  function maybe_exec_hook() {
    if [[ -f "$1" ]]
    then
      log_info "\\e[33;1m$1\\e[0m hook found: execute"
      if [[ ! -x "$1" ]] && ! chmod +x "$1"
      then
        log_warn "... could not make \\e[33;1m${1}\\e[0m executable: please do it (chmod +x)"
        # fallback technique
        sh "$1"
      else
        "$1"
      fi
    fi
  }

  # retrieve server url to test from upstream artifacts ($environment_url variable or 'environment_url.txt' file)
  function eval_env_url() {
    # shellcheck disable=SC2154
@@ -393,7 +408,14 @@ playwright:
    - maybe_install_deps
  script:
    - mkdir -p -m 777 reports
    - PLAYWRIGHT_JUNIT_OUTPUT_NAME=reports/playwright.xunit.xml npx playwright test ${TRACE+--debug} --reporter=junit $PLAYWRIGHT_EXTRA_ARGS
    # maybe execute pre hook
    - maybe_exec_hook "./pre-playwright.sh"
    # run tests
    - PLAYWRIGHT_JUNIT_OUTPUT_NAME=reports/playwright.xunit.xml npx playwright test ${TRACE+--debug} --reporter=junit $PLAYWRIGHT_EXTRA_ARGS || rc=$?
    # maybe execute post hook
    - maybe_exec_hook "./post-playwright.sh"
    # exit with return code
    - exit $rc
  artifacts:
    name: "$CI_JOB_NAME artifacts from $CI_PROJECT_NAME on $CI_COMMIT_REF_SLUG"
    when: always