Rayrun
← Back to Discord Forum

Help in playwright TS creating nested component in page objects

infinitejest4695posted in #help-playwright
Open in Discord
infinitejest4695

I am used to using Playwright in c# and now thinking about porting what we have into TS but being not overlay familiar with type script i thought i would experiment a bit. i found an issue that is confusing me. In C# i can create a page manager class that lists all my pages and with the pages i have component modals. this allows me to write a class for a component and it can be used in other pages objects. An Example of the structure might be Manager -> HomePage -> NavBar -> search input so in my test i would write await manager.Homepage.Navbar.searchinput.FillAsync("Test");

This work but experimenting with the same thing in TS seems to cause issues

I have this repo https://github.com/infinitejest69/PlaywrightTS/blob/Master/tests/POM.spec.ts (don't judge just experimenting with TS) With a test 'should show search' When i run it it seems to do the fill twice and i can't see why. i suspect my approach is just flawed for TS but the test still runs and does the fill

**EDIT To add i tried making the searchDocs a method outside of the constructor and still does the same thing

image.png

This thread is trying to answer question "Why does the 'fill' function run twice when creating a nested component in page objects in TypeScript?"

3 replies
infinitejest4695

OK after some more playing this works but not if i breakpoint on the fill step. Break pointing on the fill causes input twice. no breakpoint and the test passes. i am confused

Try replacing fill with pressSequentially just out of curiosity. Overall, code looks ok and it shouldn't fill twice.

infinitejest4695

Thanks, so the fill is the issue pressSequentially with the break point seems to work with the breakpoint at the same place. how strange. I thought it was something racy in the approach of nesting classes.

Going to play around with a page object manager hopefully dont come across these issues again. thanks for your help

Related Discord Threads

TwitterGitHubLinkedIn
AboutQuestionsDiscord ForumBrowser ExtensionTagsQA Jobs

Rayrun is a community for QA engineers. I am constantly looking for new ways to add value to people learning Playwright and other browser automation frameworks. If you have feedback, email luc@ray.run.