7

I am developing a Vue.js app for a website frontend.

For this app I would like to use Unit and E2E tests. I built my project with vue-cli.

From my understanding, vue-cli uses Karma for unit tests and Nightwatch + Selenium for E2E tests.

My .gitlab-ci.yml looks like the following:

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 runs e2e and unit tests and works on local computers. The Unit tests run smoothly and the Selenium brings up a Chrome window and uses the E2E tests.

The problem is that don't know how to run E2E Selenium tests on GitLab CI. It keeps giving me an error saying:

Could not connect to Selenium Server. Have you started the Selenium Server yet?, although it says two lines before that it has already created a Selenium server.

How can I run E2E Selenium tests on GitLab CI? If this is not achievable, what kind of E2E can I run on GitLab CI?

josealeixo.pc
  • 391
  • 3
  • 13
  • 1
    Just commenting on this question after all this time to let you know how I did it. I don't remember very well, but I know I eventually figured out that the problem was that Selenium was **not** bringing up the browser in **headless mode**. From what I remember, setting this mode somewhere would solve the problem. However, I eventually used the `claasaug/vue-cli-webpack-e2e-in-gitlab-ci` image from Docker Hub, which had everything I needed. Sorry for not giving a more straightforward answer, but I completely forgot about this thread. – josealeixo.pc Mar 19 '19 at 21:57

2 Answers2

0

You have to bring Selenium yourself to your pipeline in order to use it.

To do so, you should use something like gitlab-selenium-server as it is described in the repo's README.

Another option is to use a GitLab CI service as described in this blog post.

Kalle Richter
  • 8,008
  • 26
  • 77
  • 177
ZedTuX
  • 2,859
  • 3
  • 28
  • 58
0

CI script:

package.json :

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

“dependencies”: { “chromedriver”: “2.46.0”, “selenium-server”: “3.9.0” }

nightwatch config :

  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'                                                                           

           ]                                                                                        
        }                                                                                          
       }                                                                                            
      }