Go to content | Go to the main menu | Go to search

edhouse-CookieGdpr-Policy-s
2183657
2
/en/gdpr/
318650B6A

Back to Blog

Reviews SQA

How to use Gherkin in Robot Framework

Tech_blog

Robot Framework is a popular Python-based testing tool maintained by the community and available free of charge. This gives it a great price/performance ratio. Its syntax is based on keywords. But can Robot Framework handle BDD and Gherkin? Let’s take a closer look.

Gherkin syntax is widely used for writing test scenarios — and for good reason. Its simplicity makes it easy to understand even for non-technical stakeholders, which can be a real advantage. Gherkin uses the following keywords to define a test case:

  • Feature: Describes the functionality (the goal).
  • Scenario: A description of a specific test case.
  • Given: The initial condition (“when I’m in a certain state”).
  • When: The user’s action (“when I do something”).
  • Then: The expected result (“then something should happen”).
  • And/But: Used to chain multiple steps.

Example scenario:

  • We want to open a browser at www.edhouse.cz.
  • Then click on the search icon.
  • Type e.g. “Robot Framework” into the search box.
  • The search results page should contain the text “Robot Framework”.

We use the Selenium library to control the browser. The core code for this scenario might look like this:

You can find the full source code on our GitHub.

Some keywords take variables. For example, in the keyword I enter "${search_string}" in the search field, the variable search_string can be replaced with any value.

The result of the test appears in the standard HTML output like this:

Although Robot Framework is primarily built for keyword-driven testing, it handles Gherkin easily without major hurdles. There is no need to install anything extra as Gherkin is supported natively in Robot Framework.

Share article

Author

Pavel Kolář

Pavel Kolář SQE with a focus on automation, latent pastafarianism. I am currently working on testing REST API using Robot Framework.

Edhouse newsletter

Get the latest updates from the world of Edhouse – news, events, and current software and hardware trends.

By signing up, you agree to our Privacy Policy.

Thank you for your interest in subscribing to our newsletter! To complete your registration you need to confirm your subscription. We have just sent you a confirmation link to the email address you provided. Please click on this link to complete your registration. If you do not find the email, please check your spam or "Promotions" folder.