Skip to content

Commit

Permalink
FI-1346 chore: update create-locator to 0.0.24
Browse files Browse the repository at this point in the history
chore: update devDependencies (TypeScript to 5.6, etc)
chore: update Playwright to 1.47.2
feat: replace old locator API to new one
  • Loading branch information
uid11 committed Sep 26, 2024
1 parent 8a7cb0a commit 9983571
Show file tree
Hide file tree
Showing 27 changed files with 185 additions and 223 deletions.
10 changes: 10 additions & 0 deletions autotests/constants/attributesOptions.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import type {AttributesOptions} from 'create-locator';

/**
* Attributes options for locators.
*/
export const attributesOptions = {
parameterAttributePrefix: 'data-test-',
testIdAttribute: 'data-testid',
testIdSeparator: '-',
} as const satisfies AttributesOptions;
1 change: 1 addition & 0 deletions autotests/constants/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
export {attributesOptions} from './attributesOptions';
export {DEFAULT_PASSWORD} from './user';
3 changes: 2 additions & 1 deletion autotests/packs/allTests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ const browserFlags = [
'--ignore-certificate-errors',
];

const filterTestsIntoPack: FilterTestsIntoPack = ({options}) => options.meta.testId !== '13';
const filterTestsIntoPack: FilterTestsIntoPack = ({options}) =>
options.meta.testId !== '13' && options.meta.testId !== '15';

const userAgent =
'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.35 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.35';
Expand Down
34 changes: 20 additions & 14 deletions autotests/pageObjects/pages/E2edReportExample/E2edReportExample.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ import {
} from 'autotests/actions';
import {setPageCookies, setPageRequestHeaders} from 'autotests/context';
import {E2edReportExample as E2edReportExampleRoute} from 'autotests/routes/pageRoutes';
import {locatorIdSelector, rootLocator} from 'autotests/selectors';
import {locator} from 'autotests/selectors';
import {Page} from 'e2ed';
import {createPageObjectsFromMultiLocator, setReadonlyProperty} from 'e2ed/utils';
import {setReadonlyProperty} from 'e2ed/utils';

import {TestRunButton} from './TestRunButton';

