boxine/pentf

Add typeTestId similar to typeSelector, though just the testId would be necessary.

Closed this issue ยท 2 comments

It would be nice to have a typeTestId, similar to the typeSelector so just the data-testid is necessary.

This would make the code much simpler, especially when writing the typing functionality after the usage of waitForTestId.

It doesn't seem to be that difficult to implement, I could imagine it looking something like this:

async function typeTestId(
    page,
    testId,
    text,
    { message = undefined, timeout = getDefaultTimeout(page), delay } = {}
) {
    const config = getBrowser(page)._pentf_config;
    addBreadcrumb(config, `enter typeTestId(${testId}, text: ${text})`);
    const testIdSelector = `*[data-testid="${testId}"]`
    const el = await waitForVisible(page, testIdSelector, { timeout, message });
    await el.type(text, { delay });
    addBreadcrumb(config, `exit typeTestId(${testId}, text: ${text})`);
}

Regards to the test, I think it would be almost the same as the existing: selftest_typeSelector.js, except in our case we would need to add the data-testid as the attribute and use that value when using the typeTestId within its own test.

I could make a pull request and work on this tomorrow ๐Ÿ˜ƒ ๐Ÿ‘ ๐Ÿš€ ๐Ÿฅณ ๐Ÿค˜ ๐Ÿ’ฏ

I like this idea, it would make sense to have this in pentf. Since we're still relying on CSS-Selectors underneath, we could just leverage the existiting typeSelector function.

async function typeTestId(page, testId, text, options) {
    return typeSelector(page, `[data-testid="${testId}"]`, text, options)
}

We found a better way to solve this locally by creating a util function with the existing typeSelector.