4
votes

I am working on a project to build, test and deploy an application to the cloud using a .gitlab-ci.yml

1) Build the backend and frontend using pip install and npm install

build_backend:
  image: python
  stage: build
  script:
  - pip install requirements.txt
  artifacts:
    paths:
      - backend/

build_frontend:
  image: node
  stage: build
  script:
  - npm install
  - npm run build
  artifacts:
    paths:
      - frontend

2) Run unit and functional tests using PyUnit and Python Selenium

test_unit:
  image: python
  stage: test
  script:
    - python -m unittest discover

test_functional:
  image: python
  stage: test
  services:
    - selenium/standalone-chrome
  script:
    - python tests/example.py http://selenium__standalone-chrome:4444/wd/hub https://$CI_BUILD_REF_SLUG-dot-$GAE_PROJECT.appspot.com

3) Deploy to Google Cloud using the sdk

deploy:
  image: google/cloud-sdk
  stage: deploy
  environment:
    name: $CI_BUILD_REF_NAME
    url: https://$CI_BUILD_REF_SLUG-dot-$GAE_PROJECT.appspot.com
  script:
    - echo $GAE_KEY > /tmp/gae_key.json
    - gcloud config set project $GAE_PROJECT
    - gcloud auth activate-service-account --key-file /tmp/gae_key.json
    - gcloud --quiet app deploy --version $CI_BUILD_REF_SLUG --no-promote
  after_script:
    - rm /tmp/gae_key.json

This all runs perfectly, except for the selenium tests are run on the deployed url not the current build:

python tests/example.py http://selenium__standalone-chrome:4444/wd/hub https://$CI_BUILD_REF_SLUG-dot-$GAE_PROJECT.appspot.com

I need to have gitlab run three things simultaneously: a) Selenium b) Python server with the application - Test script

Possible approaches to run the python server:

  • Run within the same terminal commands as the test script somehow
  • Docker in Docker
  • Service

Any advice, or answers would be greatly appreciated!

1
I am also trying to run selenium tests on Gitlab ci. Can you please let me know if you configured selenium tests to run in interactive mode or using headless browsers?Sakshi Singla
At the moment I've left selenium on its default configurationKim T

1 Answers

0
votes

I wrote a blog post on how I set up web tests for a php application. Ok PHP, but I guess something similar can be done for a python project.

What I did, was starting a php development server from within the container that runs the web tests. Because of the artifacts, the development server can access the php files. I figure out the IP address of the container, and using this IP address the selenium/standalone-chrome container can connect back to the development server.

I created a simple demo-project, you can check out the .gitlab-ci.yml file. Note that I pinned the selenium container to an old version; this was because of an issue with an old version of the php webdriver package, today this isn't needed anymore.