在詹金斯管道中创建硒后端

Mar*_*ijn 5 selenium docker webdriver-io kubernetes jenkins-pipeline

我有一组在 jenkins 中运行的 webdriver.io 测试。它们运行在由外部公司在 k8s 中管理的 selenium 网格上。我想对我的 selenium 后端有更多的控制,所以我试图找到一种方法来在我的 jenkins 管道中设置一个 selenium 后端。不过,我缺乏 docker/k8s 网络知识让我望而却步。

这大概是我的管道的样子:

  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"
        }
      }
    }
  }
}

Run Code Online (Sandbox Code Playgroud)

我想要的是针对 chrome 运行我的测试。任何能让我运行 chrome 浏览器的解决方案都很好。

我试图用 selenium/standalone-chrome 指定一个额外的容器,但我不知道如何针对该容器运行我的测试。我还阅读了有关使用 docker 容器设置 selenium 网格的文章,但我不知道如何在此管道中运行这些命令,即使这可行,我也不知道如何针对此网格运行。

谁能给我提供一个我可以做些什么来完成这项工作的例子?

nis*_*yal 2

有 1 种方法不通过 Kubernetes。

使用下图,其中安装了nodejs和chrome。

  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"
        }
      }
    }
  }
}
Run Code Online (Sandbox Code Playgroud)

确保 as 是 package.json 的一部分,selenium-webdriver是其中的一部分。