Skip to content

Commit 735bb95

Browse files
pospisilfdjelinek
andauthored
feat: Provide WelcomeContentSection.getButton (#1757)
Co-authored-by: Dominik Jelinek <[email protected]>
1 parent bc05c58 commit 735bb95

File tree

3 files changed

+22
-4
lines changed

3 files changed

+22
-4
lines changed

docs/CustomTreeSection.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@ const contents = await welcome.getContents();
2525
// get all buttons
2626
const btns = await welcome.getButtons();
2727

28+
// get specific button
29+
const btn = await welcome.getButton("title");
30+
2831
// get paragraphs as strings in a list
2932
const text = await welcome.getTextSections();
3033
```

packages/page-objects/src/components/sidebar/WelcomeContent.ts

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ export class WelcomeContentButton extends AbstractElement {
5454
export class WelcomeContentSection extends AbstractElement {
5555
/**
5656
* @param panel The panel containing the welcome content.
57-
* @param parent The webelement in which the welcome content is embedded.
57+
* @param parent The webElement in which the welcome content is embedded.
5858
*/
5959
constructor(panel: WebElement, parent: ViewSection) {
6060
super(panel, parent);
@@ -77,6 +77,21 @@ export class WelcomeContentSection extends AbstractElement {
7777
);
7878
}
7979

80+
/**
81+
* Returns a specific button from the welcome view that matches the given title.
82+
* @param title The title of the button to search for.
83+
* @returns A `WelcomeContentButton` if found, otherwise `undefined`.
84+
*/
85+
public async getButton(title: string): Promise<WelcomeContentButton | undefined> {
86+
const buttons = await this.getButtons();
87+
for (const btn of buttons) {
88+
if ((await btn.getTitle()) === title) {
89+
return btn;
90+
}
91+
}
92+
return undefined;
93+
}
94+
8095
/** Finds all buttons in the welcome content */
8196
public async getButtons(): Promise<WelcomeContentButton[]> {
8297
return (await this.findElements(WelcomeContentSection.locators.WelcomeContent.button)).map((elem) => new WelcomeContentButton(elem, this));

tests/test-project/src/test/xsideBar/customView.test.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -158,10 +158,10 @@ describe('CustomTreeSection', () => {
158158
describe('WelcomeContentButton', () => {
159159
it('takeAction executes the command', async function () {
160160
this.timeout(10000);
161-
const buttons = await ((await emptyViewSection.findWelcomeContent()) as WelcomeContentSection).getButtons();
162-
await buttons[0].click();
163-
164161
await new Promise((res) => setTimeout(res, 500));
162+
const button = await ((await emptyViewSection.findWelcomeContent()) as WelcomeContentSection).getButton('Add stuff into this View');
163+
expect(button).to.be.not.be.undefined;
164+
await button?.click();
165165
expect(await emptyViewSection.findWelcomeContent()).to.equal(undefined);
166166
});
167167
});

0 commit comments

Comments
 (0)