如何使用GitLab CI设置Selenium E2E测试?

问题描述 投票:6回答:1

我正在为网站前端开发一个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?

unit-testing selenium docker gitlab-ci e2e-testing
1个回答
0
投票

CI脚本:

package.json:

测试:e2e:无头:“vue-cli-service test:e2e --config ./tests/e2e/main-test/nightwatch.conf.js --env chromeHeadless”

“依赖”:{“chromedriver”:“2.46.0”,“selenium-server”:“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'                                                                           

           ]                                                                                        
        }                                                                                          
       }                                                                                            
      }

0
投票

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

为此,您应该使用像repo的README中描述的gitlab-selenium-server之类的东西。

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

© www.soinside.com 2019 - 2024. All rights reserved.