Setting up a Playwright world object
How does Cucumber execute your test? Just like with the Playwright tests, we need a running application server and a running browser to drive the user interface (UI). In this section, we’ll write all the code that gets the environment ready for test execution.
Cucumber.js uses the concept of a world object that describes the contextual information that is shared between each scenario step. This is an object that is bound to the this
variable in each step. We also get access to it in special Before
and After
hooks, which are run before and after each scenario.
The world object should contain functions (and state) that allow you to drive the UI. Since you’ve already learned and used the Playwright API for locating objects on a page, it would be marvelous if we could use that same API. It turns out we can indeed do this. We can also use the same expect
API we’re used to as well, and we’ll do that in the next section...