Как запустить докеризованный проект транспортира, который включал Angular?

#angular #docker #selenium #npm #protractor

Вопрос:

Я новичок в транспортире. Я создал проект с angular, и он отлично работает без докера. Однако, когда я создаю образ, он успешно создается. К сожалению, не удалось запустить этот.

Папка : содержимое транспортира ниже

 .
./Dockerfile
./protractor.sh
./protractor.conf.js
./package-lock.json
./node_modules
./package.json
./specs
 

Я запустил его вручную, используя эту команду

 protractor$ ./protractor.sh protractor.conf.js
 

Затем результаты выглядят следующим образом

 [14:36:13] I/launcher - Running 1 instances of WebDriver
[14:36:13] I/local - Starting selenium standalone server...
[14:36:14] I/local - Selenium standalone server started at http://192.168.8.103:53238/wd/hub
[14:36:14] I/start - java -Djava.security.egd=file:///dev/./urandom -Dwebdriver.gecko.driver=/usr/lib/node_modules/protractor/node_modules/webdriver-manager/selenium/geckodriver-v0.29.1 -Dwebdriver.chrome.driver=/usr/lib/node_modules/protractor/node_modules/webdriver-manager/selenium/chromedriver_90.0.4430.24 -jar /usr/lib/node_modules/protractor/node_modules/webdriver-manager/selenium/selenium-server-standalone-3.141.59.jar -port 4444
[14:36:14] I/start - seleniumProcess.pid: 14964
14:36:14.643 INFO [GridLauncherV3.parse] - Selenium server version: 3.141.59, revision: e82be7d358
14:36:14.710 INFO [GridLauncherV3.lambda$buildLaunchers$3] - Launching a standalone Selenium Server on port 4444
2021-05-23 14:36:14.744:INFO::main: Logging initialized @260ms to org.seleniumhq.jetty9.util.log.StdErrLog
14:36:14.951 INFO [WebDriverServlet.<init>] - Initialising WebDriverServlet
14:36:15.069 INFO [SeleniumServer.boot] - Selenium Server is up and running on port 4444
Started
[14:36:20] W/element - more than one element found for locator By(css selector, .ng-binding) - the first result will be used
.


1 spec, 0 failures
Finished in 7.482 seconds

[14:36:22] I/local - Shutting down selenium standalone server.
[14:36:22] I/launcher - 0 instance(s) of WebDriver still running
[14:36:22] I/launcher - chrome #01 passed
 

Команда сборки Docker, как показано ниже

 sudo docker build -t priyanwso2/protractor-docker .
Sending build context to Docker daemon   36.5MB
Step 1/8 : FROM         node:latest
 ---> 7493e35c7ffa
Step 2/8 : WORKDIR  /tmp
 ---> Using cache
 ---> d1941bcedacd
Step 3/8 : RUN      apt-get update --fix-missing amp;amp;         apt-get install -y xvfb wget openjdk-11-jre-headless libgconf-2-4 libexif12 chromium amp;amp;         apt-get clean
 ---> Using cache
 ---> 0f440f61b0f9
Step 4/8 : RUN      mkdir /protractor amp;amp;            npm install -g protractor
 ---> Using cache
 ---> eca289196866
Step 5/8 : RUN      webdriver-manager update
 ---> Using cache
 ---> fa2d0cc0ca06
Step 6/8 : ADD      protractor.sh /protractor.sh
 ---> Using cache
 ---> 83ef2046c6b0
Step 7/8 : WORKDIR  /protractor
 ---> Using cache
 ---> 0f7bb601e197
Step 8/8 : ENTRYPOINT   ["/protractor.sh"]
 ---> Using cache
 ---> a25c6c8f566b
Successfully built a25c6c8f566b
Successfully tagged priyanwso2/protractor-docker:latest
 

When I run the docker images, it listed in docker images list

 priyanwso2/protractor-docker   latest    a25c6c8f566b   47 minutes ago   1.69GB
 

When I try to run the docker image it will give below error

 sudo docker run priyanwso2/protractor-docker protractor.conf.js
