-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #69 from joomcode/feat/add-createPageObjectsFromMu…
…ltiLocator feat: add `createPageObjectsFromMultiLocator` utility
- Loading branch information
Showing
40 changed files
with
490 additions
and
167 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22 changes: 22 additions & 0 deletions
22
autotests/pageObjects/pages/E2edReportExample/TestRunButton.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import type {CreateLocator} from 'e2ed/createLocator'; | ||
import type {Selector, TestRunButtonLocator} from 'e2ed/types'; | ||
|
||
type Locator = CreateLocator<TestRunButtonLocator, Selector>; | ||
|
||
/** | ||
* `TestRun` button. | ||
*/ | ||
export class TestRunButton { | ||
readonly locator: Locator; | ||
|
||
constructor(locator: Locator) { | ||
this.locator = locator; | ||
} | ||
|
||
/** | ||
* Element with `mainParams` of test. | ||
*/ | ||
get parameters(): Selector { | ||
return this.locator.parameters(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export {E2edReportExample} from './E2edReportExample'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import {createSelectorByCss} from 'autotests/selectors'; | ||
import {createLocator, getCssSelectorFromAttributesChain} from 'e2ed/createLocator'; | ||
|
||
import type {ReportRootLocator, Selector} from 'e2ed/types'; | ||
|
||
/** | ||
* Project root locator, mapped to `Selector`. | ||
*/ | ||
export const rootLocator = createLocator<ReportRootLocator, Selector>('app', { | ||
mapAttributesChain: (attributesChain) => { | ||
const cssSelector = getCssSelectorFromAttributesChain(attributesChain); | ||
|
||
return createSelectorByCss(cssSelector.replace('data-test-runhash', 'data-runhash')); | ||
}, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
78 changes: 78 additions & 0 deletions
78
autotests/tests/internalTypeTests/createPageObjectsFromMultiSelector.skip.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
/* eslint-disable max-classes-per-file */ | ||
|
||
import {type CreateLocator, createLocator, type Locator, type Node} from 'e2ed/createLocator'; | ||
import {createPageObjectsFromMultiLocator} from 'e2ed/utils'; | ||
|
||
import type {IsEqual, Selector, Void} from 'e2ed/types'; | ||
|
||
type FooLocator = Locator<{qux: Void}, {parameter: 'baz'}>; | ||
|
||
type RootLocator = Locator<{foo: Node<{bar: FooLocator}>}>; | ||
|
||
const rootLocator = createLocator<RootLocator, Selector>('app', { | ||
mapAttributesChain: () => ({}) as unknown as Selector, | ||
}); | ||
|
||
const fooLocator = rootLocator.foo.bar; | ||
|
||
type BarMappedLocator = CreateLocator<Locator<{qux: Void}>, Selector>; | ||
|
||
true satisfies IsEqual<typeof fooLocator, CreateLocator<FooLocator, Selector>>; | ||
|
||
class Foo { | ||
readonly bar: string; | ||
|
||
readonly locator: typeof fooLocator; | ||
|
||
constructor(locator: typeof fooLocator) { | ||
this.locator = locator; | ||
this.bar = 'baz'; | ||
} | ||
} | ||
|
||
class Bar { | ||
readonly locator: BarMappedLocator; | ||
|
||
constructor(locator: BarMappedLocator) { | ||
this.locator = locator; | ||
} | ||
} | ||
|
||
declare const barLocator: BarMappedLocator; | ||
|
||
void (async () => { | ||
const map = await createPageObjectsFromMultiLocator({ | ||
PageObjectClass: Foo, | ||
keyParameter: 'parameter', | ||
locator: fooLocator, | ||
}); | ||
|
||
const foo = map['bar']; | ||
|
||
if (foo !== undefined) { | ||
foo.bar satisfies string; | ||
} | ||
|
||
await createPageObjectsFromMultiLocator({ | ||
PageObjectClass: Foo, | ||
// @ts-expect-error: wrong parameter name | ||
keyParameter: 'foo', | ||
locator: fooLocator, | ||
}); | ||
|
||
await createPageObjectsFromMultiLocator({ | ||
// @ts-expect-error: wrong locator in class | ||
PageObjectClass: Bar, | ||
keyParameter: 'parameter', | ||
locator: fooLocator, | ||
}); | ||
|
||
await createPageObjectsFromMultiLocator({ | ||
PageObjectClass: Bar, | ||
// @ts-expect-error: locator without parameters | ||
keyParameter: '', | ||
locator: barLocator, | ||
}); | ||
|
||
return map; | ||
})(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.