Skip to content

Commit 65c98d7

Browse files
authored
[cascading] from release/13.4 to main (#3809)
<!-- {"currentBranch":"release/13.4","targetBranch":"main","bypassReviewers":false,"isConflicting":false} --> ## Cascading from release/13.4 to main --- <small>This Pull Request has been generated with ❤️ by the [Otter](https://github.com/AmadeusITGroup/otter) cascading tool.</small>
2 parents 6685e08 + ae08cc1 commit 65c98d7

File tree

1 file changed

+27
-12
lines changed

1 file changed

+27
-12
lines changed

packages/@o3r/testing/src/core/playwright/component-fixture.ts

Lines changed: 27 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ export class O3rComponentFixture<V extends O3rElement = O3rElement> implements C
9999
* @param options.elementConstructor Constructor that will be used to create the Element, defaults to O3rElement
100100
* @param options.index index Select the element associated to the index
101101
* @param options.shouldThrowIfNotPresent If set to true the function will throw if the element is not present
102-
* @param options.timeout Duration to wait for the element to be present before it throws
102+
* @param options.timeout Duration to wait for the element
103103
*/
104104
protected async getText<T extends O3rElement>(selector: string, options: {
105105
elementConstructor?: O3rElementConstructor<T>;
@@ -108,9 +108,6 @@ export class O3rComponentFixture<V extends O3rElement = O3rElement> implements C
108108
timeout?: number;
109109
} = {}): Promise<string | undefined> {
110110
const element = await this.queryWithOptions(selector, options.elementConstructor, options);
111-
if (!await element.isVisible()) {
112-
return;
113-
}
114111
return await element.getText();
115112
}
116113

@@ -121,7 +118,7 @@ export class O3rComponentFixture<V extends O3rElement = O3rElement> implements C
121118
* @param options.elementConstructor Constructor that will be used to create the Element, defaults to O3rElement
122119
* @param options.index index Select the element associated to the index
123120
* @param options.shouldThrowIfNotPresent If set to true the function will throw if the element is not present
124-
* @param options.timeout Duration to wait for the element to be present before it throws
121+
* @param options.timeout Duration to wait for the element
125122
*/
126123
protected async isVisible<T extends O3rElement>(selector: string, options: {
127124
elementConstructor?: O3rElementConstructor<T> | undefined;
@@ -130,7 +127,18 @@ export class O3rComponentFixture<V extends O3rElement = O3rElement> implements C
130127
timeout?: number;
131128
} = {}): Promise<boolean> {
132129
const element = await this.queryWithOptions(selector, options.elementConstructor, options);
133-
return await element.isVisible();
130+
if (options.timeout) {
131+
try {
132+
await element.sourceElement.element.waitFor({
133+
state: 'visible',
134+
timeout: options.timeout
135+
});
136+
return true;
137+
} catch {
138+
return false;
139+
}
140+
}
141+
return element.isVisible();
134142
}
135143

136144
/**
@@ -149,9 +157,7 @@ export class O3rComponentFixture<V extends O3rElement = O3rElement> implements C
149157
timeout?: number;
150158
} = {}): Promise<void> {
151159
const element = await this.queryWithOptions(selector, options.elementConstructor, options);
152-
if (await element.isVisible()) {
153-
await element.click();
154-
}
160+
await element.click();
155161
}
156162

157163
/** @inheritdoc */
@@ -160,7 +166,10 @@ export class O3rComponentFixture<V extends O3rElement = O3rElement> implements C
160166
public query<T extends O3rElement>(selector: string, returnType: O3rElementConstructor<T> | undefined): Promise<T | O3rElement> {
161167
const elements = this.rootElement.sourceElement.element.locator(selector);
162168
const element = elements.first();
163-
const selectedElement = { element: element, page: this.rootElement.sourceElement.page } as const satisfies PlaywrightSourceElement;
169+
const selectedElement = {
170+
element: element,
171+
page: this.rootElement.sourceElement.page
172+
} as const satisfies PlaywrightSourceElement;
164173
return Promise.resolve(new (returnType || O3rElement)(selectedElement));
165174
}
166175

@@ -170,7 +179,10 @@ export class O3rComponentFixture<V extends O3rElement = O3rElement> implements C
170179
public queryNth<T extends O3rElement>(selector: string, index: number, returnType: O3rElementConstructor<T> | undefined): Promise<T | O3rElement> {
171180
const elements = this.rootElement.sourceElement.element.locator(selector);
172181
const element = elements.nth(index);
173-
const selectedElement = { element: element, page: this.rootElement.sourceElement.page } as const satisfies PlaywrightSourceElement;
182+
const selectedElement = {
183+
element: element,
184+
page: this.rootElement.sourceElement.page
185+
} as const satisfies PlaywrightSourceElement;
174186
return Promise.resolve(new (returnType || O3rElement)(selectedElement));
175187
}
176188

@@ -192,7 +204,10 @@ export class O3rComponentFixture<V extends O3rElement = O3rElement> implements C
192204
const pElementsCount = await pElements.count();
193205
const elements = [];
194206
for (let i = 0; i < pElementsCount; i++) {
195-
const selectedElement: PlaywrightSourceElement = { element: pElements.nth(i), page: this.rootElement.sourceElement.page };
207+
const selectedElement: PlaywrightSourceElement = {
208+
element: pElements.nth(i),
209+
page: this.rootElement.sourceElement.page
210+
};
196211
elements.push(returnType ? new returnType(selectedElement) : new O3rElement(selectedElement));
197212
}
198213
if (groupType) {

0 commit comments

Comments
 (0)