Тесты Codecept JS запускаются в Jenkins еще до того, как Selenium Server запущен и доступен - PullRequest
0 голосов
/ 16 января 2020

Я использую Codecept JS и Selenium Standalone server (для Firefox) для запуска моих тестов. Я также интегрировал Docker, и вот мой docker -композитный файл, который определяет зависимости:

version: '2'
services:
    codeceptjs:
        image: codeception/codeceptjs
        depends_on:
            - web
            - firefox
        environment:
            - CODECEPT_ARGS=--debug
        volumes:
            - .:/tests
    web:
        image: node
        command: node app/server.js
        volumes:
            - .:/app
    firefox:
        image: selenium/standalone-firefox:3.12.0-americium
        ports:
            - '4444'
            - '5900'

В моем файле Jenkins я просто запускаю 'docker -compose up', и он работает локально на моем компьютере, но во время работы на Jenkins тесты выполняются до запуска сервера Selenium.

Мой вывод Jenkins выглядит следующим образом:

    Creating automation-tests-content-client_web_1 ...  
    15:32:10  Creating automation-tests-content-client_firefox_1 ...  
    15:32:10  [2A[2K Creating automation-tests-content-client_web_1     ... [32mdone[0m [2B[1A[2K Creating automation-tests-content-client_firefox_1 ... [32mdone[0m [1BCreating automation-tests-content-client_codeceptjs_1 ...  
    15:32:11  [1A[2K Creating automation-tests-content-client_codeceptjs_1 ... [32mdone[0m [1BAttaching to automation-tests-content-client_web_1, automation-tests-content-client_firefox_1, automation-tests-content-client_codeceptjs_1 
    15:32:11  [36mautomation-tests-content-client_web_1 |[0m internal/modules/cjs/loader.js:964 15:32:11  [36mautomation-tests-content-client_web_1 |[0m     throw err; 
    15:32:11  [36mautomation-tests-content-client_web_1 |[0m     ^ 
    15:32:11  [36mautomation-tests-content-client_web_1 |[0m  
    15:32:11  [36mautomation-tests-content-client_web_1 |[0m Error: Cannot find module '/app/server.js' 
    15:32:11  [36mautomation-tests-content-client_web_1 |[0m     at Function.Module._resolveFilename (internal/modules/cjs/loader.js:961:17) 
    15:32:11  [36mautomation-tests-content-client_web_1 |[0m     at Function.Module._load (internal/modules/cjs/loader.js:854:27) 15:32:11 [36mautomation-tests-content-client_web_1 |[0m     at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:71:12) 
    15:32:11  [36mautomation-tests-content-client_web_1 |[0m     at internal/main/run_main_module.js:17:47 { 
    15:32:11  [36mautomation-tests-content-client_web_1 |[0m   code: 'MODULE_NOT_FOUND', 
    15:32:11  [36mautomation-tests-content-client_web_1 |[0m   requireStack: [] 
    15:32:11  [36mautomation-tests-content-client_web_1 |[0m } 
    15:32:12  [36mautomation-tests-content-client_web_1 exited with code 1 
    15:32:12 [0m[32mautomation-tests-content-client_codeceptjs_1 |[0m CodeceptJS directory has been found. 
    15:32:13  [32mautomation-tests-content-client_codeceptjs_1 |[0m creating output directory: /tests/output 
    15:32:13  [32mautomation-tests-content-client_codeceptjs_1 |[0m CodeceptJS v2.3.6 
    15:32:13  [32mautomation-tests-content-client_codeceptjs_1 |[0m Using test root "/tests" 15:32:13  [32mautomation-tests-content-client_codeceptjs_1 |[0m Helpers: WebDriver 
    15:32:13  [32mautomation-tests-content-client_codeceptjs_1 |[0m Plugins: screenshotOnFail 15:32:13  [32mautomation-tests-content-client_codeceptjs_1 |[0m  
    15:32:13  [32mautomation-tests-content-client_codeceptjs_1 |[0m Content App -- 
    15:32:13  [32mautomation-tests-content-client_codeceptjs_1 |[0m   In order to boost my profile online
    15:32:13  [32mautomation-tests-content-client_codeceptjs_1 |[0m   As a Hotelier 
    15:32:13  [32mautomation-tests-content-client_codeceptjs_1 |[0m   I want to be able to update my hotel info via the Microservices App 
    15:32:13  [32mautomation-tests-content-client_codeceptjs_1 |[0m   
    Leaving required fields throw an error 
    15:32:13  [32mautomation-tests-content-client_codeceptjs_1 |[0m    ✖ "before each" hook: codeceptjs.before for "Leaving required fields throw an error" in 79ms 
    15:32:13  [32mautomation-tests-content-client_codeceptjs_1 |[0m Error: Can't connect to WebDriver. 
    15:32:13  [32mautomation-tests-content-client_codeceptjs_1 |[0m Error: Failed to create session. 
    15:32:13  [32mautomation-tests-content-client_codeceptjs_1 |[0m Unable to connect to "172.18.0.3:4444", make sure browser driver is running on that address. 
    15:32:13  [32mautomation-tests-content-client_codeceptjs_1 |[0m If you use services like chromedriver see initialiseServices logs above or in wdio.log file. 
    15:32:13  [32mautomation-tests-content-client_codeceptjs_1 |[0m  
    15:32:13  [32mautomation-tests-content-client_codeceptjs_1 |[0m Please make sure Selenium Server (ChromeDriver or PhantomJS) is running and accessible 
    15:32:13  [32mautomation-tests-content-client_codeceptjs_1 |[0m  
    15:32:13  [32mautomation-tests-content-client_codeceptjs_1 |[0m -- FAILURES: 
    15:32:13  [32mautomation-tests-content-client_codeceptjs_1 |[0m  
    15:32:13  [32mautomation-tests-content-client_codeceptjs_1 |[0m   1) Content App 
    15:32:13  [32mautomation-tests-content-client_codeceptjs_1 |[0m  "before each" hook: codeceptjs.before for "Leaving required fields throw an error": 
    15:32:13  [32mautomation-tests-content-client_codeceptjs_1 |[0m      Can't connect to WebDriver. 
    15:32:13  [32mautomation-tests-content-client_codeceptjs_1 |[0m Error: Failed to create session. 
    15:32:13  [32mautomation-tests-content-client_codeceptjs_1 |[0m Unable to connect to "172.18.0.3:4444", make sure browser driver is running on that address. 
    15:32:13  [32mautomation-tests-content-client_codeceptjs_1 |[0m If you use services like chromedriver see initialiseServices logs above or in wdio.log file. 
    15:32:13  [32mautomation-tests-content-client_codeceptjs_1 |[0m 
    15:32:13  [32mautomation-tests-content-client_codeceptjs_1 |[0m Please make sure Selenium Server (ChromeDriver or PhantomJS) is running and accessible 
    15:32:13  [32mautomation-tests-content-client_codeceptjs_1 |[0m   
    15:32:13  [32mautomation-tests-content-client_codeceptjs_1 |[0m   Run with --verbose flag to see NodeJS stacktrace 
    15:32:13  [32mautomation-tests-content-client_codeceptjs_1 |[0m 
    15:32:13  [32mautomation-tests-content-client_codeceptjs_1 |[0m  
    15:32:13  [32mautomation-tests-content-client_codeceptjs_1 |[0m   FAIL  | 0 passed, 1 failed   // 91ms 
    15:32:14  [32mautomation-tests-content-client_codeceptjs_1 exited with code 1 
    15:32:21  [0m[33mautomation-tests-content-client_firefox_1 |[0m 14:32:21.414 INFO [GridLauncherV3.launch] - Selenium build info: version: '3.12.0', revision: '7c6e0b3' 
    15:32:21  [33mautomation-tests-content-client_firefox_1 |[0m 14:32:21.451 INFO [GridLauncherV3$1.launch] - Launching a standalone Selenium Server on port 4444 
    15:32:22  [33mautomation-tests-content-client_firefox_1 |[0m 2019-12-11 14:32:22.216:INFO::main: Logging initialized @7349ms to org.seleniumhq.jetty9.util.log.StdErrLog 
    15:32:26  [33mautomation-tests-content-client_firefox_1 |[0m 14:32:26.437 INFO [SeleniumServer.boot] - Selenium Server is up and running on port 4444

Как вы можете видеть, тесты получают запустить до запуска сервера и, следовательно, он не работает. Это происходит потому, что образ Codecept JS извлекается до того, как образ firefox запущен и работает. Есть ли способ, как я могу решить эту проблему? Может быть, заставить мои тесты ждать, пока сервер не будет?

...