【问题标题】:How to setup Selenium E2E testing with GitLab CI?如何使用 GitLab CI 设置 Selenium E2E 测试?
【发布时间】:2018-05-12 13:37:04
【问题描述】:

我正在为网站前端开发一个 Vue.js 应用程序。

对于这个应用程序,我想使用单元和 E2E 测试。我用vue-cli 构建了我的项目。

据我了解,vue-cli 使用 Karma 进行单元测试,使用 Nightwatch + Selenium 进行 E2E 测试。

我的.gitlab-ci.yml 如下所示:

stages:
  - test

test:express:
  image: node:boron
  stage: test
  script:
    - cd backend/
    - npm install --progress=false
    - ./node_modules/.bin/jasmine

test:vue:
  image: node:boron
  stage: test
  script:
    - cd frontend/
    - npm install --progress=false
    - npm test

npm test 运行 e2e 和单元测试并在本地计算机上工作。单元测试运行顺利,Selenium 会打开 Chrome 窗口并使用 E2E 测试。

问题是不知道如何在 GitLab CI 上运行 E2E Selenium 测试。它一直给我一个错误说:

Could not connect to Selenium Server. Have you started the Selenium Server yet?,虽然前面两行说它已经创建了一个 Selenium 服务器。

如何在 GitLab CI 上运行 E2E Selenium 测试?如果这无法实现,我可以在 GitLab CI 上运行哪种 E2E?

【问题讨论】:

  • 这么久了才评论这个问题,让你知道我是怎么做到的。我不太记得了,但我知道我最终发现问题在于 Selenium 没有headless 模式启动浏览器。据我记得,在某处设置此模式可以解决问题。然而,我最终使用了来自 Docker Hub 的 claasaug/vue-cli-webpack-e2e-in-gitlab-ci 镜像,它拥有我需要的一切。很抱歉没有给出更直接的答案,但我完全忘记了这个帖子。

标签: unit-testing selenium docker gitlab-ci e2e-testing


【解决方案1】:

CI 脚本:

package.json:

test:e2e:headless : "vue-cli-service test:e2e --config ./tests/e2e/main-test/nightwatch.conf.js --env chromeHeadless"

“依赖”:{ “chromedriver”:“2.46.0”, “硒服务器”:“3.9.0” }

守夜人配置:

  selenium: {                                                                                      
     start_process: true,                                                                           
     server_path: require('selenium-server').path,                                                  
     port: 4449,                                                                                    
     cli_args: {                                                                                    
       'webdriver.chrome.driver': require('chromedriver').path                                      
     }                                                                                              
   },                                                                                               

   test_settings: {                                                                                 
     default: {                                                                                     
       selenium_port: 4449,                                                                         
       selenium_host: 'localhost',                                                                  
       silent: true,                                                                                
       globals: {                                                                                   
         devServerURL: 'http://localhost:' + config.devServer.port                                  
       }                                                                                            
     },                                                                                             
     chromeHeadless: {                                                                              
       desiredCapabilities: {                                                                       
         browserName: 'chromeHeadless',                                                             
         javascriptEnabled: true,                                                                   
         acceptSslCerts: true,                                                                      
         chromeOptions: {                                                                           
           args: [                                                                                  
             'headless',                                                                            
             'disable-gpu',                                                                         
             'no-sandbox'                                                                           

           ]                                                                                        
        }                                                                                          
       }                                                                                            
      }

【讨论】:

    【解决方案2】:

    您必须自己将 Selenium 带入管道才能使用它。

    为此,您应该使用类似 gitlab-selenium-server 的内容,如 repo 的自述文件中所述。

    另一种选择是使用 this blog post 中所述的 GitLab CI 服务。

    【讨论】:

      猜你喜欢
      • 2021-05-10
      • 2016-05-05
      • 2019-01-04
      • 1970-01-01
      • 1970-01-01
      • 2017-05-25
      • 2023-01-03
      • 2017-03-03
      • 2022-11-10
      相关资源
      最近更新 更多