From 68aa47fd9daac5ad40d1520d886924abc14a0de5 Mon Sep 17 00:00:00 2001 From: Markus Danek Date: Tue, 8 Nov 2016 11:47:01 +0100 Subject: [PATCH] TT#5496 ngcp-csc test environment without PhantomJS Add new Dockerfile and testrunner script to switch from PhantomJS to Chromium for End-to-End tests. Change-Id: If561965d2fac5bd63791163cd584a66f71df03b1 --- Readme.md | 14 +- sencha | 1 + t/Dockerfile | 30 ++-- t/config/karma.conf.js | 33 ++++ t/config/wdio.conf.js | 30 ++++ t/jenkins_docker_run | 2 +- t/karma.conf.js | 72 --------- t/package.json | 19 +-- t/{ => specs}/app_test.js | 0 t/{karma => specs}/karma-setup.spec.js | 0 t/{wdio => specs}/wdio-setup.spec.js | 0 t/testrunner | 18 +-- t/wdio.conf.js | 199 ------------------------- t/xvfb-chromium | 22 +++ 14 files changed, 130 insertions(+), 310 deletions(-) create mode 120000 sencha create mode 100644 t/config/karma.conf.js create mode 100644 t/config/wdio.conf.js delete mode 100644 t/karma.conf.js rename t/{ => specs}/app_test.js (100%) rename t/{karma => specs}/karma-setup.spec.js (100%) rename t/{wdio => specs}/wdio-setup.spec.js (100%) delete mode 100644 t/wdio.conf.js create mode 100755 t/xvfb-chromium diff --git a/Readme.md b/Readme.md index f090aaa9..44c6b9fd 100644 --- a/Readme.md +++ b/Readme.md @@ -135,7 +135,6 @@ sencha web start ``` makes the build available at **localhost:1841** - ## Watch changes sencha app watch @@ -147,7 +146,6 @@ http://docs.sencha.com/cmd/ and regarding ExtJS http://docs.sencha.com/extjs/6.2.0/ - ## Tests Install all Node.js dependencies in *ngcp-csc/t/* with ```npm install```. @@ -156,14 +154,14 @@ Install all Node.js dependencies in *ngcp-csc/t/* with ```npm install```. Make sure that selenium-server and the NGCP-CSC application is running. -Karma test: ```npm run test-karma``` - -WebdriverIO test: ```npm run test-karma``` - -*Change the path to your local PhantomJS executable in wdio.conf.js.* +``` +npm test +``` ### Docker Create and run Docker Image (see instructions inside the Dockerfile). -Run inside Docker: ```cd /code && sencha app build -c && ./t/testrunner``` +Inside docker: + +```cd /code && /opt/Sencha/Cmd/sencha app build -c && ./t/testrunner``` diff --git a/sencha b/sencha new file mode 120000 index 00000000..cd8c6c7b --- /dev/null +++ b/sencha @@ -0,0 +1 @@ +/opt/Sencha/Cmd/sencha \ No newline at end of file diff --git a/t/Dockerfile b/t/Dockerfile index 9f6efd9a..f0a67b7b 100644 --- a/t/Dockerfile +++ b/t/Dockerfile @@ -5,31 +5,43 @@ FROM docker.mgm.sipwise.com/sipwise-jessie:latest # is updated with the current date. It will force refresh of all # of the base images and things like `apt-get update` won't be using # old cached versions when the Dockerfile is built. -ENV REFRESHED_AT 2016-10-27 +ENV REFRESHED_AT 2016-11-16 RUN echo "deb https://deb.sipwise.com/autobuild/ release-trunk-jessie main" >>/etc/apt/sources.list RUN apt-get update RUN apt-get install --assume-yes \ + chromium \ curl \ - default-jre-headless \ devscripts \ - nodejs \ - nodejs-legacy \ - npm \ + libgconf-2-4 \ + openjdk-7-jre-headless \ sencha-cmd \ unzip \ - xterm + xvfb RUN adduser --disabled-password --gecos=Selenium-User selenium - WORKDIR /home/selenium RUN wget -O selenium-server-standalone-2.53.1.jar http://selenium-release.storage.googleapis.com/2.53/selenium-server-standalone-2.53.1.jar RUN ln -s selenium-server-standalone-2.53.1.jar selenium-server-standalone.jar +RUN wget -O chromedriver_linux64.zip https://deb.sipwise.com/files/chromedriver_linux64_2.25.zip && unzip chromedriver_linux64.zip + +ADD xvfb-chromium /usr/bin/xvfb-chromium +RUN ln -s /usr/bin/xvfb-chromium /usr/bin/google-chrome +RUN ln -s /usr/bin/xvfb-chromium /usr/bin/chromium-browser + +# Needs to be removed when sipwise node.js backport is available +RUN curl -sL https://deb.nodesource.com/setup_4.x | bash - +RUN apt-get install -y nodejs + RUN echo "cd /code && /opt/Sencha/Cmd/sencha app build -c && ./t/testrunner" >/root/.bash_history -WORKDIR /home/selenium +RUN ln -s /home/selenium/chromedriver /usr/bin/chromedriver + +COPY jenkins_docker_run /home/selenium/ + +WORKDIR /home/selenium/ ################################################################################ # Instructions for usage @@ -43,5 +55,5 @@ WORKDIR /home/selenium # % docker run --rm -i -t -v $(pwd)/..:/code:rw docker.mgm.sipwise.com/ngcp-csc-jessie:latest bash # # Inside docker: -# cd /code && sencha app build -c && ./t/testrunner +# cd /code && /opt/Sencha/Cmd/sencha app build -c && ./t/testrunner ################################################################################ diff --git a/t/config/karma.conf.js b/t/config/karma.conf.js new file mode 100644 index 00000000..bf8142d9 --- /dev/null +++ b/t/config/karma.conf.js @@ -0,0 +1,33 @@ +module.exports = function(config) { + config.set({ + basePath: '', + frameworks: ['jasmine'], + files: [ + '../../ext/build/ext-all-debug.js', '../specs/app_test.js', '../specs/karma-*.js' + ], + browsers: ['Chrome'], + plugins: [ + 'karma-jasmine', 'karma-chrome-launcher', 'karma-junit-reporter' + ], + exclude: [], + preprocessors: {}, + reporters: [ + 'progress', 'junit' + ], + junitReporter: { + outputDir: '../', + outputFile: undefined, + suite: '', + useBrowserName: true, + nameFormatter: undefined, + classNameFormatter: undefined, + properties: {} + }, + port: 9876, + colors: true, + logLevel: config.LOG_INFO, + autoWatch: true, + singleRun: true, + concurrency: Infinity + }) +} diff --git a/t/config/wdio.conf.js b/t/config/wdio.conf.js new file mode 100644 index 00000000..cadc6f49 --- /dev/null +++ b/t/config/wdio.conf.js @@ -0,0 +1,30 @@ +exports.config = { + specs: ['./specs/wdio-*.js'], + exclude: [], + maxInstances: 10, + capabilities: [ + { + maxInstances: 5, + browserName: 'chrome', + } + ], + sync: true, + logLevel: 'silent', + coloredLogs: true, + screenshotPath: './errorShots/', + baseUrl: 'http://localhost:1841', + waitforTimeout: 10000, + connectionRetryTimeout: 90000, + connectionRetryCount: 3, + framework: 'jasmine', + reporters: [ + 'spec', 'junit' + ], + reporterOptions: { + outputDir: '../' + }, + jasmineNodeOpts: { + defaultTimeoutInterval: 10000, + expectationResultHandler: function(passed, assertion) {} + } +} diff --git a/t/jenkins_docker_run b/t/jenkins_docker_run index a702e4b1..882cdff8 100644 --- a/t/jenkins_docker_run +++ b/t/jenkins_docker_run @@ -1,4 +1,4 @@ #!/bin/bash # This script is used for running the tests with proper arguments # from within Jenkins -cd /code && sencha app build -c && ./t/testrunner +cd /code && /opt/Sencha/Cmd/sencha app build -c && ./t/testrunner diff --git a/t/karma.conf.js b/t/karma.conf.js deleted file mode 100644 index 878263d3..00000000 --- a/t/karma.conf.js +++ /dev/null @@ -1,72 +0,0 @@ -// Karma configuration - -module.exports = function(config) { - config.set({ - - // base path that will be used to resolve all patterns (eg. files, exclude) - basePath: '', - - // frameworks to use - // available frameworks: https://npmjs.org/browse/keyword/karma-adapter - frameworks: ['jasmine'], - - // list of files / patterns to load in the browser - files: [ - '../ext/build/ext-all-debug.js', 'app_test.js', - - //{pattern: 'app/data/*.json', included: false}, - - 'karma/*.js' - ], - - // list of files to exclude - exclude: [], - - // preprocess matching files before serving them to the browser - // available preprocessors: https://npmjs.org/browse/keyword/karma-preprocessor - preprocessors: {}, - - // test results reporter to use - // possible values: 'dots', 'progress' - // available reporters: https://npmjs.org/browse/keyword/karma-reporter - reporters: [ - 'progress', 'junit' - ], - - // the default configuration - junitReporter: { - outputDir: '', // results will be saved as $outputDir/$browserName.xml - outputFile: undefined, // if included, results will be saved as $outputDir/$browserName/$outputFile - suite: '', // suite will become the package name attribute in xml testsuite element - useBrowserName: true, // add browser name to report and classes names - nameFormatter: undefined, // function (browser, result) to customize the name attribute in xml testcase element - classNameFormatter: undefined, // function (browser, result) to customize the classname attribute in xml testcase element - properties: {} // key value pair of properties to add to the section of the report - }, - - // web server port - port: 9876, - - // enable / disable colors in the output (reporters and logs) - colors: true, - - // level of logging - // possible values: config.LOG_DISABLE || config.LOG_ERROR || config.LOG_WARN || config.LOG_INFO || config.LOG_DEBUG - logLevel: config.LOG_INFO, - - // enable / disable watching file and executing tests whenever any file changes - autoWatch: true, - - // start these browsers - // available browser launchers: https://npmjs.org/browse/keyword/karma-launcher - browsers: ['PhantomJS'], - - // Continuous Integration mode - // if true, Karma captures browsers, runs the tests and exits - singleRun: true, - - // Concurrency level - // how many browser should be started simultaneous - concurrency: Infinity - }) -} diff --git a/t/package.json b/t/package.json index 7a2e3903..9ce0ef12 100644 --- a/t/package.json +++ b/t/package.json @@ -1,25 +1,22 @@ { "name": "ngcp-csc", "description": "Sipwise ngcp-csc tests", - "version": "1.0.0", + "version": "1.0.1", + "author": "Markus Danek ", + "private": "true", "scripts": { - "test-karma": "karma start karma.conf.js", - "test-wdio": "wdio wdio.conf.js" + "test": "karma start config/karma.conf.js && wdio config/wdio.conf.js" }, "dependencies": { - "install": "^0.8.1", "jasmine": "^2.5.2", "karma": "^1.3.0", + "karma-chrome-launcher": "^2.0.0", "karma-jasmine": "^1.0.2", - "karma-phantomjs-launcher": "^1.0.2", - "phantomjs-prebuilt": "^2.1.13", + "karma-junit-reporter": "^1.1.0", "selenium-standalone": "^5.7.2", "wdio-jasmine-framework": "^0.2.6", - "webdriverio": "^4.2.16" - }, - "devDependencies": { - "karma-junit-reporter": "^1.1.0", "wdio-junit-reporter": "^0.1.0", - "wdio-spec-reporter": "0.0.3" + "wdio-spec-reporter": "0.0.3", + "webdriverio": "^4.2.16" } } diff --git a/t/app_test.js b/t/specs/app_test.js similarity index 100% rename from t/app_test.js rename to t/specs/app_test.js diff --git a/t/karma/karma-setup.spec.js b/t/specs/karma-setup.spec.js similarity index 100% rename from t/karma/karma-setup.spec.js rename to t/specs/karma-setup.spec.js diff --git a/t/wdio/wdio-setup.spec.js b/t/specs/wdio-setup.spec.js similarity index 100% rename from t/wdio/wdio-setup.spec.js rename to t/specs/wdio-setup.spec.js diff --git a/t/testrunner b/t/testrunner index e7df6c51..3baf101b 100755 --- a/t/testrunner +++ b/t/testrunner @@ -1,7 +1,5 @@ #!/bin/bash -export PATH="$PATH:/opt/Sencha/Cmd/" - if ! [ -f /.dockerenv ] && ! grep -q 'devices:/docker' /proc/1/cgroup ; then echo "Not running inside docker, exiting to avoid data damage." >&2 exit 1 @@ -16,7 +14,7 @@ PASSWORD="selenium" pkill -f '/usr/bin/java -jar /home/selenium/selenium-server-standalone.jar' || true # NOTE: this could silently fail because selenium-server-standalone.jar is missing a daemonize option -DISPLAY=:99 /usr/bin/java -jar /home/selenium/selenium-server-standalone.jar -trustAllSSLCertificates -log /home/selenium/selenium.log & +DISPLAY=:98 /usr/bin/java -jar /home/selenium/selenium-server-standalone.jar -trustAllSSLCertificates -log /home/selenium/selenium.log & sleep 5 @@ -27,18 +25,18 @@ echo "Selenium server log file available at /home/selenium/selenium.log" cp -Rf . /tmp/code cd /tmp/code/t/ rm -rf node_modules node_modules - npm install -echo "Starting karma test" -./node_modules/karma/bin/karma start karma.conf.js +echo "Starting Karma test" +cd /tmp/code/t/ +./node_modules/karma/bin/karma start config/karma.conf.js -echo "Starting webdriverio test" +echo "Starting WebdriverIO test" cd /tmp/code/ -sencha web start & +/opt/Sencha/Cmd/sencha web start & sleep 5 -cd /tmp/code/t -./node_modules/.bin/wdio wdio.conf.js +cd /tmp/code/t/ +./node_modules/.bin/wdio config/wdio.conf.js echo "Finished test execution, test execution returned with exit code." echo "################################################################################" diff --git a/t/wdio.conf.js b/t/wdio.conf.js deleted file mode 100644 index 7fb5cab0..00000000 --- a/t/wdio.conf.js +++ /dev/null @@ -1,199 +0,0 @@ -exports.config = { - - // - // ================== - // Specify Test Files - // ================== - // Define which test specs should run. The pattern is relative to the directory - // from which `wdio` was called. Notice that, if you are calling `wdio` from an - // NPM script (see https://docs.npmjs.com/cli/run-script) then the current working - // directory is where your package.json resides, so `wdio` will be called from there. - // - specs: [ - './wdio/*.js' - ], - // Patterns to exclude. - exclude: [ - // 'path/to/excluded/files' - ], - // - // ============ - // Capabilities - // ============ - // Define your capabilities here. WebdriverIO can run multiple capabilities at the same - // time. Depending on the number of capabilities, WebdriverIO launches several test - // sessions. Within your capabilities you can overwrite the spec and exclude options in - // order to group specific specs to a specific capability. - // - // First, you can define how many instances should be started at the same time. Let's - // say you have 3 different capabilities (Chrome, Firefox, and Safari) and you have - // set maxInstances to 1; wdio will spawn 3 processes. Therefore, if you have 10 spec - // files and you set maxInstances to 10, all spec files will get tested at the same time - // and 30 processes will get spawned. The property handles how many capabilities - // from the same test should run tests. - // - maxInstances: 10, - // - // If you have trouble getting all important capabilities together, check out the - // Sauce Labs platform configurator - a great tool to configure your capabilities: - // https://docs.saucelabs.com/reference/platforms-configurator - // - capabilities: [{ - // maxInstances can get overwritten per capability. So if you have an in-house Selenium - // grid with only 5 firefox instance available you can make sure that not more than - // 5 instance gets started at a time. - maxInstances: 5, - // - browserName: 'phantomjs', - "phantomjs.binary.path": "/tmp/code/t/node_modules/phantomjs-prebuilt/lib/phantom/bin/phantomjs" // Docker path - // "phantomjs.binary.path": "/usr/local/bin/phantomjs" // Local path - }], - // - // =================== - // Test Configurations - // =================== - // Define all options that are relevant for the WebdriverIO instance here - // - // By default WebdriverIO commands are executed in a synchronous way using - // the wdio-sync package. If you still want to run your tests in an async way - // e.g. using promises you can set the sync option to false. - sync: true, - // - // Level of logging verbosity: silent | verbose | command | data | result | error - logLevel: 'silent', - // - // Enables colors for log output. - coloredLogs: true, - // - // Saves a screenshot to a given path if a command fails. - screenshotPath: './errorShots/', - // - // Set a base URL in order to shorten url command calls. If your url parameter starts - // with "/", then the base url gets prepended. - baseUrl: 'http://localhost:1841', - // - // Default timeout for all waitFor* commands. - waitforTimeout: 10000, - // - // Default timeout in milliseconds for request - // if Selenium Grid doesn't send response - connectionRetryTimeout: 90000, - // - // Default request retries count - connectionRetryCount: 3, - // - // Initialize the browser instance with a WebdriverIO plugin. The object should have the - // plugin name as key and the desired plugin options as properties. Make sure you have - // the plugin installed before running any tests. The following plugins are currently - // available: - // WebdriverCSS: https://github.com/webdriverio/webdrivercss - // WebdriverRTC: https://github.com/webdriverio/webdriverrtc - // Browserevent: https://github.com/webdriverio/browserevent - // plugins: { - // webdrivercss: { - // screenshotRoot: 'my-shots', - // failedComparisonsRoot: 'diffs', - // misMatchTolerance: 0.05, - // screenWidth: [320,480,640,1024] - // }, - // webdriverrtc: {}, - // browserevent: {} - // }, - // - // Test runner services - // Services take over a specific job you don't want to take care of. They enhance - // your test setup with almost no effort. Unlike plugins, they don't add new - // commands. Instead, they hook themselves up into the test process. - // services: ['phantomjs'], - // Framework you want to run your specs with. - // The following are supported: Mocha, Jasmine, and Cucumber - // see also: http://webdriver.io/guide/testrunner/frameworks.html - // - // Make sure you have the wdio adapter package for the specific framework installed - // before running any tests. - framework: 'jasmine', - // - // Test reporter for stdout. - // The only one supported by default is 'dot' - // see also: http://webdriver.io/guide/testrunner/reporters.html - reporters: ['spec', 'junit'], - // - reporterOptions: { - outputDir: './' - }, - // Options to be passed to Jasmine. - jasmineNodeOpts: { - // - // Jasmine default timeout - defaultTimeoutInterval: 10000, - // - // The Jasmine framework allows interception of each assertion in order to log the state of the application - // or website depending on the result. For example, it is pretty handy to take a screenshot every time - // an assertion fails. - expectationResultHandler: function(passed, assertion) { - // do something - } - }, - - // - // ===== - // Hooks - // ===== - // WebdriverIO provides several hooks you can use to interfere with the test process in order to enhance - // it and to build services around it. You can either apply a single function or an array of - // methods to it. If one of them returns with a promise, WebdriverIO will wait until that promise got - // resolved to continue. - // - // Gets executed once before all workers get launched. - // onPrepare: function (config, capabilities) { - // }, - // - // Gets executed before test execution begins. At this point you can access all global - // variables, such as `browser`. It is the perfect place to define custom commands. - // before: function (capabilities, specs) { - // }, - // - // Hook that gets executed before the suite starts - // beforeSuite: function (suite) { - // }, - // - // Hook that gets executed _before_ a hook within the suite starts (e.g. runs before calling - // beforeEach in Mocha) - // beforeHook: function () { - // }, - // - // Hook that gets executed _after_ a hook within the suite starts (e.g. runs after calling - // afterEach in Mocha) - // afterHook: function () { - // }, - // - // Function to be executed before a test (in Mocha/Jasmine) or a step (in Cucumber) starts. - // beforeTest: function (test) { - // }, - // - // Runs before a WebdriverIO command gets executed. - // beforeCommand: function (commandName, args) { - // }, - // - // Runs after a WebdriverIO command gets executed - // afterCommand: function (commandName, args, result, error) { - // }, - // - // Function to be executed after a test (in Mocha/Jasmine) or a step (in Cucumber) starts. - // afterTest: function (test) { - // }, - // - // Hook that gets executed after the suite has ended - // afterSuite: function (suite) { - // }, - // - // Gets executed after all tests are done. You still have access to all global variables from - // the test. - // after: function (result, capabilities, specs) { - // }, - // - // Gets executed after all workers got shut down and the process is about to exit. It is not - // possible to defer the end of the process using a promise. - // onComplete: function(exitCode) { - // } -} diff --git a/t/xvfb-chromium b/t/xvfb-chromium new file mode 100755 index 00000000..5311ba50 --- /dev/null +++ b/t/xvfb-chromium @@ -0,0 +1,22 @@ +#!/bin/bash + +_kill_procs() { + kill -TERM $chromium + wait $chromium + kill -TERM $xvfb +} + +trap _kill_procs SIGTERM + +XVFB_WHD=${XVFB_WHD:-1280x720x16} + +Xvfb :99 -ac -screen 0 $XVFB_WHD -nolisten tcp & +xvfb=$! + +export DISPLAY=:99 + +chromium --no-sandbox $@ & +chromium=$! + +wait $chromium +wait $xvfb