2017-03-06 106 views
6

我試圖在使用Selenium Hub的Docker中使用nightwatchjs寫並行測試。我能夠在沒有Selenium Hub的情況下在Docker中並行運行測試,但是,一些子進程會超時導致多次重試。結果非常不一致。我希望使用Selenium Hub或類似的東西來刪除超時和重試,以便測試結果更加一致,穩定並且不超時。nightwatchjs並行模式selenium hub docker撰寫

但是,現在當我運行docker-compose run --rm nightwatch時,使用以下代碼,selenium服務器將以並行模式啓動並啓動多個子進程,但只有第一個子進程會執行。然後,其他子進程將得到Error retrieving a new session from the selenium server. Connection refused! Is selenium server started?我是否錯過了一些東西,讓nightwatchjs測試在沒有超時的情況下平行運行?

nightwatch.conf.js

module.exports = { 
    src_folders: ['tests'], 
    output_folder: 'reports', 
    custom_commands_path: '', 
    custom_assertions_path: '', 
    page_objects_path: 'page_objects', 
    test_workers: true, 
    live_output: true, 
    detailed_output: true, 

    selenium: { 
    start_process: true, 
    server_path: './bin/selenium-server-standalone-3.0.1.jar', 
    log_path: '', 
    host: '127.0.0.1', 
    port: 4444, 
    cli_args: { 
     'webdriver.chrome.driver' : './node_modules/chromedriver/bin/chromedriver' 
    } 
    }, 

    test_settings: { 
    default: { 
    launch_url: 'https://example.com', 
    selenium_port: 4444, 
    selenium_host: 'hub', 
    silent: true, 
    screenshots: { 
     'enabled': false, 
     'path': '' 
    }, 
    desiredCapabilities: { 
     browserName: 'chrome', 
     javascriptEnabled: true, 
     acceptSslCerts: true, 
     chromeOptions: { 
     args: [ 
      '--window-size=1024,768', 
      '--no-sandbox' 
     ] 
     } 
    }, 
    globals: { 
     waitForConditionTimeout: 20000, 
     asyncHookTimeout: 70000 
    } 
    } 
}; 

搬運工-compose.yml

version: '2' 

services: 
    nightwatch: 
    build: 
     context: . 
    command: /bin/sh -c "node ./node_modules/nightwatch/bin/nightwatch" 
    links: 
     - chrome 
     - hub 
    volumes: 
     - .:/opt/nightwatch 
    chrome: 
    environment: 
     VIRTUAL_HOST: node.chrome.docker 
     HUB_PORT_4444_TCP_ADDR: hub 
     HUB_PORT_4444_TCP_PORT: 4444 
    image: selenium/node-chrome:3.1.0-astatine 
    links: 
     - hub 
    hub: 
    ports: 
     - 4444:4444 
    image: selenium/hub:3.1.0-astatine 

Dockerfile

FROM java:8-jre 

## Node.js setup 
RUN curl -sL https://deb.nodesource.com/setup_6.x | bash - 
RUN apt-get install -y nodejs 

RUN npm config set spin false 

WORKDIR /app 

COPY . ./ 

RUN npm install 
+0

你可以發佈守夜Dockerfile嗎? –

+0

@BaoTran我已經包括了夜間Dockerfile。 – wwwuser

回答

2

的搬運工節點圖像被配置成只運行一個瀏覽器實例。您可以通過覆蓋環境變量改變這一點,就像這樣:

chrome: 
    environment: 
     VIRTUAL_HOST: node.chrome.docker 
     HUB_PORT_4444_TCP_ADDR: hub 
     HUB_PORT_4444_TCP_PORT: 4444 
     NODE_MAX_INSTANCES: 5 
     NODE_MAX_SESSION: 5 
    image: selenium/node-chrome:3.1.0-astatine 
    links: 
     - hub 

在你感興趣的話,我通過看Dockerfile source發現了這一點。