4

How can I load the data dynamically from a .properties file to my jBehave story file? I have been using $ in my story file like:

When the stock is traded at price : $<price>
Then the alert status should be $<status>

I am trying to fetch the values of and from properties file placed under my src/test/resources folder and included my .properties file in the pom.xml like

    <testResource>
<directory>${basedir}/src/test/resources</directory>
<filtering>false</filtering>
<includes>
include>**/*.properties</include>
</includes>
    </testResource>

But still its not working. When I try running "mvn integration-test" on my cmd. It throws me this exception

org.json.JSONException: A JSONObject text must begin with '{' at character 1
    at org.json.JSONTokener.syntaxError(JSONTokener.java:410)
    at org.json.JSONObject.<init>(JSONObject.java:179)
    at org.json.JSONObject.<init>(JSONObject.java:402)....

I am not sure where am I going wrong. Please help me out. Awaiting reply!! -Tester

1 Answers1

0

The parameters are provided by the Examples statement. You are probably familiar with this part but did not include it in your sample story:

When the stock is traded at price : <price>
Then the alert status should be <status>
Examples:
|price|status|
|10.00|low|
|20.00|medium|
|50.00|high|

I don't believe using $ in combination with <> is valid. I recommend using <> instead of $ because the latter can be ambiguous when JBehave attempts to find matching steps.

What you might not be aware of, however, is that the last four lines of the story above (Examples and the three data lines) can be saved as a text file and then be referred to in the story by filename, allowing the examples table to be dynamically altered.

Examples:
TableFiles/storystats.table

Perhaps this is what you're looking for.

Bill Hileman
  • 2,798
  • 2
  • 17
  • 24