Creating a Jenkins test result template for Robot Framework tests that incorporates tags involves several steps. Below is a guide to help you achieve this. We'll cover:
Generating Robot Framework Test Results with Tags
Configuring Jenkins to Publish Robot Framework Test Results
Customizing the Test Result Template in Jenkins (if necessary)
Step 1: Generating Robot Framework Test Results with Tags
First, ensure your Robot Framework tests are properly tagged. You can add tags to your test cases like this:
robot
*** Test Cases ***
My Test Case
[Tags] Smoke Regression
# Your test steps here
When running your tests, use the --output option to specify the output file, and optionally, use --log and --report for logging and reporting, respectively. Tags will be included in the output file.
Step 2: Configuring Jenkins to Publish Robot Framework Test Results
Install the Necessary Plugin:
In your Jenkins instance, go to Manage Jenkins > Manage Plugins, and ensure you have the Robot Framework Plugin installed. If not, install it. This plugin allows Jenkins to parse and display Robot Framework test results.
Configure Your Jenkins Job:
Open your Jenkins job configuration.
In the Post-build Actions section, click on Publish Robot Framework test results.
Specify the path to your output.xml file (e.g., path/to/output.xml or use wildcards like **/output.xml if the file is in a subdirectory).
Save your changes.
Step 3: Customizing the Test Result Template (if necessary)
The Robot Framework Plugin for Jenkins provides a decent overview of test results, including tags. However, if you wish to further customize the appearance or layout of your test results (beyond the standard plugin capabilities), you might need to:
A. Leverage Plugin Capabilities (No Coding)
Check the plugin's documentation for any customization options that might have been added, such as configuring the display of certain fields or highlighting based on tags.
B. Create a Custom Dashboard View
Jenkins Dashboard: Use the Dashboard View plugin to create a custom dashboard. You can then add a Test Result Trend chart and filter it by tag, among other customizations.
C. Advanced Customization with Groovy (via Scriptler or Groovy Postbuild)
For deep customization, you might write a Groovy script to parse the output.xml, extract tag-specific data, and generate a custom HTML report.
Install Scriptler or use the Groovy Postbuild plugin.
Write a Groovy script to parse output.xml, focusing on tags. This involves XML parsing and potentially creating HTML content.
Example Groovy Snippet (simplified, you'll need to expand this based on your XML structure and desired output):
groovy
// Import necessary libraries for XML parsing and file operations
import groovy.xml.XmlSlurper
// Define the workspace path for accessing files
def workspacePath = env.WORKSPACE
// Parse the Robot Framework output.xml file
def outputXml = new XmlSlurper().parse(new File(workspacePath + '/output.xml'))
// Find all tests with a specific tag (e.g., 'Smoke')
def smokeTests = outputXml.testcase.findAll { it.tag.@name == 'Smoke' }
// Generate HTML content for the smoke tests
def htmlContent = "<html><body><h2>Smoke Tests</h2><ul>"
smokeTests.each {
// Add each test name as a list item
htmlContent += "<li>${it.@name}</li>"
}
htmlContent += "</ul></body></html>"
// Write the HTML content to a file in the workspace
new File(workspacePath + '/SmokeTests.html').write(htmlContent)
Publish this HTML as a post-build action using the Publish HTML reports plugin.
Note: The above Groovy script is a significant simplification. You'll need to adapt it to your specific requirements, especially the XML parsing part, as the structure of output.xml from Robot Framework can be complex. Always test your scripts in a non-production environment first.
Tags in Final Report:
The Robot Framework plugin will display tags associated with each test case in the test results.
You can filter tests by tags in the Jenkins UI after the plugin processes the output.xml file.
Custom scripts (like the Groovy example) can further process tags to create specialized reports, such as a dedicated page for "Smoke" tests.
Key Concepts for Beginners:
Robot Framework: An open-source test automation framework used for acceptance testing and acceptance test-driven development (ATDD).
Jenkins: An automation server that enables you to build, test, and deploy your projects in a controlled environment.
Tags: In Robot Framework, tags are used to categorize test cases, making it easier to run subsets of tests (e.g., smoke tests) or filter results.
output.xml: The XML file generated by Robot Framework containing detailed test results, including tags, which Jenkins can parse and display.