Expand All @@ -23,14 +23,13 @@ export class E2edReportExample extends Page<CustomPageParams> {
/**
* Navigation bar with test retries.
*/
readonly navigationRetries: Selector = locatorIdSelector('app-navigation-retries');
readonly navigationRetries: Selector = locator('RetriesButtons');

/**
* Button tabs in navigation bar with test retries.
*/
readonly navigationRetriesButton: Selector = this.navigationRetries.findByLocatorId(
'app-navigation-retries-button',
);
readonly navigationRetriesButton: Selector =
this.navigationRetries.findByLocatorId('RetryButton');

/**
* Selected button tab in navigation bar with test retries.
Expand All @@ -53,13 +52,13 @@ export class E2edReportExample extends Page<CustomPageParams> {
/**
* Test run button.
*/
readonly testRunButton: Selector = this.testRunsList.findByLocatorId('app-retries-retry-button');
readonly testRunButton: Selector = this.testRunsList.findByLocatorId('TestRunButton');

/**
* List of test runs of retry.
*/
get testRunsList(): Selector {
return locatorIdSelector('app-column1');
return locator('column1');
}

/**
Expand All @@ -82,12 +81,19 @@ export class E2edReportExample extends Page<CustomPageParams> {
/**
* Get `TestRunButton` hash (hashed by test `mainParams`).
*/
getTestRunButtons(): Promise<Readonly<Record<string, TestRunButton>>> {
return createPageObjectsFromMultiLocator({
PageObjectClass: TestRunButton,
keyParameter: 'runhash',
locator: rootLocator.retries.retry.button,
});
async getTestRunButtons(): Promise<readonly TestRunButton[]> {
const multiSelector = locator('TestRunButton');
const numberOfPageObjects = await multiSelector.count;

const buttons: TestRunButton[] = [];

for (let index = 0; index < numberOfPageObjects; index += 1) {
const selector = multiSelector.nth(index);

buttons.push(new TestRunButton(selector));
}

return buttons;
}

override init(this: E2edReportExample): void {
Expand Down
15 changes: 8 additions & 7 deletions autotests/pageObjects/pages/E2edReportExample/TestRunButton.ts
Original file line number Diff line number Diff line change
@@ -1,22 +1,23 @@
import type {CreateLocator} from 'e2ed/createLocator';
import type {Selector, TestRunButtonLocator} from 'e2ed/types';
import {locator} from 'autotests/selectors';

type Locator = CreateLocator<TestRunButtonLocator, Selector>;
import type {Selector} from 'e2ed/types';

const testId = 'TestRunButton';

/**
* `TestRun` button.
*/
export class TestRunButton {
readonly locator: Locator;
readonly selector: Selector;

constructor(locator: Locator) {
this.locator = locator;
constructor(selector: Selector) {
this.selector = selector;
}

/**
* Element with `mainParams` of test.
*/
get parameters(): Selector {
return this.locator.parameters();
return locator(testId, 'parameters');
}
}
2 changes: 1 addition & 1 deletion autotests/selectors/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
export {inputSelector} from './inputSelector';
export {rootLocator} from './rootLocator';
export {chain, locator} from './locator';
export {
createSelector,
createSelectorByCss,
Expand Down
14 changes: 14 additions & 0 deletions autotests/selectors/locator.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import {attributesOptions} from 'autotests/constants';
import {createTestUtils} from 'e2ed/createLocator';

import {createSelectorByCss} from './selectorFunctions';

/**
* Test utils, that produce `Selector`.
*/
export const {chain, locator} = createTestUtils({
attributesOptions,
createLocatorByCssSelector: (cssSelector) =>
createSelectorByCss(cssSelector.replace('data-test-runhash', 'data-runhash')),
supportWildcardsInCssSelectors: true,
});
15 changes: 0 additions & 15 deletions autotests/selectors/rootLocator.ts

This file was deleted.

10 changes: 5 additions & 5 deletions autotests/tests/e2edReportExample/selectorCustomMethods.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import {test} from 'autotests';
import {E2edReportExample} from 'autotests/pageObjects/pages';
import {chain} from 'autotests/selectors';
import {expect} from 'e2ed';
import {click, navigateToPage} from 'e2ed/actions';

Expand All @@ -15,22 +16,21 @@ test('selector custom methods', {meta: {testId: '15'}}, async () => {
'selected navigation retries button exists',
).ok();

const testRunButtonsHash = await reportPage.getTestRunButtons();
const testRunButtons = await reportPage.getTestRunButtons();

const retriesButtonsCount = await reportPage.navigationRetriesButton.count;

const testRunButtonsCount = Object.keys(testRunButtonsHash).length;
const testRunButtonsCount = Object.keys(testRunButtons).length;

await expect(reportPage.testRunButton.count, 'getTestRunButtons find all buttons').eql(
testRunButtonsCount,
);

let buttonsIndex = 0;

for (const testRunButton of Object.values(testRunButtonsHash)) {
for (const testRunButton of Object.values(testRunButtons)) {
const selector = reportPage.testRunButton.nth(buttonsIndex);
const mainParams = await selector.findByLocatorId(String(testRunButton.locator.parameters))
.textContent;
const mainParams = await chain(selector, testRunButton.parameters).textContent;

await expect(testRunButton.parameters.textContent, 'mainParams of test run button correct').eql(
mainParams,
Expand Down
72 changes: 37 additions & 35 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 8 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,14 @@
"url": "git+https://github.com/joomcode/e2ed.git"
},
"dependencies": {
"@playwright/test": "1.47.0",
"create-locator": "0.0.23",
"@playwright/test": "1.47.2",
"create-locator": "0.0.24",
"get-modules-graph": "0.0.9",
"globby": "11.1.0"
},
"devDependencies": {
"@playwright/browser-chromium": "1.47.0",
"@types/node": "22.5.4",
"@playwright/browser-chromium": "1.47.2",
"@types/node": "22.7.2",
"@typescript-eslint/eslint-plugin": "7.18.0",
"@typescript-eslint/parser": "7.18.0",
"assert-modules-support-case-insensitive-fs": "1.0.1",
Expand All @@ -42,13 +42,13 @@
"eslint-plugin-import": "2.30.0",
"eslint-plugin-simple-import-sort": "12.1.1",
"eslint-plugin-typescript-sort-keys": "3.2.0",
"husky": "9.1.5",
"husky": "9.1.6",
"prettier": "3.3.3",
"typescript": "5.5.4"
"typescript": "5.6.2"
},
"peerDependencies": {
"@types/node": ">=16.11.1",
"typescript": ">=4.8"
"@types/node": ">=20",
"typescript": ">=5"
},
"exports": {
".": "./index.js",
Expand Down
Loading

0 comments on commit 9983571

Please sign in to comment.