You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Then in my steps, I can set and share the _context values this._context = {};
When(
"a valid search request",
async function ({ page, request }) {
const tests = new SearchText(page);
this._context["order_search_response"] =
await tests.searchAPI.callSearchRequest(
request,
this._context["valid_token"],
);
}
);
Then(
"the API returned all the search criteria",
async function ({ page }) {
const tests = new SearchText(page);
tests.cartSearchAsserts.assertValidResponseWithSchema(
this._context["order_search_response"]
);
}
);
With the use of context, for each worker that I used, they are unique during run time.
The text was updated successfully, but these errors were encountered:
I've noticed that you use mixed steps style: rely on this and pass fixtures as a first argument to step functions. In general, it's better to follow pure Playwright-style or pure Cucumber-style steps. There are more details here #208 (comment).
If using playwright-style, you can share context between steps by defining _context as a fixture:
import{testasbase}from'playwright-bdd';exportconsttest=base.extend({_context: async({},use)=>{awaituse({});// <- _context initialized with empty object}});
Or, you can set up full world via fixture, check out this guide.
Alternatively, you can use existing approach. Playwright-bdd provides a fallback for mixed steps style: it always initializes this as empty object, so you can attach _context to it:
When("a valid search request",asyncfunction({ page, request }){consttests=newSearchText(page);this._context=this._context||{};// ensure this._context is initialized, because by default `this` is empty objectthis._context["order_search_response"]=awaittests.searchAPI.callSearchRequest(request,this._context["valid_token"],);});
In that case, you don't need to define CustomWorld at all.
I do have this before and able to utilize the CustomWorld that I have created.
_context
valuesthis._context = {};
With the use of context, for each worker that I used, they are unique during run time.
The text was updated successfully, but these errors were encountered: