2016-03-03 39 views
-1

我有一個gradle腳本來執行一個SOAPUI測試套件。目前失敗的日誌來自同一個文件夾。我想獲得所有通行證,並且在獨立的文件夾中創建日誌爲 。我也想要一個類似index.html的報告來查看執行通過/失敗報告。它是否創建了任何testsuite.xml來存儲每個測試用例的傳遞和失敗數據,如ANT? 我不熟悉gradle。所以我需要一個很好的Gradle腳本來幫助我解決這個問題。下面是我目前的gradle這個腳本給出只能執行一個測試套件:需要通過Gradle腳本指導執行soapui項目xml並生成報告html

class SoapUITask extends Exec { 
    String soapUIExecutable = '/SOAPUIpath/SoapUI-5.1.2/bin/testrunner.sh' 
    String soapUIArgs = '' 
    public SoapUITask(){ 
     super() 
     this.setExecutable(soapUIExecutable) 
     //printReport=true 

    } 
    public void setSoapUIArgs(String soapUIArgs) { 
     this.args = "$soapUIArgs".trim().split(" ") as List 
    }                    
} 
// execute SOAPUI 
task executeSOAPUI(type: SoapUITask){ 
    // simply pass the project path as argument, 
    // note that the extra " are needed 
    soapUIArgs = '/path/of/SOAPUI project xml/src/PCDEMO-soapui-project.xml' 
} 
+0

