Selenium on Circle CI 2

selenium

#1

Did anyone manage to get a firefox/chrome container working with Circle CI 2?

I tried multiple images from Docker Hub but they all fail to connect… and without any debugging capabilities I am kind of lost


#2

I used WDIO without any issues:


#3

Thanks Alex, but that’s on Circle 1. I’m having issued with Circle 2 :slight_smile:


#4

I have gotten Selenium running on 2.0.

This is my Dockerfile:

FROM buildpack-deps:jessie

RUN groupadd --gid 1000 node \
  && useradd --uid 1000 --gid node --shell /bin/bash --create-home node

# gpg keys listed at https://github.com/nodejs/node
RUN set -ex \
  && for key in \
    9554F04D7259F04124DE6B476D5A82AC7E37093B \
    94AE36675C464D64BAFA68DD7434390BDBE9B9C5 \
    0034A06D9D9B0064CE8ADF6BF1747F4AD2306D93 \
    FD3A5288F042B6850C66B31F09FE44734EB7990E \
    71DCFD284A79C3B38668286BC97EC7A07EDE3FC1 \
    DD8F2338BAE7501E3DD5AC78C273792F7D83545D \
    B9AE9905FFD7803F25714661B63B535A4C206CA9 \
    C4F0DFFF4E8C1A8236409D08E73BC641CC11F4C8 \
  ; do \
    gpg --keyserver ha.pool.sks-keyservers.net --recv-keys "$key"; \
  done

ENV NPM_CONFIG_LOGLEVEL info
ENV NODE_VERSION 6.6.0

RUN curl -SLO "https://nodejs.org/dist/v$NODE_VERSION/node-v$NODE_VERSION-linux-x64.tar.xz" \
  && curl -SLO "https://nodejs.org/dist/v$NODE_VERSION/SHASUMS256.txt.asc" \
  && gpg --batch --decrypt --output SHASUMS256.txt SHASUMS256.txt.asc \
  && grep " node-v$NODE_VERSION-linux-x64.tar.xz\$" SHASUMS256.txt | sha256sum -c - \
  && tar -xJf "node-v$NODE_VERSION-linux-x64.tar.xz" -C /usr/local --strip-components=1 \
  && rm "node-v$NODE_VERSION-linux-x64.tar.xz" SHASUMS256.txt.asc SHASUMS256.txt \
  && ln -s /usr/local/bin/node /usr/local/bin/nodejs \
  && apt update \
  && apt install -y git ocaml libelf-dev firefox-esr chromedriver xvfb openjdk-7-jdk

RUN npm install -g yarn@0.18.0
ENV PATH "$PATH:/root/.yarn/bin/"

CMD [ "node" ]

This is the relevant bit of circle.yml:

          - type: shell
            name: Start Xvfb
            command: |
              wget http://selenium-release.storage.googleapis.com/2.53/selenium-server-standalone-2.53.1.jar -O selenium-server.jar
              Xvfb :7055
            background: true

#5

In CircleCI 2.0 you can use selenium/standalone images.

Simply add the following to config.yml:

  - image: selenium/standalone-chrome:3.1.0

Current versions for Firefox and Chrome:

Your tests should now run just as they do locally if you’re set up for webdriver / selenium etc.


#6

Worked! Thanks!!


#7

Hi, we’re trying to get Selenium working with Circle 2.0 with python tests but the code doesn’t find the chromedriver or geckodriver executable, complains that it needs to be in PATH.

This is our circle.yml:

version: 2
jobs:
  build:
    working_directory: ~/working
    docker:
      - image: truckfly/python-yarn:latest
        environment:
          DJANGO_SETTINGS_MODULE: truckfly.settings.circle
      - image: postgres:9.4.11
        environment:
          POSTGRES_USER: ubuntu
          POSTGRES_DB: circle_test
          POSTGRES_PASSWORD: ""
      - image: selenium/standalone-chrome:latest
    steps:
      - checkout
      - restore_cache:
          key: dashdoc-venv-{{ checksum "requirements.txt" }}
      - run:
          name: Install pip packages
          command: virtualenv venv; source venv/bin/activate; pip install -r requirements.txt
      - save_cache:
          key: dashdoc-venv-{{ checksum "requirements.txt" }}
          paths:
            - "./venv"
      - restore_cache:
          key: dashdoc-yarn-{{ checksum "yarn.lock" }}
      - run:
          name: Install npm packages
          command: yarn
      - save_cache:
          key: dashdoc-yarn-{{ checksum "yarn.lock" }}
          paths:
            - "~/.yarn-cache"
      - run:
          name: Javascript tests
          command: yarn test
      - run:
          name: Python tests
          command: coverage run manage.py test
      - run:
          name: Code coverage
          command: codecov -t key

Any idea?


#8

I’d use one of our Python based browser images;

https://hub.docker.com/r/circleci/python/tags/

You can extend it and install Yarn.


#9

Hi @rohara, thanks for the response. Using python2.7-browser as the base image yields the same results during tests. Do we still need to have the - image: selenium/standalone-chrome:latest line in the circle.yml? It’s not very clear in the docs how the different containers specified in circle.yml interact. When I SSH into the build I don’t have access to the docker command which makes it even harder to debug things…


#10

I don’t see how that would help you debug your Python app.

No. It’s installed on the container you’re using so there’s no need.

Have you gotten browser testing working elsewhere? With what versions of software?


#11

@rohara thanks for your help, we got it working with the python-2.7-browsers image. Sorry for the latest message, it was an unrelated problem.

The bit about being able to see which containers are up and running on the SSH build was maybe more due to confusion about whether we are running inside the primary container or on the host VM when ssh-ing into the build, and how to locate/access the other docker containers that are running. It’s also that I don’t have much experience with docker…


#12

You SSH into the primary container (the first one listed in the docker bit of the config). The other container logs are accessible from within a given build page.

I hope this helps!


#13

Hi,

I am trying to run tests on 5 browsers (Chrome, Opera, Firefox, Safari, IE) on a docker image, solely so I can run integration tests locally before it runs on circle ci when I push changes over. We are using webdriverio’s testrunner to run our cucumber tests. When I run with Chrome and Safari (in developer mode) locally everything works fine, however, I start getting problems with all browsers when I try to run in docker. There is no debugging with the errors so I’m pretty lost. If any of you are familiar with the use-case I am writing about I would really appreciate some help.


#14

I recommend using one of the browser variants of our CircleCI Images for simplicity.

https://circleci.com/docs/2.0/circleci-images/


#15

Hi @rohara

Thank you for that excellent suggestion! I am using this circleci/node image with tag latest-browsers and getting the folowing error before booting into the container via bash:

ERROR: euid != 0,directory /tmp/.X11-unix will not be created.

Seems to be about graphics driver, probably from chrome, any help in this area?


#16

Just ignore it, it’s irrelevant.


#17

One more thing @rohara, how can I access the Dockerfiles for your pre-built images?


#18

#19

Hi @tom,

What url do you point the browser to then? Let’s say I have a webserver running in my main image on port 80. Do i point the browser to 127.0.0.1:80? localhost?

I can connect to the selenium driver but the browser always crashes on Connection refused when trying to display a page.


#20

Is there a reason your tutorial doesn’t use these https://circleci.com/docs/2.0/project-walkthrough/#install-and-run-selenium-to-automate-browser-testing