<p>I have a set of webdriver.io tests that are run in jenkins. They run against a selenium grid that is managed in k8s by an external company. I would like to have more control over my selenium backend, so I am trying to find a way to set up a selenium backend in my jenkins pipeline. My lack of docker/k8s networking knowledge is holding me back though.</p>

<p>This is rougly how my pipeline looks:</p>

<pre><code>  agent {
    kubernetes {
      defaultContainer 'jnlp'
      yaml """
        apiVersion: v1
        kind: Pod
        spec:
            containers:
              - name: node
                image: node:12.14.1
                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"
        }
      }
    }
  }
}

</code></pre>

<p>What I want is to run my tests against chrome. Any solution that will give me a chrome browser to run against is good. </p>

<p>I have tried to specify an extra container with selenium/standalone-chrome, but I have no idea how to run my tests against that container. I have also read up on setting up a selenium grid using docker containers, but I don't know how to run these commands in this pipeline, and even if this would work, I am not sure how to run against this grid.</p>

<p>Can anyone provide me with an example of what I could do to make this work?</p>

<p>There is 1 approach which is not via Kubernetes.  </p>

<p>Use the below image in which nodejs and chrome both are installed.</p>

<pre><code>  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"
        }
      }
    }
  }
}
</code></pre>

<p>Make sure as part of package.json, <code>selenium-webdriver</code> is part of it.</p>
