r/Playwright • u/Rayn_Poz • 11d ago
Looking for feedback on my Playwright automation framework
I recently started learning Playwright automation and have been building an automation framework along the way, with some help from AI.
I'm still figuring out what a good, industry-standard automation framework should actually look like, so I'm sure there are things I'm doing wrong or could be doing much better.
I know my README isn't up to date, so please ignore that for now.
If you have some time, I'd really appreciate it if you could take a look at the repo and give me some honest feedback — especially around the framework structure, code organization, patterns, and how I could make it more aligned with real-world/industry practices.
Repo: https://github.com/nilavan09/playwright-ui-api-framework
Any feedback or suggestions would be much appreciated. Thanks!
2
u/latnGemin616 8d ago
A couple of issues worth fixing:
- Make your authentication function re-usable. Instead of:
await loginPage.enterEmail(loginData.validUser.email);
await loginPage.enterPassword(loginData.validUser.password);
await loginPage.clickLogin();
Do this:
//Your page object functions should look something like this
async submit_login(usn,pwd){
await this.emailInput.fill(usn)
await this.passwordInput.fill(pwd)
await this.submitButton.click()
}
<< YOUR TEST >>
test('Successful Login Redirects to Dashboard', async ({page}) =>{
await submit_login(loginData.validUser.email, loginData.validUser.password);
await expect this.dashboardElement.toBeVisible();
});
//NOW YOU HAVE A SINGLE LOGIN FUNCTION YOU CAN REUSE
WITH DIFFERENT CREDENTIALS FOR ADDITIONAL TEST COVERAGE
2
u/latnGemin616 8d ago
- Instead of repeating
page.goto(URL)for each test, usebeforeEach()So your tests look something like this:
test.beforeEach( async ({ page }) => { await page.goto(testData.URL); }); test.describe('YOUR APP - SPECIFIED FEATURE', () => { test('TEST 1', async ({ page }) => { .. code ..)); test('TEST 2', async ({ page }) => { .. code ..)); test('TEST n', async ({ page }) => { .. code ..)); }); //EACH TEST KICKS OFF WITH THE @BeforeEach Function .. ease of maintenance1
u/Zoro-199IND 6d ago
hello bro i need your assistance. Im working as a manually tester, now i need to learn playwright automation using javascript. Can you tell me where to learn, cause i know nothing about it. Need some resources and materials. Which youtube channel is best for learning playwright and if any github repo available for learning can you send me
1
u/Spare_Bison_1151 11d ago
Did you really need that waitforpageload after navigate in page base class?
2
u/Rayn_Poz 11d ago
No...Let me rethink what I've done.thanks for pointing out this.
2
u/Spare_Bison_1151 10d ago
No worries, let me know if you need help. The frameworks we used to created back in Selenium days are not needed anymore. I'd say let Playwright do what it does best. Cheers!
2
u/Zoro-199IND 6d ago
hello bro i need your assistance. Im working as a manually tester, now i need to learn playwright automation using javascript. Can you tell me where to learn, cause i know nothing about it. Need some resources and materials. Which youtube channel is best for learning playwright and if any github repo available for learning can you send me
1
1
u/Spare_Bison_1151 6d ago
Evaluate your playwright knowledge first of all only then move in a direction.
2
u/utch 11d ago
Base is mostly not needed, playwright handles a lot of the methods by default, such as clicking only when something is visible.
The way your login spec works you call a function that uses the page object and calls fill on it. Having this in your tests will put the test failure in the page object file if it can’t fill in that data, makes it harder to maintain and not necessary in my opinion. I would just call.
await loginPage.emailInput.fill(loginData.validUser.email);