您的代碼應該與您的問題放在一起,而不是作爲評論。請編輯您的問題並刪除評論。另請閱讀[如何問](http:// stackoverflow。COM /幫助/如何對問)。 – aribeiro

+0

謝謝....我已經完成了。 – user2530711

回答

0

如果你想生成和SOAPUI documentation可以使用如下參數HTML報告:

-f - Specifies the root directory, where the runner will save test result files. If the specified directory does not exist, it will be created.

-F Specifies the format of the exported reports. Usage: -F. Supported formats include PDF, XLS, HTML, RTF, CSV, TXT and XML. If the parameter is not specified, PDF is used. To export results in several formats, separate them with commas. For example, -FPDF,XML,CSV.

注意:正如您在文檔中看到的,-F參數僅適用於PRO版本。如果您使用免費版本,當您嘗試使用-F參數,你會得到後續的輸出中: org.apache.commons.cli.UnrecognizedOptionException: Unrecognized option: -FPDF

所以,你可以修改task executeSOAPUI添加-f location-FHTML如下:

// execute SOAPUI 
task executeSOAPUI(type: SoapUITask){ 
    // simply pass the project path as argument, 
    // note that the extra " are needed 
    soapUIArgs = '-f "path/of/outputReports" -FHTML "/path/of/SOAPUI project xml/src/PCDEMO-soapui-project.xml"' 
} 

相反,如果您期待的Junit Html樣式報告您可以嘗試使用以下參數(該參數也僅適用於PRO版本):

-R - Specifies the type of the report data.

Usage: -R. Report type can be one of the following:

Project Report - Generates a report in the format that is specified by the -F argument. The runner will save the report files to the directory that the -f argument specifies. Depending on the -A argument value, the files can be organized into subdirectories.

TestSuite Report - As above, but for TestSuites.

TestCase Report - As above, but for TestCases.

JUnit-Style HTML Report - Generates a report as JUnit-style HTML files. See JUnit-Style HTML Reports. When this value is used, the runner ignores the -F and -A arguments.

Data Export - Generates XML files with report data. See Data Export. When you use this argument, -F must be XML or must not be specified.

Use the -f argument to specify the directory, where the runner will save generated report files.

使用這個你task可能是:

// execute SOAPUI 
task executeSOAPUI(type: SoapUITask){ 
    // simply pass the project path as argument, 
    // note that the extra " are needed 
    soapUIArgs = '-f "path/of/outputReports" -R"JUnit-Style HTML Report" "/path/of/SOAPUI project xml/src/PCDEMO-soapui-project.xml"' 
} 

聲明:我沒有PRO版本,所以我無法測試任何我給的答案的選項。

+0

作爲建議我已運行下面的代碼: 任務executeSOAPUI(類型:SoapUITask){// 簡單地將項目路徑作爲參數, //注意,額外的「需要 soapUIArgs =「-f「/路徑//SOAPUI /編譯/ soapUI的-報告-HTML」 -j 「/路徑/ SOAPUI項目XML/src目錄/ project.xml中」」 } 但它與下面的錯誤encontered的/的: 的java.lang。例外:無法加載SoapUI項目文件[「/ path/of/SOAPUI project xml/src/project.xml」] 任何想法? – user2530711

+0

@ user2530711您擁有PRO版本?並且是您的'/ path/of/SOAPUI項目xml/src/pr oject.xml'項目路徑?你可以先嚐試從命令行直接運行以檢查它是否在從gradle執行之前正常工作? '/SOAPUIpath/SoapUI-5.1.2/bin/testrunner.sh -f「/ path/of/SOAPUI/build/soapui-reports-html」-j「/ path/of/SOAPUI project xml/src/project.xml 「' – albciff

+0

感謝您的幫助。我能夠在特定的文件夾中看到失敗的日誌txt文件,儘管它不會保存傳遞的OK.txt文件。 index.html尚未創建。運行gradle構建後,我收到以下錯誤:進程'命令/SOAPUIpath/SoapUI-5.1.2/bin/testrunner.sh'以非零退出值255結束 – user2530711

0

我將這個答案作爲一個單獨的POST發佈,因爲我認爲這是一個很好的選擇,因爲誰沒有PRO版本,並且有足夠的空間來存放它們。

因此,可能的選擇是生成Junit Xml報告文件,然後使用Xml報告和Xslt轉換生成Html。

要生成Junit Xml報告,您可以使用-j參數,也可以使用-f來指定文件夾。

然後您可以創建Gradle任務來執行XSLT轉換(我的解決方案基於this solution on github)。

所以你build.gradle可能是:

repositories {  
    maven { url "http://repo.maven.apache.org/maven2" } 
} 

configurations { 
    antClasspath 
} 
// dependency for XMLResultAggregator task 
dependencies { 
    antClasspath 'org.apache.ant:ant-junit:1.8.2' 
} 


class SoapUITask extends Exec { 
    String soapUIExecutable = '/SOAPUIpath/SoapUI-5.1.2/bin/testrunner.sh' 
    String soapUIArgs = '' 

    public SoapUITask(){ 
     super() 
     this.setExecutable(soapUIExecutable) 
    } 

    public void setSoapUIArgs(String soapUIArgs) { 
     this.args = "$soapUIArgs".trim().split(" ") as List 
    } 
} 

// execute SOAPUI 
task executeSOAPUI(type: SoapUITask){ 

    def reportPath = 'path/of/outputReports' 

    soapUIArgs = '-f "' + reportPath + '" -j "/path/of/SOAPUI project xml/src/PCDEMO-soapui-project.xml"' 

    // perform the xslt 
    doLast { 
     soapuiXmlToHtml(reportPath) 
    } 

} 

// task to perform the XSLT 
def soapuiXmlToHtml(resultsDir) { 
    def targetDir = new File(resultsDir, 'html') 

    ant.taskdef(
     name: 'junitreport', 
     classname: 'org.apache.tools.ant.taskdefs.optional.junit.XMLResultAggregator', 
     classpath: configurations.antClasspath.asPath 
    ) 

    ant.junitreport(todir: resultsDir) { 
     fileset(dir: resultsDir, includes: 'TEST-*.xml') 
     report(todir: targetDir, format: "frames") 
    } 
} 

然後你就可以調用gradle executeSOAPUI和你的JUnit HTML報告將在path/of/outputReports/html/文件夾中生成。

希望它有幫助,