Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions src/actions/check.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import {LogEventType} from '../constants/internal';
import {step} from '../step';

import type {Locator} from '@playwright/test';

import type {Selector} from '../types/internal';

type Options = Parameters<Locator['check']>[0];

/**
* Checks checkbox or radio element, if it is not checked yet.
*/
export const check = (selector: Selector, options: Options = {}): Promise<void> =>
step(
`Checks checked or radio element ${selector.description}`,
async () => {
await selector.getPlaywrightLocator().check(options);
},
{payload: {...options, selector}, type: LogEventType.InternalAction},
);
1 change: 1 addition & 0 deletions src/actions/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ export {
assertUrlMatchRoute,
} from './asserts';
export {blur} from './blur';
export {check} from './check';
export {clearCookies} from './clearCookies';
export {clearInput} from './clearInput';
export {click} from './click';
Expand Down
2 changes: 1 addition & 1 deletion src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ if (IS_DEBUG || isUiMode) {
}

const useOptions: PlaywrightTestConfig['use'] = {
actionTimeout: Math.round(userlandPack.testIdleTimeout / 2),
actionTimeout: userlandPack.selectorTimeout,
browserName: userlandPack.browserName,
// eslint-disable-next-line @typescript-eslint/naming-convention
bypassCSP: !userlandPack.enableCsp,
Expand Down
16 changes: 11 additions & 5 deletions src/utils/expect/getAssertionPromise.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,11 +76,17 @@ export const getAssertionPromise = ({

const assertionPromise: Promise<Expect> = RESOLVED_PROMISE.then(() => {
if (isThenable(context.actualValue)) {
return addTimeoutToPromise(
context.actualValue as Promise<unknown>,
timeout,
timeoutError,
).then(runAssertion);
return addTimeoutToPromise(context.actualValue as Promise<unknown>, timeout, timeoutError)
.then(runAssertion)
.catch((error: Error) => {
const ctx: Expect = {
actualValue: '<Thenable>',
description: context.description,
error,
};

return ctx;
});
}

return runAssertion(context.actualValue);
Expand Down
1 change: 1 addition & 0 deletions src/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ export {getHash} from './getHash';
export {getKeysCounter} from './getKeysCounter';
export {getEquivalentHeadersNames, getHeadersFromHeaderEntries, getHeaderValue} from './headers';
export {getContentJsonHeaders} from './http';
export {getCheckedInputValue, getInputByValue} from './input';
export {log} from './log';
export {deepMerge, getEntries, getKeys, setReadonlyProperty} from './object';
export {createPageObjectsFromMultiLocator} from './pageObjects';
Expand Down
18 changes: 18 additions & 0 deletions src/utils/input/getCheckedInputValue.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import type {Selector} from '../../types/internal';

/**
* Get checked input value from multiselector (usually from `<input type="radio">`).
*/
export const getCheckedInputValue = async (input: Selector): Promise<string | null> => {
const count = await input.count;

for (let index = 0; index < count; index += 1) {
const currentInput = input.nth(index);

if (await currentInput.checked) {
return currentInput.value;
}
}

return null;
};
18 changes: 18 additions & 0 deletions src/utils/input/getInputByValue.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import type {Selector} from '../../types/internal';

/**
* Get input from multiselector (usually from `<input type="radio">`) by input value.
*/
export const getInputByValue = async (input: Selector, value: string): Promise<Selector | null> => {
const count = await input.count;

for (let index = 0; index < count; index += 1) {
const currentInput = input.nth(index);

if ((await currentInput.value) === value) {
return currentInput;
}
}

return null;
};
2 changes: 2 additions & 0 deletions src/utils/input/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export {getCheckedInputValue} from './getCheckedInputValue';
export {getInputByValue} from './getInputByValue';