[09:09:57] E/configParser - Error code: 105
[09:09:57] E/configParser - Error message: failed loading configuration file protractor.conf.js
[09:09:57] E/configParser - Error: Cannot find module '/protractor/protractor.conf.js'
Require stack:
- /usr/local/lib/node_modules/protractor/built/configParser.js
- /usr/local/lib/node_modules/protractor/built/launcher.js
- /usr/local/lib/node_modules/protractor/built/cli.js
- /usr/local/lib/node_modules/protractor/bin/protractor
    at Function.Module._resolveFilename (node:internal/modules/cjs/loader:941:15)
    at Function.Module._load (node:internal/modules/cjs/loader:774:27)
    at Module.require (node:internal/modules/cjs/loader:1013:19)
    at require (node:internal/modules/cjs/helpers:93:18)
    at ConfigParser.addFileConfig (/usr/local/lib/node_modules/protractor/built/configParser.js:135:26)
    at Object.initFn [as init] (/usr/local/lib/node_modules/protractor/built/launcher.js:93:22)
    at Object.<anonymous> (/usr/local/lib/node_modules/protractor/built/cli.js:227:10)
    at Module._compile (node:internal/modules/cjs/loader:1109:14)
    at Object.Module._extensions..js (node:internal/modules/cjs/loader:1138:10)
    at Module.load (node:internal/modules/cjs/loader:989:32)
 

OS Ubuntu 18.04 LTS (64bit)

Dockerfile

 FROM            node:latest

WORKDIR         /tmp

RUN             apt-get update --fix-missing amp;amp; 
                apt-get install -y xvfb wget openjdk-11-jre-headless libgconf-2-4 libexif12 chromium amp;amp; 
                apt-get clean

RUN             mkdir /protractor amp;amp; 
                npm install -g protractor

RUN             webdriver-manager update

ADD             protractor.sh /protractor.sh

WORKDIR         /protractor

ENTRYPOINT      ["/protractor.sh"]
 

package.json file as per below

 {
  "name": "test",
  "version": "1.0.0",
  "description": "Test e2e package",
  "main": "conf.js",
  "dependencies": {
    "chromedriver": "^90.0.1",
    "jasmine": "^3.7.0",
    "protractor": "^7.0.0",
    "webdriver-manager": "^12.1.8"
  },
  "scripts": {
    "test": "protractor.conf.js"
  },
  "author": "SOAS",
  "license": "ISC"
}
 

protractor.conf.js как указано ниже

 exports.config = {
  multiCapabilities: [{browserName: 'chrome'}],
  specs: ['specs/superCalculatorTest.js' ],
  onPrepare: function(){browser.ignoreSynchronization = true;},
};
 

Смотрите здесь код в protractor.sh

 #!/bin/bash
webdriver-manager start amp;
protractor $@
 

в папке спецификации один js (superCalculatorTest.js) существует. вот его код

 const { $, browser } = require("protractor");
let url = 'https://juliemr.github.io/protractor-demo/';

describe('Super Calculator Test suite', () => {
    it('Verify Adding two Integers', () => {
        browser.get(url);
        browser.sleep(2000);
        element(by.model('first')).sendKeys(2);
        element(by.model('second')).sendKeys(5);
        element(by.id('gobutton')).click();
        browser.sleep(2000);
        expect(element(by.className('ng-binding')).getText()).toEqual('7');
        browser.sleep(2000);
    });
});
 

Пожалуйста, помогите разобраться с этой проблемой. Я использую эту среднюю страницу для написания части тестирования.
https://bytes.grubhub.com/end-to-end-testing-with-docker-71008dca11a0

Ответ №1:

Вы упускаете самую важную часть в своем файле dockerfile. Вам нужно скопировать все файлы в контейнер. Вы запускаете mkdir , а затем сразу же запускаете npm install , но в вашем protractor каталоге ничего нет. Там пусто.

 COPY /path/to/source /path/to/destination
 

См. документы https://docs.docker.com/engine/reference/builder/#copy