Create a selenium backend in a jenkins pipeline
There is 1 approach which is not via Kubernetes.
Use the below image in which nodejs and chrome both are installed.
agent { kubernetes { defaultContainer 'jnlp' yaml """ apiVersion: v1 kind: Pod spec: containers: - name: node-chrome image: larcado/nodejs-chrome command: - cat tty: true """ } } stages { stage('Checkout codebase') { // do checkout } } stage('Build') { steps { container('node') { sh ''' npm install --production ''' } } } stage('Test-Mocha') { steps { container('node') { sh "node_modules/.bin/wdio ./test/config/wdio.conf.js --spec ./test/helpers/sandBox/sandbox1.js" } } } }}
Make sure as part of package.json, selenium-webdriver
is part of it.
There are a couple of ways to do it.
1. Using Selenium Grid (Ideal way) - Below are the steps:
- Host a separate selenium Grid using the below docker-compose file.
version: '2'services: firefox: image: selenium/node-firefox:3.14.0-gallium volumes: - /dev/shm:/dev/shm depends_on: - hub environment: HUB_HOST: hub chrome: image: selenium/node-chrome:3.14.0-gallium volumes: - /dev/shm:/dev/shm depends_on: - hub environment: HUB_HOST: hub hub: image: selenium/hub:3.14.0-gallium ports: - "4444:4444"
Execute the
docker-compose up -d
command to start the Selenium Grid which is running localhost:4444Once this grid is running, please generate the wdio config which be used to run against a grid.
- After config is generated, run your pipeline by using the pipeline which you mentioned in your question, which will run against the Selenium Grid
Note:- Use the new wdio
config which you generated to use against the selenium grid.
Hope this helps.