FitNesse: Is it required to write fixtures to add and use variables on test page - fitnesse

I am trying to add a table of variables and its values in FitNesse suite page, so that it can be used for all my tests.
I am using xmlHtttp tests for SOAP web services and fhoeben/hsac-fitnesse-fixtures (slim) for this.
Is it required to write separate fixtures to add a table?

Yes you can.
Using a scenario allows us to generate multiple request, only changing certain values.
!*> Scenario definition
!define POST_BODY_2 { {{{
<s11:Envelope xmlns:s11="http://schemas.xmlsoap.org/soap/envelope/">
<s11:Body>
<ns1:GetCityWeatherByZIP xmlns:ns1="http://ws.cdyne.com/WeatherWS/">
<ns1:ZIP>#{zip}</ns1:ZIP>
</ns1:GetCityWeatherByZIP>
</s11:Body>
</s11:Envelope>
}}} }
|script|xml http test|
|table template |send request |
|post |${POST_BODY_2} |to |${URL} |
|check |response status|200 |
|show |response |
|register prefix|weather |for namespace|http://ws.cdyne.com/WeatherWS/|
|$City= |xPath |//weather:City/text() |
*!
|send request |
|zip |City? |
|10007|New York |
|94102|San Francisco|
In this example the variable zip is used so the request is sent with either 10007 or 94102.

Related

How to fetch the test result and code coverate stats in fastlane to notify else where?

Am using fastlane for my app and right now have configured to generate HTML reports for tests & code coverage.
Is it possible to fetch the stats as seen on command line so that I could use it to notify on separate chat app which I use ?
+------------------+---------+
| xcov Coverage Report |
+------------------+---------+
| 123456789012.app | 100.00% |
+------------------+---------+
+--------------------+---+
| Test Results |
+--------------------+---+
| Number of tests | 1 |
| Number of failures | 0 |
+--------------------+---+
You can use tools like xcov and gcovr to gather coverage data on top of fastlane. Links are as follows to the documentation:
https://docs.fastlane.tools/actions/gcovr/
https://docs.fastlane.tools/actions/xcov/
For test results, i believe there is no straight forward answer for that because the logs you see in the console are not directly exposed by Xcode.
When you are running your application, Xcode creates a file called TestSummaries.plist, which has all the steps and results.
Some of the developers were in your position, where they ended up writing a macOS application, just to parse the plist and get all the data. Following is the reference to the project.
https://github.com/nacuteodor/ProcessTestSummaries
https://github.com/KrauseFx/trainer
Lastly, go through the following article which explains how test logs are structured in the testSummaries.plist
https://michele.io/test-logs-in-xcode/
Hope all the links and explanations help you out. :)

FitNesse: Is it possible to extract information from the response of a test step, and use this value in the next test step

I am wondering that is there any possibility in FitNesse, while executing the test stages, to get a value from the response of a test stage and use this value in the next test stage.
I am using hsac-fitnesse-fixtures and SOAP web services.
For example, we have 3 test stages, and value from the response of the first stage can automatically transfer to the second stage to get the response of the second stage.
When comparing with SOAP UI we have property transfer.
Example below:
We have request XML:
!define POST_BODY_2 { {{{
<ns1:ZIP>#{zip}</ns1:ZIP>
</s11:Envelope>
}}} }
Stage 1:
|check|xPath|//weather:City/text()|#{City}|
And we get a response XML that contains the city name, as here.
Is it possible to pass this city name as a value to the second test stage?
I.e we have another post XML request !define POST_BODY_3 and to this request can we pass the value (city value) and have the next response XML.
Stage 2 test:
|check |response status|200|
If you are using SLiM as test system, you can use slim symbol
$slimSymbol is a "runtime variable" used in SLiM test system. They are defined by using $slimSymbol= symtax in the test case, and the value will only be available in the runtime. Documentation here
In your case, you are using a decision table in the first test case. So instead of having only one output column, I guess you can do
#some setup here
| send request |
| zip | City? | City? |
| 10007 | New York | $response1= |
| 94102 | San Francisco | $response2= |
And in the later test case, you can refer to the city names using $response1 and $response2. Note that there isn't {} around the variables.

How to convert a parameter in FitNesse?

I am using FitNesse with Xebium for documenting/running automated test scripts.
I was wondering how these test scripts can be improved e.g. by removing duplication:
|scenario |Given a customer check with status positive|
|start app with customerId|1000001 |
|scenario |Given a customer check with status negative|
|start app with customerId|1000002 |
|scenario |Given a customer check with status error|
|start app with customerId|1000003 |
(... and so on)
I have the feeling that this can be put in one table, but how?
I know its an old post, but I believe you can plan your acceptance tests something like below
|start app |
|status |given customer|whatever validation?|
|positive|1000001 |works fine |
|negative|1000002 |can not be launched |
|error |1000003 |can not be launched |

Re-using Python's behave feature file for both Unit and Functional tests

The following Gherking test defines the desired behaviour for one of my servers:
Scenario Outline: Calling the server with a valid JSON
Given A GIS update server
When I call /update with the json in the file <filename>
Then the response status code is <status_code>
And the response is a valid JSON
And the response JSON contains the key status
And the response JSON contains the key timestamp
And the response JSON contains the key validity
Examples:
| filename | status_code |
| valid_minimal.json | 200 |
| valid_minimal_minified.json | 200 |
| valid_full.json | 200 |
| valid_full_minified.json | 200 |
| valid_full_some_nulls.json | 200 |
| valid_full_all_nulls.json | 200 |
I wrote this code for unit testing a Flask server. The steps file, which interpret the Gherkin directives, open a test client and make the necessary calls and assertions:
#given(u'A GIS update server')
def step_impl(context):
context.app = application.test_client()
The feature file is similar for unit and functional tests. The only difference is in a few steps file which would have to make HTTP calls rather than calling the test client's methods.
What's the right way to re-use this behave feature file by passing parameters to the steps file?
Expanding on Parva's comments, I suggest sending parameters via the command line which will be detected in your step definitions and adjust behaviour for unit vs functional testing (the decision of whether you separate your unit and functional tests for clarity is up to you ;).
There is an example given in the Behave documentation around Debug on error, which gives a good example of using environmental attributes in modifying the execution of your steps method:
# -- FILE: features/environment.py
# USE: BEHAVE_DEBUG_ON_ERROR=yes (to enable debug-on-error)
from distutils.util import strtobool as _bool
import os
BEHAVE_DEBUG_ON_ERROR = _bool(os.environ.get("BEHAVE_DEBUG_ON_ERROR", "no"))
def after_step(context, step):
if BEHAVE_DEBUG_ON_ERROR and step.status == "failed":
# -- ENTER DEBUGGER: Zoom in on failure location.
# NOTE: Use IPython debugger, same for pdb (basic python debugger).
import ipdb
ipdb.post_mortem(step.exc_traceback)
You may change that to detect a command line passed variable such as UNIT_TESTING and have it hit a different endpoint or perform alternate functionality for your tests.
REQUIRES: behave >= 1.2.5
I think, the test stage concept should help you with your needs. It allows you to use different step implementations for different test stages.
behave --stage=functional
If your changes are minor, use the userdata concept to pass a flag to your step implementation, like:
behave -D test_stage=unit …
behave -D test_stage=functional …

How do I compare xml output in a Cucumber step using a multiline string example?

Chargify has this Cucumber scenario in their docs.
Scenario: Retrieve a customer via my reference id (as an integer or simple string)
Given I have a customer with these attributes
| reference | first_name | last_name | email |
| 7890 | Joe | Blow | joe#example.com |
When I send a GET request to https://[#subdomain].chargify.com/customers/lookup.xml?reference=7890
Then the response status should be "200 OK"
And the response should be the xml:
"""
<?xml version="1.0" encoding="UTF-8"?>
<customer>
<id type="integer">`auto generated`</id>
<first_name>Joe</first_name>
<last_name>Blow</last_name>
<email>joe#example.com</email>
<organization>`your value`</organization>
<reference>7890</reference>
<created_at type="datetime">`auto generated`</created_at>
<updated_at type="datetime">`auto generated`</updated_at>
</customer>
"""
I'm trying to follow their approach in testing an API we're developing here, instead of checking for the tags one by one, like I we were doing before coming across this example.
So far no luck matching the response's output with the step's multiline string, due to formatting issues. Haven't found a way with Nokogiri nor with simple stripped string comparison.
Is there an elegant (and efficient) way to do this?
Update
Here's the cucumber step using Mark's solution:
Then /^I should see the following output$/ do |xml_output|
response = Hash.from_xml(page.body)
expected = Hash.from_xml(xml_output)
expected.diff(response).should == {}
end
You can use Hash.from_xml and then compare with Hash.diff. Comparing as hashes eliminates insignificant whitespace from messing up comparisons.
In case you don't want the dependency on ActiveSuport (for instance, if you are outside Rails), you might try the equivalent-xml gem. It allows you to write the above expectation as follows:
response = page.body
response.should be_equivalent_to(xml_output)

Resources