如何使用机器人框架docker映像在Jenkinsfile中启动机器人框架测试?

时间:2018-10-06 10:24:01

标签: docker robotframework

在Jenkinsfile中,我想使用现有的Robot框架docker映像。对于浏览器测试而言,非常完整的Docker映像为:ppodgorsek / robot-framework

使用示例:

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>

如何启动机器人框架测试?

2 个答案:

答案 0 :(得分:3)

像这样?我不知道robotframework是如何工作的:)

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')
        }
    }
}

答案 1 :(得分:3)

解决方案1 ​​:感谢@parasit,我找到了“ ppodgorsek / robot-framework”。

您可以使用以下管道代码从Jenkinsfile启动机器人框架测试:

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')
        }
    }
}

如果您具有这些步骤(包括发布),则可以在著名的log​​.html和report.html文件中找到结果,如下所示:

enter image description here

如果遇到显示RF结果的问题,则可以在Jenkins中执行followin脚本>管理jenkins>脚本控制台:

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 :使用小得多的Robot Framework映像,我可以启动Robot Frameworkrunning。它抱怨未安装chromedriver。该脚本如下所示。当您不必使用浏览器进行测试时,这可能就足够了。

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')
        }
    }
}