DEV Community

Cover image for Behavior Driven Development (BDD) using Playwright

Behavior Driven Development (BDD) using Playwright

Swikriti Tripathi on February 07, 2022

Playwright is an open-source NodeJS framework for browser automation. It is developed by Microsoft and the development team has members that were i...
Collapse
 
ankitverma profile image
Ankit Verma

Thanks for the good article!

Collapse
 
charliewhu profile image
Charlie Avery • Edited

Hi, I'm not sure where you're getting the page object from in your todoContext.js file. This doesn't run for me while having the same config, and I get ReferenceError: page is not defined, any ideas why?

Collapse
 
swikritit profile image
Swikriti Tripathi

Hi sorry for the late reply but page is created incucumber.conf.js file and is set global so that it can be used across all the other files

Before(async function () {
   global.context = await global.browser.newContext();
   global.page = await global.context.newPage();
});
Enter fullscreen mode Exit fullscreen mode
Collapse
 
parsh07_20 profile image
Prashant Patil

it's still not working

Image description

Image description

Collapse
 
jwsheen profile image
James W. Shin

After rename cucumber.config.js to cucumber.conf.js, everything ok.

Thread Thread
 
parsh07_20 profile image
Prashant Patil

When execute it i am getting,

Image description

but still i am getting undefined for steps even though those are defined

Image description

Image description

and the thread issue is still not working for me
FYR

Image description

Thread Thread
 
akwasin profile image
akwasin

About the import issue, there's a few possible solutions.
One could be to add "type": "module" to your package.json. Another cause could depend on if you're using typescript commonJS or esNext. take a look at those two possible fixes.

Collapse
 
vitalets profile image
Vitaliy Potapov • Edited

Thanks for the article!
Inspired by it I've created playwright-bdd package that allows to run Cucumber tests with Playwright. The only difference is that it uses Playwright as a test runner and utilizes Cucumber as a library.

Collapse
 
nsaranya25 profile image
nsaranya25

Hello, I see your project - playwright-bdd-example. This is what I'm trying to implement. Could you please answer to my questions? Where you are launching the browser? Just giving the device in playwright-config.ts is enough? And the same project can be done in javascript as well?

Collapse
 
vitalets profile image
Vitaliy Potapov

Hello! Yes, just giving the device in playwright config is enough, b/c tests are actually normal Playwright tests. The same can be done in JavaScript as well

Collapse
 
shaney profile image
shane young

Hi, Thank you very much for the sharing. It is great, but when start to run, I always got this error:
Parse error in "tests\acceptance\features\todo.feature" (1:1): expected: #EOF, #Language, #TagLine, #FeatureLine, #Comment, #Empty, got '// todo.feature'

I am still learning. Could you please give me some help?
Thank

Shane

Collapse
 
onlyplanb profile image
CodeCase • Edited

I think you should remove the following

// todo.feature

from your featurefile because of your lintersettings?

Collapse
 
shaney profile image
shane young

Oh, right. Did forget that. :)
Thanks a lot.

Collapse
 
richardcariven profile image
RichardCariven

github.com/vitalets/playwright-bdd there is now a dedicated PLaywright-BDD runner which allows you to write Cucumber tests using the playwright runner directly.

It really streamlines the code, means you can directly use the Playwright.config.ts file to store all your browser config, and automatically creates a new context for every test. You can also use Playwright Fixtures to streamline your test and your framework. I have been porting our Cucumber project across and don't think I will use the cucumber runner ever again.

Collapse
 
al_p_664cee7c7a4c4393f08b profile image
Al P

Hi Brother. Do you have the same sample repo project for PlayWright with BDD frame work java. Do you have a mail id to reach out?

Collapse
 
vinny06 profile image
arvinder06

Thanks for this. I am just wondering how we can shard these tests and run in multiple machines at the same time?