Gherkin steps - veepee-oss/gingerspec GitHub Wiki
GingerSpec contains tons of predefined Gherkin steps ready to use in your own features. The steps cover a wide range of functionality, from steps for testing Rest endpoints, perform front-end testing using selenium, and even for testing Kafka services!
Gingerspec steps are designed to allow the user to jump directly into the test implementation by using Gherkin language and without having to type any java code or worrying about any set-up. In order for the steps to be usable in a wide range of situations, they have to be very low level. The only downside to this is that it could result in very long and imperative-style scenarios. Fortunately, you can also have the flexibility to create your own steps, so you can get more declarative-style scenarios, better suited to be read by business and stakeholders
GingerSpec steps cover the following range of technologies
- Selenium steps
- Soap services steps
- SQL database steps
- SSH and bash steps
- File parsing steps
- Big data steps
- Kafka steps
- Mobile steps
- Rest steps
Also, check the automatically generated documentation for GIngerSpec here
Selenium steps
Steps for testing web applications (browser automation). Notice that the Feature contains the tag @web at the beginning. This tag is required when using the Selenium steps of GingerSpec. I recommend you to take a look at the documentation of the @web tag here. Tests will use the Chrome browser by default.
Also, take a look at the documentation for running selenium features. There you will find more examples and advance use cases, like how to run your tests in different browsers (Firefox, Safari, Opera, etc) or using a Selenium Grid.
@web
Feature: Testing basic functionality of a web page
Scenario: Fill the form and click the submit button
Given I go to 'http://demoqa.com/text-box'
And I type 'John' on the element with 'id:userName'
And I type '[email protected]' on the element with 'id:userEmail'
And I type '123 fake address' on the element with 'id:currentAddress'
When I scroll down until the element with 'id:submit' is visible
And I click on the element with 'id:submit'
Then at least '1' elements exists with 'id:output'
Check also these examples:
For a complete list of steps definitions related to Selenium, please check the corresponding class in the javadoc here
Soap services steps
Steps definitions for working with SOAP web services
Feature: communicating with a remote webservice
For this example, we are going to demonstrate how to execute the method of the Webservice
located in http://www.dneonline.com/calculator.asmx
Scenario: Execute "Add" operation
Given The webservice WSDL is located in 'http://www.dneonline.com/calculator.asmx?WSDL'
When I execute the method 'Add' based on 'schemas/AddRequest.xml' with:
| intA | 1 |
| intB | 1 |
Then The response matches the following cases:
| AddResult | equal | 2 |
When I execute the method 'Add' based on 'schemas/AddRequest.xml' with:
| intA | 3 |
| intB | 5 |
Then The response matches the following cases:
| AddResult | equal | 8 |
| AddResult | not equal | 10 |
Check also these examples:
For a complete list of steps definitions related to SOAP services, please check the corresponding class in the javadoc here
SQL database steps
Steps definitions for working with relational databases (PostgreSQL and MySQL)
@sql
Feature: SQL Database Steps
Scenario: Executing SELECT statements on a MySQL database
Given I connect with JDBC to database 'mysql' type 'mysql' on host '${MYSQL_HOST}' and port '3306' with user 'root' and password 'mysql'
Then I execute query 'CREATE TABLE IF NOT EXISTS weather1 (city varchar(80), temp_lo int, temp_hi int, prcp real, date date);'
Then I execute query 'TRUNCATE weather1'
Then I execute query 'INSERT INTO weather1 (city, temp_lo, temp_hi, prcp, date) VALUES ('San Francisco', 15, 43, 0.0, '2004-11-29');'
Then I execute query 'INSERT INTO weather1 (city, temp_lo, temp_hi, prcp, date) VALUES ('Kyiv', 5, 37, 0.4, '2014-11-29');'
Then I execute query 'INSERT INTO weather1 (city, temp_lo, temp_hi, prcp, date) VALUES ('Paris', 8, 37, 0.4, '2016-11-30');'
When I query the database with 'SELECT * FROM weather1;'
Then I check that result is:
| city | temp_lo | temp_hi | prcp | date |
| San Francisco | 15 | 43 | 0.0 | 2004-11-29 |
| Kyiv | 5 | 37 | 0.4 | 2014-11-29 |
| Paris | 8 | 37 | 0.4 | 2016-11-30 |
Then I check that table 'weather1' is iqual to
| city | temp_lo | temp_hi | prcp | date |
| San Francisco | 15 | 43 | 0.0 | 2004-11-29 |
| Kyiv | 5 | 37 | 0.4 | 2014-11-29 |
| Paris | 8 | 37 | 0.4 | 2016-11-30 |
Check also these examples:
For a complete list of steps definitions related to SQL, please check the corresponding class in the javadoc here
SSH and bash steps
Steps definitions for running bash commands and establishing SSH connections with a remote host
Feature: Example on how to execute commands in the system shell
Background: Connect to bootstrap machine
Given I open a ssh connection to '${SSH}' with user 'root' and password 'temporal'
Scenario: Default exit status - Successful (0)
Then I run 'ls /tmp' in the ssh connection
Scenario: Outbound Inbound file
When I outbound copy 'exampleJSON.conf' through a ssh connection to '/tmp/exampleJSON.conf'
Then I inbound copy '/tmp/exampleJSON.conf' through a ssh connection to 'fileFromSsh.conf'
Scenario: Default exit status - Check output
When I run 'ls -la /tmp' in the ssh connection
Then the command output contains 'total'
Check also these examples:
For a complete list of steps definitions related to SSH and bash commands, please check the corresponding class in the javadoc here
File parsing steps
Steps definitions for handling and parsing text files. This class makes use of Utah-parser, a Java library for parsing semi-structured text files
Feature: Verify the resulting records from a file
Scenario: Parse a text file against a XML definition and get a list of records
Given I parse the file located at 'files/f10_ip_bgp_summary_example.txt' using the template defined in 'files/f10_ip_bgp_summary_template.xml'
Then the result contains '3' records
Then the result contains at least '3' records
And the total of the column 'localAS' is '196653'
And there are '3' records with column 'localAS' equal to '65551'
And there are '1' records with column 'remoteAS' equal to '65553'
And the record at position '0' at column 'remoteIp' has the value '10.10.10.10'
Check also these examples:
For a complete list of steps definitions related to files manipulation, please check the corresponding class in the javadoc here
Big data steps (WIP)
Steps definition for big data functionality
Kafka steps
Steps definitions for working with Apache Kafka
Feature: Kafka steps test.
This feature provides examples of how to use the included steps for testing Kafka services
Scenario: Using String, Long serializers/deserializers
Given I connect to kafka at '${ZOOKEEPER_HOST}:2181'
Given I create a Kafka topic named 'stringTopic' if it doesn't exists
When I send a message 'hello' to the kafka topic named 'stringTopic'
Then The kafka topic 'stringTopic' has a message containing 'hello'
Given I create a Kafka topic named 'longTopic' if it doesn't exists
When I send a message '1234567890' to the kafka topic named 'longTopic' with:
| key.serializer | org.apache.kafka.common.serialization.StringSerializer |
| value.serializer | org.apache.kafka.common.serialization.LongSerializer |
Then The kafka topic 'longTopic' has a message containing '1234567890' with:
| key.deserializer | org.apache.kafka.common.serialization.StringDeserializer |
| value.deserializer | org.apache.kafka.common.serialization.LongDeserializer |
Then I close the connection to kafka
Check also these examples:
For a complete list of steps definitions related to Kafka, please check the corresponding class in the javadoc here
Mobile steps
Step definition for Appium (mobile testing). This class contains the functionality that is only available in the {@link MobileDriver}. most of the steps definitions for selenium ( in {@link SeleniumGSpec}) can be used for mobile testing
@mobile
Feature: Running tests in mobile devices
Scenario: Opening an closing the app
Given I open the application
And I wait '5' seconds
Given I close the application
Scenario: Changing orientation
Given I rotate the device to 'landscape' mode
And I wait '3' seconds
Given I rotate the device to 'portrait' mode
Check also these examples:
For a complete list of steps definitions related to Mobile, please check the corresponding class in the Javadoc here
IMPORTANT: All mobile-related steps, make use of a MobileDriver, which is in essence very similar to the WebDriver used in selenium steps (MobileDriver is a sub-class of WebDriver). Because of this, there is a lot of common functionality between selenium and mobile steps. This page will only list the steps that are exclusive to the MobileDriver and that can only be executed on a mobile device.
Other common functionality (find elements, click elements, type on element, etc) is the same for selenium and mobile, so you can use the selenium steps in exactly the same way
Rest steps
Steps definitions for testing REST services. These steps make use of rest-assured behind the scenes. Notice that the Feature contains the tag @rest at the beginning. This tag is required when using the Rest steps of GingerSpec. I recommend you to take a look at the documentation of the @rest tag here
@rest
Feature: Testing a RestFull API
Scenario: A successful response with a valid body is returned
Given I securely send requests to 'jsonplaceholder.typicode.com:443'
When I send a 'GET' request to '/posts'
Then the service response status must be '200'
And I save element '$.[0].userId' in environment variable 'USER_ID'
Then '${USER_ID}' matches '1'
Scenario: A new element is inserted via a POST call
Given I securely send requests to 'jsonplaceholder.typicode.com:443'
When I send a 'POST' request to '/posts' based on 'schemas/mytestdata.json' as 'json'
Then the service response status must be '201'
And I save element '$.title' in environment variable 'TITLE'
Then '${TITLE}' contains 'This is a test'
Scenario: Data in local file is altered using a datatable before sending
Given I securely send requests to 'jsonplaceholder.typicode.com:443'
When I send a 'POST' request to '/posts' based on 'schemas/mytestdata.json' as 'json' with:
| $.title | UPDATE | This is a test 2 |
Then the service response status must be '201'
And I save element '$' in environment variable 'response'
And 'response' matches the following cases:
| $.title | contains | 2 |
| $.body | contains | This is a test |
| $.userId | not equal | 2 |
Check also these examples:
For a complete list of steps definitions related to testing REST services, please check the corresponding class in the Javadoc here