Commit 05c4c086 authored by Pierre Smeyers's avatar Pierre Smeyers
Browse files

feat: add hook scripts support

parent 129aed02
Loading
Loading
Loading
Loading
+7 −0
Original line number Diff line number Diff line
@@ -103,6 +103,13 @@ or through a basic `environment_url.txt` file, then the Robot Framework test wil
:warning: all our deployment templates implement this design. Therefore even purely dynamic environments (such as review
environments) will automatically be propagated to your Robot Framework tests.

### Hook scripts

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

* `pre-robot.sh` is executed **before** running Robot Framework,
* `post-robot.sh` is executed **after** running Robot Framework (whichever the tests status).

### How to manage Robot Framework tests in a separate GitLab repository

This template can obviously be used in an application repository that also embeds the Robot Framework test scripts.
+22 −1
Original line number Diff line number Diff line
@@ -389,6 +389,20 @@ 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
  }

  function robot_cli() {
    eval_base_url
@@ -447,7 +461,14 @@ robotframework:
  stage: acceptance
  script:
    - mkdir -p -m 777 reports
    - robot_cli $ROBOT_OPTIONS --variable BROWSER:${ROBOT_BROWSER} --outputdir reports/ --xunit robotframework.xunit.xml $ROBOT_TESTS_DIR
    # maybe execute pre hook
    - maybe_exec_hook "./pre-robot.sh"
    # run tests
    - robot_cli $ROBOT_OPTIONS --variable BROWSER:${ROBOT_BROWSER} --outputdir reports/ --xunit robotframework.xunit.xml $ROBOT_TESTS_DIR || rc=$?
    # maybe execute post hook
    - maybe_exec_hook "./post-robot.sh"
    # exit with return code
    - exit $rc
  artifacts:
    name: "$CI_JOB_NAME artifacts from $CI_PROJECT_NAME on $CI_COMMIT_REF_SLUG"
    expire_in: 1 day