Replies: 1 comment 1 reply
-
Now that we've shipped the chaining feature, you can simply pass the /**
* Helper for checking checkbox in specific table row
*/
function checkRow(screen: Screen, name: string | RegExp) {
const edit = await screen.findByTestId("Edit Group Codes");
await edit.click();
const editTable = await screen.findByTestId('editable-nested-table-AuctionGroupCode');
const editRow = within(editTable).getByRole('row', { name }); // ---> should be able to pass different names each time
const checkbox = within(editRow).getByRole('cell', { name: /check/ });
await checkbox.click();
}
test('Group code table', async ({ page, screen, within }) => {
const table = await screen.findByTestId('nested-table-AuctionGroupCode');
const row = within(table).getByRole('row', { name: /NEW HIRE/ });
const cell = within(row).getAllByRole('cell');
const activeStatus = await cell.nth(0).textContent();
console.log('Status is :' + activeStatus);
// ↯ Invoke test helper ↯
await checkRow(screen, /NEW HIRE/);
const save = await screen.findByTestId('button-text-save-AuctionGroupCode');
await save.click();
await page.waitForTimeout(3000);
if (activeStatus == 'minus-circle') {
expect(await cell.nth(0).textContent()).toEqual('success');
} else {
expect(await cell.nth(0).textContent()).toEqual('minus-circle');
}
}); If you're absolutely set on using the so-called Screenplay pattern, you could probably pass a
import { LocatorQueries } from '@playwright-testing-libary/test';
declare module '@playwright/test' {
interface Page extends LocatorQueries {}
} |
Beta Was this translation helpful? Give feedback.
-
Below is the design pattern to build a test framework to achieve easy maintenance and build re usable methods.
Screenplay pattern instead of Page object model:
https://medium.com/tech-p7s1/testla-screenplay-for-playwright-2b8e340f4475
https://www.npmjs.com/package/@testla/screenplay-playwright
Can you please suggest if a screenplay pattern can be incorporated /or used in the tests that are written using playwright testing library?
Is there any example how to use playwright testing library to setup a test framework that incorporates Screenplay pattern?
We do not want to follow page object model pattern in our framework as the above article explains as Screenplay pattern is better than the play object model pattern.
2.Below is the test, however want to test with the multiple test data to the below method to test if a checkbox is clickable.
wondering how playwright testing library recommends when we want to test the same piece of code with multiple test data.
Can you please advise how you build reusable methods so that can be reused ? Do you have examples to refer to?
Basically we do not want to repeat the code for each user eg: NEW HIRE, we have 10+ other users I want to test these same below lines of code with different name- arguments. do you have any recommendations please?
Beta Was this translation helpful? Give feedback.
All reactions