Sap 使用Project Piper进行自动测试

Sap 使用Project Piper进行自动测试,sap,karma-runner,sap-cloud-sdk,karma-chrome-launcher,Sap,Karma Runner,Sap Cloud Sdk,Karma Chrome Launcher,我们目前正在为基于的SCP CF环境设置CI/CD管道。经过大量的尝试和错误,我们已经完成了重要的过程,但是我们仍然无法运行我们的业力测试 我们知道我们需要使用,但是我们无法启动/连接到sidecar容器中的Chrome 相关日志: [Pipeline] sh + cd ./nodejs + npm test > nodejs@1.0.0 test /var/jenkins_home/workspace/CICD_Multibranch_master/nodejs > karma

我们目前正在为基于的SCP CF环境设置CI/CD管道。经过大量的尝试和错误,我们已经完成了重要的过程,但是我们仍然无法运行我们的业力测试

我们知道我们需要使用,但是我们无法启动/连接到sidecar容器中的Chrome

相关日志:

[Pipeline] sh
+ cd ./nodejs
+ npm test

> nodejs@1.0.0 test /var/jenkins_home/workspace/CICD_Multibranch_master/nodejs
> karma start ./karma.conf.js

10 07 2019 14:42:53.897:DEBUG [config]: Loading config /var/jenkins_home/workspace/CICD_Multibranch_master/nodejs/karma.conf.js
10 07 2019 14:42:53.906:DEBUG [karma-server]: Final config [{"LOG_DISABLE":"1","LOG_ERROR":"2","LOG_WARN":"3","LOG_INFO":"4","LOG_DEBUG":"5","frameworks":"6","protocol":"7","port":9876,"listenAddress":"8","hostname":"9","httpsServerConfig":"10","basePath":"11","files":"12","browserConsoleLogOptions":"13","customContextFile":null,"customDebugFile":null,"customClientContextFile":null,"exclude":"14","logLevel":"5","colors":false,"autoWatch":false,"autoWatchBatchDelay":250,"restartOnFileChange":false,"usePolling":true,"reporters":"15","singleRun":true,"browsers":"16","captureTimeout":60000,"proxies":"17","proxyValidateSSL":true,"preprocessors":"18","urlRoot":"19","reportSlowerThan":0,"loggers":"20","transports":"21","forceJSONP":false,"plugins":"22","client":"23","defaultClient":"23","browserDisconnectTimeout":2000,"browserDisconnectTolerance":0,"browserNoActivityTimeout":30000,"processKillTimeout":2000,"concurrency":null,"failOnEmptyTestSuite":true,"retryLimit":2,"detached":false,"crossOriginAttribute":true,"browserSocketTimeout":20000,"cmd":"24","configFile":"25","customLaunchers":"26","junitReporter":"27"},"OFF","ERROR","WARN","INFO","DEBUG",["28"],"http:","0.0.0.0","localhost",{},"/var/jenkins_home/workspace/CICD_Multibranch_master/nodejs",["29","30"],{"level":"31","format":"32","terminal":true},["25"],["33"],["34"],{},{},"/",["35"],["36","37"],["38","39","40","41","42"],{"args":"43","useIframe":true,"runInParent":false,"captureConsole":true,"clearContext":true},"start","/var/jenkins_home/workspace/CICD_Multibranch_master/nodejs/karma.conf.js",{"chromeSel":"44"},{"outputFile":"45","suite":"46"},"qunit",{"pattern":"47","served":true,"included":true,"watched":true,"nocache":false,"weight":"48"},{"pattern":"49","served":true,"included":true,"watched":true,"nocache":false,"weight":"50"},"debug","%b %T: %m","junit","chromeSel",{"type":"51","layout":"52"},"polling","websocket","karma-qunit","karma-junit-reporter","karma-chrome-launcher","karma-webdriver-launcher",{"launcher:chromeSel":"53"},[],{"base":"54","config":"55","browserName":"56"},"test-results-karma.xml","","/var/jenkins_home/workspace/CICD_Multibranch_master/nodejs/server.js",[1,0,0,0,0,0],"/var/jenkins_home/workspace/CICD_Multibranch_master/nodejs/tests/sampleTest.spec.js",[1,0,0,0,0,0],"console",{"type":"57","pattern":"58"},["59",null],"WebDriver",{"hostname":"60","port":4444},"chrome","pattern","%d{DATE}:%p [%c]: %m","factory","selenium"]
10 07 2019 14:42:53.907:DEBUG [plugin]: Loading plugin karma-qunit.
10 07 2019 14:42:53.908:DEBUG [plugin]: Loading plugin karma-junit-reporter.
10 07 2019 14:42:53.923:DEBUG [plugin]: Loading plugin karma-chrome-launcher.
10 07 2019 14:42:53.931:DEBUG [plugin]: Loading plugin karma-webdriver-launcher.
10 07 2019 14:42:54.179:DEBUG [plugin]: Loading inlined plugin (defining launcher:chromeSel).
10 07 2019 14:42:54.193:DEBUG [web-server]: Instantiating middleware
10 07 2019 14:42:54.194:DEBUG [reporter]: Trying to load reporter: junit
10 07 2019 14:42:54.195:DEBUG [reporter]: Trying to load color-version of reporter: junit (junit_color)
10 07 2019 14:42:54.195:DEBUG [reporter]: Couldn't load color-version.
10 07 2019 14:42:54.224:INFO [karma-server]: Karma v4.1.0 server started at http://0.0.0.0:9876/
10 07 2019 14:42:54.225:INFO [launcher]: Launching browsers chromeSel with concurrency unlimited
10 07 2019 14:42:54.231:INFO [launcher]: Starting browser chrome via Remote WebDriver
10 07 2019 14:42:54.232:DEBUG [launcher]: null -> BEING_CAPTURED
10 07 2019 14:42:54.232:DEBUG [temp-dir]: Creating temp dir at /tmp/karma-89562642
10 07 2019 14:42:54.235:DEBUG [WebDriver]: WebDriver config: {"hostname":"selenium","port":4444}
10 07 2019 14:42:54.235:DEBUG [WebDriver]: Browser capabilities: {"platform":"ANY","testName":"Karma test","tags":[],"version":"","base":"WebDriver","browserName":"chrome"}
10 07 2019 14:43:54.281:WARN [launcher]: chrome via Remote WebDriver have not captured in 60000 ms, killing.
10 07 2019 14:43:54.286:DEBUG [launcher]: BEING_CAPTURED -> BEING_KILLED
10 07 2019 14:43:54.355:INFO [WebDriver]: Killed Karma test.
10 07 2019 14:43:54.355:DEBUG [launcher]: Process chrome via Remote WebDriver exited with code -1 and signal timeout
10 07 2019 14:43:54.356:DEBUG [temp-dir]: Cleaning temp dir /tmp/karma-89562642
10 07 2019 14:43:54.358:INFO [launcher]: Trying to start chrome via Remote WebDriver again (1/2).
karma.conf.js:

