Robot Framework
Since Camel 3.0
Both producer and consumer are supported
The robotframework: component allows for processing camel exchanges in acceptance test suites which are already implemented with its own DSL. The depending keyword libraries that can be used inside test suites implemented in Robot DSL, could have been implemented either via Java or Python.
This component will let you execute business logic of acceptance test cases in Robot language on which you can pass parameters to feed data via power of Camel Routes. However, there is no reverse binding of parameters back where you can pass values back into Camel exchange. Therefore, for that reason, it actually acts like a template language passing camel exchanges by binding data into the test cases implemented.
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-robotframework</artifactId>
<version>x.x.x</version> <!-- use the same version as your Camel core version -->
</dependency> URI format
robotframework:resourceUri[?options]
Where resourceUri is the file system path of the test suite file (such as folder/mytests.robot) or directory to run. It is passed to Robot Framework as is, so a relative path is resolved against the current working directory. A scheme such as classpath: or file: is not supported.
| Robot Framework runs in the JVM of the application and redirects the JVM wide standard output and standard error during a run. The component therefore runs one Robot Framework execution at a time in a JVM: concurrent exchanges, consumers and routes wait for the run in progress to complete. |
Configuring Options
Camel components are configured on two separate levels:
-
component level
-
endpoint level
Configuring Component Options
At the component level, you set general and shared configurations that are, then, inherited by the endpoints. It is the highest configuration level.
For example, a component may have security settings, credentials for authentication, urls for network connection and so forth.
Some components only have a few options, and others may have many. Because components typically have pre-configured defaults that are commonly used, then you may often only need to configure a few options on a component; or none at all.
You can configure components using:
-
the Component DSL.
-
in a configuration file (
application.properties,*.yamlfiles, etc). -
directly in the Java code.
Configuring Endpoint Options
You usually spend more time setting up endpoints because they have many options. These options help you customize what you want the endpoint to do. The options are also categorized into whether the endpoint is used as a consumer (from), as a producer (to), or both.
Configuring endpoints is most often done directly in the endpoint URI as path and query parameters. You can also use the Endpoint DSL and DataFormat DSL as a type safe way of configuring endpoints and data formats in Java.
A good practice when configuring options is to use Property Placeholders.
Property placeholders provide a few benefits:
-
They help prevent using hardcoded urls, port numbers, sensitive information, and other settings.
-
They allow externalizing the configuration from the code.
-
They help the code to become more flexible and reusable.
The following two sections list all the options, firstly for the component followed by the endpoint.
Component Options
The Robot Framework component supports the following options which are listed below.
| Name | Description | Default | Type |
|---|---|---|---|
Whether to also pass the exchange properties to the test, as properties.name variables. By default only the message body, headers and exchange variables are passed. | false | boolean | |
Whether the CamelRobotResourceUri header can set the test suite file or directory to run instead of the resourceUri of the endpoint. Enabling this lets a message choose which tests run, which is a security risk if the header comes from an untrusted sender, so use this with care. | false | boolean | |
The path of a text file to read more robot command line arguments from, one per line (the robot --argumentfile option). | String | ||
Creates combined statistics based on tags, in the format tags:name, which are added to the Statistics by Tag table (the robot --tagstatcombine option). The tags can be combined with AND, OR and NOT, such as tag1ANDtag2:My_name. Separate several entries with comma. | String | ||
Deprecated since Robot Framework 4.0 (the robot --critical option): a test case that has none of these tags is marked as skipped instead of failed when it fails. Separate several tags with comma. | String | ||
The path of a debug file that Robot Framework writes during the execution (the robot --debugfile option), relative to outputDirectory unless absolute. Not written unless set. | String | ||
The documentation of the top-level test suite (the robot --doc option). If the value is the path of an existing file, Robot Framework reads the documentation from that file. | String | ||
Whether to run in dry run mode (the robot --dryrun option): Robot Framework verifies the test data and runs the test cases without executing the keywords of test libraries. Useful to validate the syntax of the test data. | false | boolean | |
Selects the test cases not to run by tag (the robot --exclude option). These test cases are not run even if they match includes. Separate several tags with comma. | String | ||
Whether to stop the test execution as soon as a test case fails (the robot --exitonfailure option). The remaining test cases are marked as failed without running. | false | boolean | |
Selects the test cases to run by tag (the robot --include option). A tag can be a pattern, and tags can be combined with AND, OR and NOT, such as fooANDbar. Separate several tags with comma. | String | ||
A single listener that gets notified of the test execution (the robot --listener option), as a class name or the path of a listener file, with arguments after the name separated with colon. Use listeners for several. | String | ||
Listeners that get notified of the test execution, such as when test cases start and end (the robot --listener option). A listener is a class name or the path of a listener file, and arguments can be given after the name separated with colon, such as MyListener:arg1:arg2. Separate several listeners with comma. | String | ||
The path of the HTML log file (the robot --log option), relative to outputDirectory unless absolute. Robot Framework uses log.html by default; NONE disables it. | String | ||
The threshold level for logging (the robot --loglevel option): TRACE, DEBUG, INFO (the default of Robot Framework), WARN or NONE. Use LEVEL:DEFAULT, such as DEBUG:INFO, to also set the log level that the log file shows by default. | String | ||
The title of the HTML log file (the robot --logtitle option). By default the suite name followed by Test Log. | String | ||
Metadata of the top-level test suite, in the format name:value (the robot --metadata option). Separate several entries with comma. | String | ||
ANSI color use in the console output (the robot --consolecolors option): auto (the default, colors on Unix and when output is redirected to a terminal, but not on Windows), on (always on Unix), ansi (like on but with ANSI codes on Windows too), or off (never). | String | ||
Deprecated Deprecated: the robot --monitorwidth option was removed in Robot Framework 3.0. This option is ignored. | String | ||
The name of the top-level test suite (the robot --name option). By default Robot Framework derives it from the name of the test suite file or directory. | String | ||
Deprecated since Robot Framework 4.0 (the robot --noncritical option, an alias of --skiponfailure): a test case that has one of these tags is marked as skipped instead of failed when it fails. Separate several tags with comma. | String | ||
Whether the return code in the CamelRobotReturnCode header is 0 even if test cases fail (the robot --nostatusrc option). Error codes, such as for invalid test data, are returned as usual. | false | boolean | |
The path of the XML output file (the robot --output option), relative to outputDirectory unless absolute. Robot Framework uses output.xml by default; NONE disables it, which also disables the log file. | String | ||
The directory where Robot Framework writes the output files (the robot --outputdir option). The relative paths of output, log, report, xunitFile and debugFile are resolved against it. By default the current working directory. | String | ||
Randomizes the execution order (the robot --randomize option): all (suites and test cases), suites, tests or none. Add :seed to use a given integer random seed, such as tests:1234. | String | ||
The path of the HTML report file (the robot --report option), relative to outputDirectory unless absolute. Robot Framework uses report.html by default; NONE disables it. | String | ||
The background colors of the HTML report file, in the order passed:failed:skipped, where skipped can be omitted (the robot --reportbackground option). Color names and codes both work, such as green:red:yellow. | String | ||
The title of the HTML report file (the robot --reporttitle option). By default the suite name followed by Test Report. | String | ||
Whether to run the test suite even if it has no test cases, for example when includes or excludes match none (the robot --runemptysuite option). Otherwise an empty test suite is an error. | false | boolean | |
The path of the XML output file of an earlier run, to run again only the test cases that failed in it (the robot --rerunfailed option). | String | ||
Deprecated Deprecated: the robot --runmode option was removed in Robot Framework 2.8. Use dryrun, exitOnFailure, skipTeardownOnExit and randomize instead. This option is ignored. | String | ||
Whether to skip the teardowns when the test execution is stopped prematurely, such as with exitOnFailure (the robot --skipteardownonexit option). | false | boolean | |
Deprecated Deprecated: the robot --splitoutputs option was removed in Robot Framework 3.0. This option is ignored. | String | ||
Selects the test suites to run by name (the robot --suite option). The name can be a pattern and contain the parent suite name, such as Parent.Suite. Separate several names with comma. | String | ||
How many suite levels to show in the Statistics by Suite table of the log and report files (the robot --suitestatlevel option). By default all levels are shown. | String | ||
Deprecated Deprecated: the robot --summarytitle option was removed in Robot Framework 3.0. This option is ignored. | String | ||
Adds documentation to the tags matching a pattern, in the format pattern:doc (the robot --tagdoc option). Separate several entries with comma. | String | ||
Tags that are set to all executed test cases (the robot --settag option). Separate several tags with comma. | String | ||
Excludes the matching tags from the Statistics by Tag table of the log and report files (the robot --tagstatexclude option). A tag can be a pattern. Separate several tags with comma. | String | ||
Includes only the matching tags in the Statistics by Tag table of the log and report files (the robot --tagstatinclude option). A tag can be a pattern. Separate several tags with comma. | String | ||
Adds external links to the Statistics by Tag table, in the format pattern:link:title (the robot --tagstatlink option). Separate several entries with comma. | String | ||
Selects the test cases to run by name or long name, such as Parent.Test (the robot --test option). The name is case and space insensitive, and can be a pattern with * and ? wildcards. Separate several names with comma. | String | ||
Whether to add a timestamp in the format YYYYMMDD-hhmmss to the names of all output files, between the base name and the extension (the robot --timestampoutputs option). | false | boolean | |
Variable files to read variables from (the robot --variablefile option). Arguments to a variable file can be given after its path, separated with colon, such as vars.py:arg1. Separate several files with comma. | String | ||
Variables in the format name:value to pass to Robot Framework (the robot --variable option). Separate several variables with comma. When a variable is also set by the exchange message (body, headers or exchange variables), the message value takes precedence over the endpoint variable on the same name. | String | ||
Deprecated Deprecated: the robot --warnonskippedfiles option was removed in Robot Framework 3.0. This option is ignored. | false | boolean | |
The path of the xUnit compatible XML result file (the robot --xunit option), relative to outputDirectory unless absolute. If not set, the component uses TEST-{resourceUri}.xml (the path of the test suite with its blanks replaced by underscores), so the file is always written. | String | ||
Allows for bridging the consumer to the Camel routing Error Handler, which mean any exceptions (if possible) occurred while the Camel consumer is trying to pickup incoming messages, or the likes, will now be processed as a message and handled by the routing Error Handler. Important: This is only possible if the 3rd party component allows Camel to be alerted if an exception was thrown. Some components handle this internally only, and therefore bridgeErrorHandler is not possible. In other situations we may improve the Camel component to hook into the 3rd party component and make this possible for future releases. By default the consumer will use the org.apache.camel.spi.ExceptionHandler to deal with exceptions, that will be logged at WARN or ERROR level and ignored. | false | boolean | |
Whether the producer should be started lazy (on the first message). By starting lazy you can use this to allow CamelContext and routes to startup in situations where a producer may otherwise fail during starting and cause the route to fail being started. By deferring this startup to be lazy then the startup failure can be handled during routing messages via Camel’s routing error handlers. Beware that when the first message is processed then creating and starting the producer may take a little time and prolong the total processing time of the processing. | false | boolean | |
Whether autowiring is enabled. This is used for automatic autowiring options (the option must be marked as autowired) by looking up in the registry to find if there is a single instance of matching type, which then gets configured on the component. This can be used for automatic configuring JDBC data sources, JMS connection factories, AWS Clients, etc. | true | boolean | |
The shared configuration of the endpoints. Each endpoint gets a copy of it, which its own options then change. | RobotFrameworkCamelConfiguration |
Endpoint Options
The Robot Framework endpoint is configured using URI syntax:
robotframework:resourceUri
With the following path and query parameters:
Path Parameters
| Name | Description | Default | Type |
|---|---|---|---|
Required Path to the resource. You can prefix with: classpath, file, http, ref, or bean. classpath, file and http loads the resource using these protocols (classpath is default). ref will lookup the resource in the registry. bean will call a method on a bean to be used as the resource. For bean you can specify the method name after dot, eg bean:myBean.myMethod. | String |
Query Parameters
| Name | Description | Default | Type |
|---|---|---|---|
Whether to also pass the exchange properties to the test, as properties.name variables. By default only the message body, headers and exchange variables are passed. | false | boolean | |
Whether the CamelRobotResourceUri header can set the test suite file or directory to run instead of the resourceUri of the endpoint. Enabling this lets a message choose which tests run, which is a security risk if the header comes from an untrusted sender, so use this with care. | false | boolean | |
The path of a text file to read more robot command line arguments from, one per line (the robot --argumentfile option). | String | ||
Creates combined statistics based on tags, in the format tags:name, which are added to the Statistics by Tag table (the robot --tagstatcombine option). The tags can be combined with AND, OR and NOT, such as tag1ANDtag2:My_name. Separate several entries with comma. | String | ||
Deprecated since Robot Framework 4.0 (the robot --critical option): a test case that has none of these tags is marked as skipped instead of failed when it fails. Separate several tags with comma. | String | ||
The path of a debug file that Robot Framework writes during the execution (the robot --debugfile option), relative to outputDirectory unless absolute. Not written unless set. | String | ||
The documentation of the top-level test suite (the robot --doc option). If the value is the path of an existing file, Robot Framework reads the documentation from that file. | String | ||
Whether to run in dry run mode (the robot --dryrun option): Robot Framework verifies the test data and runs the test cases without executing the keywords of test libraries. Useful to validate the syntax of the test data. | false | boolean | |
Selects the test cases not to run by tag (the robot --exclude option). These test cases are not run even if they match includes. Separate several tags with comma. | String | ||
Whether to stop the test execution as soon as a test case fails (the robot --exitonfailure option). The remaining test cases are marked as failed without running. | false | boolean | |
Selects the test cases to run by tag (the robot --include option). A tag can be a pattern, and tags can be combined with AND, OR and NOT, such as fooANDbar. Separate several tags with comma. | String | ||
A single listener that gets notified of the test execution (the robot --listener option), as a class name or the path of a listener file, with arguments after the name separated with colon. Use listeners for several. | String | ||
Listeners that get notified of the test execution, such as when test cases start and end (the robot --listener option). A listener is a class name or the path of a listener file, and arguments can be given after the name separated with colon, such as MyListener:arg1:arg2. Separate several listeners with comma. | String | ||
The path of the HTML log file (the robot --log option), relative to outputDirectory unless absolute. Robot Framework uses log.html by default; NONE disables it. | String | ||
The threshold level for logging (the robot --loglevel option): TRACE, DEBUG, INFO (the default of Robot Framework), WARN or NONE. Use LEVEL:DEFAULT, such as DEBUG:INFO, to also set the log level that the log file shows by default. | String | ||
The title of the HTML log file (the robot --logtitle option). By default the suite name followed by Test Log. | String | ||
Metadata of the top-level test suite, in the format name:value (the robot --metadata option). Separate several entries with comma. | String | ||
ANSI color use in the console output (the robot --consolecolors option): auto (the default, colors on Unix and when output is redirected to a terminal, but not on Windows), on (always on Unix), ansi (like on but with ANSI codes on Windows too), or off (never). | String | ||
Deprecated Deprecated: the robot --monitorwidth option was removed in Robot Framework 3.0. This option is ignored. | String | ||
The name of the top-level test suite (the robot --name option). By default Robot Framework derives it from the name of the test suite file or directory. | String | ||
Deprecated since Robot Framework 4.0 (the robot --noncritical option, an alias of --skiponfailure): a test case that has one of these tags is marked as skipped instead of failed when it fails. Separate several tags with comma. | String | ||
Whether the return code in the CamelRobotReturnCode header is 0 even if test cases fail (the robot --nostatusrc option). Error codes, such as for invalid test data, are returned as usual. | false | boolean | |
The path of the XML output file (the robot --output option), relative to outputDirectory unless absolute. Robot Framework uses output.xml by default; NONE disables it, which also disables the log file. | String | ||
The directory where Robot Framework writes the output files (the robot --outputdir option). The relative paths of output, log, report, xunitFile and debugFile are resolved against it. By default the current working directory. | String | ||
Randomizes the execution order (the robot --randomize option): all (suites and test cases), suites, tests or none. Add :seed to use a given integer random seed, such as tests:1234. | String | ||
The path of the HTML report file (the robot --report option), relative to outputDirectory unless absolute. Robot Framework uses report.html by default; NONE disables it. | String | ||
The background colors of the HTML report file, in the order passed:failed:skipped, where skipped can be omitted (the robot --reportbackground option). Color names and codes both work, such as green:red:yellow. | String | ||
The title of the HTML report file (the robot --reporttitle option). By default the suite name followed by Test Report. | String | ||
Whether to run the test suite even if it has no test cases, for example when includes or excludes match none (the robot --runemptysuite option). Otherwise an empty test suite is an error. | false | boolean | |
The path of the XML output file of an earlier run, to run again only the test cases that failed in it (the robot --rerunfailed option). | String | ||
Deprecated Deprecated: the robot --runmode option was removed in Robot Framework 2.8. Use dryrun, exitOnFailure, skipTeardownOnExit and randomize instead. This option is ignored. | String | ||
Whether to skip the teardowns when the test execution is stopped prematurely, such as with exitOnFailure (the robot --skipteardownonexit option). | false | boolean | |
Deprecated Deprecated: the robot --splitoutputs option was removed in Robot Framework 3.0. This option is ignored. | String | ||
Selects the test suites to run by name (the robot --suite option). The name can be a pattern and contain the parent suite name, such as Parent.Suite. Separate several names with comma. | String | ||
How many suite levels to show in the Statistics by Suite table of the log and report files (the robot --suitestatlevel option). By default all levels are shown. | String | ||
Deprecated Deprecated: the robot --summarytitle option was removed in Robot Framework 3.0. This option is ignored. | String | ||
Adds documentation to the tags matching a pattern, in the format pattern:doc (the robot --tagdoc option). Separate several entries with comma. | String | ||
Tags that are set to all executed test cases (the robot --settag option). Separate several tags with comma. | String | ||
Excludes the matching tags from the Statistics by Tag table of the log and report files (the robot --tagstatexclude option). A tag can be a pattern. Separate several tags with comma. | String | ||
Includes only the matching tags in the Statistics by Tag table of the log and report files (the robot --tagstatinclude option). A tag can be a pattern. Separate several tags with comma. | String | ||
Adds external links to the Statistics by Tag table, in the format pattern:link:title (the robot --tagstatlink option). Separate several entries with comma. | String | ||
Selects the test cases to run by name or long name, such as Parent.Test (the robot --test option). The name is case and space insensitive, and can be a pattern with * and ? wildcards. Separate several names with comma. | String | ||
Whether to add a timestamp in the format YYYYMMDD-hhmmss to the names of all output files, between the base name and the extension (the robot --timestampoutputs option). | false | boolean | |
Variable files to read variables from (the robot --variablefile option). Arguments to a variable file can be given after its path, separated with colon, such as vars.py:arg1. Separate several files with comma. | String | ||
Variables in the format name:value to pass to Robot Framework (the robot --variable option). Separate several variables with comma. When a variable is also set by the exchange message (body, headers or exchange variables), the message value takes precedence over the endpoint variable on the same name. | String | ||
Deprecated Deprecated: the robot --warnonskippedfiles option was removed in Robot Framework 3.0. This option is ignored. | false | boolean | |
The path of the xUnit compatible XML result file (the robot --xunit option), relative to outputDirectory unless absolute. If not set, the component uses TEST-{resourceUri}.xml (the path of the test suite with its blanks replaced by underscores), so the file is always written. | String | ||
If the polling consumer did not poll any files, you can enable this option to send an empty message (no body) instead. | false | boolean | |
Allows for bridging the consumer to the Camel routing Error Handler, which mean any exceptions (if possible) occurred while the Camel consumer is trying to pickup incoming messages, or the likes, will now be processed as a message and handled by the routing Error Handler. Important: This is only possible if the 3rd party component allows Camel to be alerted if an exception was thrown. Some components handle this internally only, and therefore bridgeErrorHandler is not possible. In other situations we may improve the Camel component to hook into the 3rd party component and make this possible for future releases. By default the consumer will use the org.apache.camel.spi.ExceptionHandler to deal with exceptions, that will be logged at WARN or ERROR level and ignored. | false | boolean | |
To let the consumer use a custom ExceptionHandler. Notice if the option bridgeErrorHandler is enabled then this option is not in use. By default the consumer will deal with exceptions, that will be logged at WARN or ERROR level and ignored. | ExceptionHandler | ||
Sets the exchange pattern when the consumer creates an exchange. Enum values:
| ExchangePattern | ||
A pluggable org.apache.camel.PollingConsumerPollingStrategy allowing you to provide your custom implementation to control error handling usually occurred during the poll operation before an Exchange have been created and being routed in Camel. | PollingConsumerPollStrategy | ||
Whether the producer should be started lazy (on the first message). By starting lazy you can use this to allow CamelContext and routes to startup in situations where a producer may otherwise fail during starting and cause the route to fail being started. By deferring this startup to be lazy then the startup failure can be handled during routing messages via Camel’s routing error handlers. Beware that when the first message is processed then creating and starting the producer may take a little time and prolong the total processing time of the processing. | false | boolean | |
The number of subsequent error polls (failed due some error) that should happen before the backoffMultipler should kick-in. | int | ||
The number of subsequent idle polls that should happen before the backoffMultipler should kick-in. | int | ||
To let the scheduled polling consumer backoff if there has been a number of subsequent idles/errors in a row. The multiplier is then the number of polls that will be skipped before the next actual attempt is happening again. When this option is in use then backoffIdleThreshold and/or backoffErrorThreshold must also be configured. | int | ||
Milliseconds before the next poll. | 500 | long | |
If greedy is enabled, then the ScheduledPollConsumer will run immediately again, if the previous run polled 1 or more messages. | false | boolean | |
How long a poll may run before the health check of the consumer reports DOWN. The health check is otherwise based on the polls that are done, so it stays UP while a poll hangs, for example on a read without timeout from a connection that went silent. A poll includes routing the messages it polled, so set this above the longest poll you expect. The poll is not interrupted. The value is in millis (not affected by timeUnit). The default 0 turns this off. | 0 | long | |
Milliseconds before the first poll starts. | 1000 | long | |
Specifies a maximum limit of number of fires. So if you set it to 1, the scheduler will only fire once. If you set it to 5, it will only fire five times. A value of zero or negative means fire forever. | 0 | long | |
The consumer logs a start/complete log line when it polls. This option allows you to configure the logging level for that. Enum values:
| TRACE | LoggingLevel | |
Allows for configuring a custom/shared thread pool to use for the consumer. By default each consumer has its own single threaded thread pool. | ScheduledExecutorService | ||
To use a cron scheduler from either camel-spring or camel-quartz component. Use value spring or quartz for built in scheduler. | none | Object | |
To configure additional properties when using a custom scheduler or any of the Quartz, Spring based scheduler. This is a multi-value option with prefix: scheduler. | Map | ||
Whether the scheduler should be auto started. | true | boolean | |
Time unit for initialDelay and delay options. Enum values:
| MILLISECONDS | TimeUnit | |
Controls if fixed delay or fixed rate is used. See ScheduledExecutorService in JDK for details. | true | boolean |
Message Headers
The Robot Framework component supports the following message header(s), which is/are listed below:
| Name | Description | Default | Type |
|---|---|---|---|
| Constant: | The Robot Framework variables that the component passed to the test run, as name:value strings, created from the message body, headers, exchange variables and (with allowContextMapAll) exchange properties. | List | |
| Constant: | The return code of the Robot Framework run: 0 when all test cases passed, otherwise the number of failed test cases (at most 250), or 251 to 255 for errors, such as 252 for invalid test data or command line options. A failed run does not fail the exchange. | Integer | |
CamelRobotResourceUri (common) Constant: | The path of the test suite file or directory to run instead of the resourceUri of the endpoint. Only used when allowTemplateFromHeader is enabled, and removed from the message then. | String |
Message Body
The message body at each side of the Robot Framework component: Consumer is the body of the messages the consumer creates, Consumer reply the bodies a consumer that answers its caller can reply with, Producer input the bodies the producer can send or write, and Producer output the body after the producer.
| Side | Body | Description |
|---|---|---|
Consumer |
| No body: each poll runs the test, and the outcome is in the CamelRobotReturnCode header (0 when all tests pass). |
Producer input |
| The test gets the body converted to a String as the body variable, the headers as headers.name, the exchange variables as variables.name and, with allowContextMapAll, the exchange properties as properties.name; a null value is not passed. |
Producer output |
| The body is left as it is. The CamelRobotReturnCode header has the return code of the run (0 when all tests pass, non-zero otherwise), and CamelRobotVariables the variables passed to it; a failed test does not fail the exchange. |
The bodies are the ones with the default options. A side that is not listed is not known, and tooling does not guess it. The carriers, the sides and the tools that use them are described in Message Body Types.
Examples
For example, you could use something like:
-
Java
-
XML
-
YAML
from("direct:setVariableCamelBody")
.to("robotframework:src/test/resources/org/apache/camel/component/robotframework/set_variable_camel_body.robot"); <route>
<from uri="direct:setVariableCamelBody"/>
<to uri="robotframework:src/test/resources/org/apache/camel/component/robotframework/set_variable_camel_body.robot"/>
</route> - route:
from:
uri: direct:setVariableCamelBody
steps:
- to:
uri: robotframework:src/test/resources/org/apache/camel/component/robotframework/set_variable_camel_body.robot To use a robot test case to execute and collect the results and pass them to generate a custom report if such need happens
It’s possible to specify what template the component should use dynamically via a header, so for example:
from("direct:in")
.setHeader("CamelRobotResourceUri").constant("path/to/my/template.robot")
.to("robotframework:dummy?allowTemplateFromHeader=true"); Robotframework component helps you pass values into robot test cases with the similar approach how you would be able to pass values using Camel Simple Language. Components support passing values in three different ways. Exchange body, headers, and properties.
from("direct:in")
.setBody(constant("Hello Robot"))
.setHeader("CamelRobotResourceUri").constant("path/to/my/template.robot")
.to("robotframework:dummy?allowTemplateFromHeader=true"); And the template.robot file:
*** Test Cases ***
Set Variable Camel Body Test Case
${myvar} = Set Variable ${body}
Should Be Equal ${myvar} ${body} from("direct:in")
.setHeader("testHeader", constant("testHeaderValue"))
.setHeader("CamelRobotResourceUri").constant("path/to/my/template.robot")
.to("robotframework:dummy?allowTemplateFromHeader=true"); And the template.robot file:
*** Test Cases ***
Set Variable Camel Header Test Case
${myvar} = Set Variable ${headers.testHeader}
Should Be Equal ${myvar} ${headers.testHeader} from("direct:in")
.setProperty("testProperty", constant("testPropertyValue"))
.setHeader("CamelRobotResourceUri").constant("path/to/my/template.robot")
.to("robotframework:dummy?allowTemplateFromHeader=true&allowContextMapAll=true"); And the template.robot file:
*** Test Cases ***
Set Variable Camel Property Test Case
${myvar} = Set Variable ${properties.testProperty}
Should Be Equal ${myvar} ${properties.testProperty} Please note that when you pass values through Camel Exchange to test cases, they will be available as case-sensitive body, headers.[yourHeaderName], variables.[yourVariableName] and properties.[yourPropertyName]. The exchange properties are only passed when allowContextMapAll=true.
The values are passed as strings. A null body, header, variable or property is not passed at all, as a Robot Framework variable cannot be null. So with no message body (such as the consumer, which polls with an empty exchange), there is no ${body} variable. A test can give such a variable a default value in its own * Variables * table, as the values passed from Camel override that table.
Compare the values as strings, for example with Should Be Equal. Do not put them into an expression that Robot Framework evaluates as Python, such as Should Be True or Evaluate, as the message body and headers may come from an untrusted sender. |