How can I start a Robot Framework test in a Jenkinsfile using a robot framework docker image? [closed]

£可爱£侵袭症+ 提交于 2019-12-25 19:09:11

问题


In the Jenkinsfile I would like to use an existing Robot framework docker image. The Docker image that is pretty complete for browser testing is: ppodgorsek/robot-framework

An example of the use is:

docker run \
    -v <local path to the reports' folder>:/opt/robotframework/reports:Z \
    -v <local path to the test suites' folder>:/opt/robotframework/tests:Z \
    ppodgorsek/robot-framework:<version>

How can I start a Robot Framework test?


回答1:


Something like this? I dont have idea how robotframework works :)

pipeline {
    agent {
        docker {
            image 'ppodgorsek/robot-framework'
        }
    }
    stages {
        stage('Checkout') {
            steps {
                git branch: "master", credentialsId: "jenkins-key", url:'ssh://git@github.org/mysupercode/'

            }
        }
        stage('Test') {
            steps{
                sh 'do_super_tests.sh'
            }
        }
    }
    post {
        always {
            archive (includes: 'mytestfolder/mytest.html')
        }
    }
}



回答2:


Solution-1: thanks to @parasit I found 'ppodgorsek/robot-framework'.

You can start a Robot Framework test from a Jenkinsfile with this pipeline code:

pipeline {
    agent any
    stages {
        stage('Checkout') {
            steps {
                git branch: "master", url:'https://github.com/johan974/robot-framework-demo1.git'
            }
        }
        stage('Test') {
            steps{
                sh 'docker run -v ${PWD}/reports:/opt/robotframework/reports:Z -v ${PWD}/Tests:/opt/robotframework/tests:Z \
                            -e BROWSER=chrome ppodgorsek/robot-framework:latest'
            }
        }
    }
    post {
        always {
            archive (includes: 'reports/*.html')
        }
    }
}

If you have these steps (including post), then you can find the results in the famous log.html en report.html files as shown below:

If you face problems showing the RF results, you can execute the followin script in your Jenkins > manage jenkins > script console:

System.setProperty("hudson.model.DirectoryBrowserSupport.CSP","sandbox allow-scripts; default-src 'none'; img-src 'self' data: ; style-src 'self' 'unsafe-inline' data: ; script-src 'self' 'unsafe-inline' 'unsafe-eval' ;")

UPDATE-2: using the much smaller Robot Framework image I could start Robot Frameworkrunning. It complains about the chromedriver not installed. This script is shown below. It could be enough when you don't have to test using a browser.

pipeline {
    agent {
        docker {
            image 'manycoding/robotframework'
        }
    }
    stages {
        stage('Checkout') {
            steps {
                git branch: "master", url:'https://github.com/johan974/robot-framework-demo1.git'
            }
        }
        stage('Test') {
            steps{
                sh 'chmod a+x ./run-tests.sh && ./run-tests.sh'
            }
        }
    }
    post {
        always {
            archive (includes: 'reports/*.html')
        }
    }
}


来源:https://stackoverflow.com/questions/52678060/how-can-i-start-a-robot-framework-test-in-a-jenkinsfile-using-a-robot-framework

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!