// Karma configuration

module.exports = function(config) {
var webdriverConfig = {
    hostname: 'selenium',
    port: 4444
}   
  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: ['qunit'],

    plugins: ['karma-qunit','karma-junit-reporter','karma-chrome-launcher', 'karma-webdriver-launcher'],


    // list of files / patterns to load in the browser
    files: [
      'server.js',
      'tests/sampleTest.spec.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: ['junit'],


    // web server port
    //port: 9876,
    //hostname: localhost,


    // enable / disable colors in the output (reporters and logs)
    colors: false,


    // level of logging
    // possible values: config.LOG_DISABLE || config.LOG_ERROR || config.LOG_WARN || config.LOG_INFO || config.LOG_DEBUG
    logLevel: config.LOG_DEBUG,


    // enable / disable watching file and executing tests whenever any file changes
    autoWatch: false,

    customLaunchers: {
        'chromeSel': {
            base: 'WebDriver',
            config: webdriverConfig,
            browserName: 'chrome'
        }
    },

    // start these browsers
    // available browser launchers: https://npmjs.org/browse/keyword/karma-launcher
    browsers: ['chromeSel'],


    // Continuous Integration mode
    // if true, Karma captures browsers, runs the tests and exits
    singleRun: true,
    junitReporter: {
        outputFile: 'test-results-karma.xml',
        suite: ''
    }
  });
};
詹金斯档案:

#!groovy
@Library('piper-lib-os') _


node(){

  stage('Prepare')   {
      deleteDir()
      checkout scm
      setupCommonPipelineEnvironment
  }

  stage('Build')   {
      karmaExecuteTests script: this, modules: ['./nodejs'],
      installCommand: "npm install karma karma-qunit karma-junit-reporter karma-chrome-launcher qunit karma-webdriver-launcher", 
      runCommand: 'npm test'
      mtaBuild script:this, buildTarget: 'CF', applicationName: 'appLibrary'
  }

  stage('Deploy to QA')   {
   testsPublishResults script: this, junit: [updateResults: true, archive: true]
   cloudFoundryDeploy(
    script: this,
    cloudFoundry: [apiEndpoint: 'https://api.cf.eu10.hana.ondemand.com', manifest: 'manifest.yml', org:'xxx', space:'xxx', credentialsId: 'xxx'],
    deployTool: 'mtaDeployPlugin'
    )
  }
}
非常感谢,
Nico

要在Jenkins上运行
karmaExecuteTests
步骤,需要安装Docker deamon。我想是这样的


在Docker sidecar模式中,容器可以使用它们的容器名称相互交谈(
karma
&
selenium
)。因此,对于浏览器(
config.customLaunchers.chromeSel.config.hostname
),您可以将主机名正确设置为
selenium
,但您还需要将
config.hostname
设置为
karma

您不需要声明要在karma配置中使用的
karma-
前缀模块,它们默认情况下是导入的。此外,您还应该考虑将<代码>安装命令中提到的模块添加到代码< >包中。JSON<代码>文件,并退回到默认的代码>安装命令< /代码>。谢谢有关删除业力插件的提示。安装的模块已经是package.json文件的一部分,因此我可以用
installCommand:“npm config set@sap:registry”替换
installCommand
https://npm.sap.com &&npm安装--quiet“
另一句话:要有一致的开发设置,您应该在项目存储库中的
.npmrc
文件中定义范围注册表
@sap…registry
。这样,您也可以省略
nom config set
命令。谢谢,克里斯托弗!这是缺少的一部分,它现在适用于JS代码。您知道如何在不定义新的docker容器或使用这些几乎没有维护的docker容器(包括Chrome和nodejs)的情况下测试nodejs代码吗。?Selenium容器不包括nodejs,并且没有用于中sidecarContainer的
安装命令。。。