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

2023-12-29

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

对于这个应用程序,我想使用单元测试和端到端测试。我用以下方式构建了我的项目vue-cli https://github.com/vuejs/vue-cli.

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

My .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?


CI脚本:

  • npm 安装 wget
  • https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb
  • apt install -y ./google-chrome-stable_current_amd64.deb apt-get
  • 安装-y默认jdk
  • npm 运行测试:e2e:无头

包.json:

测试:e2e:headless :“vue-cli-service测试: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'                                                                           

           ]                                                                                        
        }                                                                                          
       }                                                                                            
      }
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

如何使用 GitLab CI 设置 Selenium E2E 测试? 的相关文章

随机推荐