You can automate test cases in TF Automate by simply writing them in the text pane using Gherkin specification that can be found here. The Gherkin spec contains all the currently implemented sentences with their descriptions and examples.
Generally, Anton, the TestFirst AI Assistant, can help you write test cases for testing web applications. However, sometimes you might want to correct something or use a custom selector. In this article, you will find general information on the Gherkin language and the usage of the data repository items in your test cases.
Gherkin General Information
Gherkin is a human-readable syntax that describes the behavior of the software with a set of scenarios.
Gherkin can support multiple languages. You can check the list of supported languages here. You can switch the language using the dropdown in the test case title line.
Gherkin keywords
There are several keywords used in the TestFirst Automate Gherkin implementation:
- Scenario - a keyword indicating the start of a test case step. A scenario must contain an action and an expected result, and can contain a precondition.
- Given - a keyword indicating the precondition of a test step or the test case as a whole.
- When - a keyword indicating the action to be taken to achieve the expected result.
- Then - a keyword indicating the expected result of a test step.
- And - a connecting keyword, used within the precondition, action, and expected result when there is more than one precondition, action to be taken and/or more than one expected result to be achieved.
Example:
Scenario: Navigate to TestFirst website
Given browser "Chrome"
When I visit "https://www.testfirst.com/"
And I click "Features"
Then "START NOW" is displayed
And "Features That Make You Go Fast" is displayed
In the example:
- The scenario has the title "Navigate to TestFirst website". It can be any plain text, as the title is only there to help you understand what is done in the test step.
- The precondition indicated by the Given keyword, states that the test case should be executed in browser Chrome.
- The action indicated by the When keyword, states that to achieve the expected result, we need to visit the specified URL and click a specific element on the page. The action part of the scenario contains 2 sentences. One starts with the When keyword, the other continues with the And keyword.
- The expected result indicated by the Then keyword, checks for the presence of specific elements on the page. The And keyword allows for multiple elements to be checked.
Autocompletion of the Sentences
When you start writing a sentence in TF Automate, the auto-completer will suggest all the possible options for continuing the sentence, sorted by relevance. Thus, if you are writing a test case for a web application, and have a Given browser "<Browser"
sentence in the beginning of the test case, the auto-completer will first suggest the sentences relevant to the web application testing.
When you click on the sentence in the auto-completer list, it will insert the next portion of the sentence, till the next optional part of the sentence or the next argument.
Smart selectors
By default, Anton generates scenarios using smart selectors. A smart selector is a selector built based on the selector name. However, sometimes smart selectors might not work. In such cases, you will have to create your own selectors in TF Automate. You can find information on how to create good custom selectors in this article. Read this article to find out how to add a custom selector to the data repository.
If the text you want to use as a smart selector contains double quotes, you will need to use "\" as an escape character. For instance, if the text on the element is 'Some text in "double quotes" here', the "When I click selector" sentence would look like this: When I click "Some text in \"double quotes\" here" |
You can use variables from the data repository in simple selectors by enclosing them in double curly braces. For instance, When I click "Selector with a {{variable}}" |
When the path to a selector in the Data Repository is too long, you can use aliases for the selector location by using the following sentence (as per the Gherkin spec): Given selector alias "<Selector alias>" for "<Selector>" |
Using Data Repository Items
In order to insert a data repository item, type it in with curly braces around it. If the item is not in the root folder, use the dot notation to specify its location. You can find the examples for each type of a data repository item below.
To use a selector from the data repository:
When I click "{Selector from the data repository}"
When I click "{Folder in the data repository.Selector in this folder}"
To use a variable from the data repository:
When I type "{{Variable from the data repository}}" in "<Selector>"
When I type "{{Folder in the data repository.Variable in the folder}}"
Read this article for information on how to add items to the data repository. |
Comments
0 comments
Please sign in to leave a comment.