Skip to content

Commit

Permalink
Improve stability of Modal dialog tests (#826)
Browse files Browse the repository at this point in the history
Signed-off-by: Dominik Jelinek <[email protected]>
  • Loading branch information
djelinek authored Jun 5, 2023
1 parent 56a3b13 commit b68e671
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 23 deletions.
9 changes: 5 additions & 4 deletions page-objects/src/components/dialog/ModalDialog.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { AbstractElement } from "../AbstractElement";
* Page Object for Custom Style Modal Dialogs (non-native)
*/
export class ModalDialog extends AbstractElement {

constructor() {
super(ModalDialog.locators.Dialog.constructor);
}
Expand All @@ -14,15 +15,15 @@ export class ModalDialog extends AbstractElement {
*/
async getMessage(): Promise<string> {
const message = await this.findElement(ModalDialog.locators.Dialog.message);
return message.getText();
return await message.getText();
}

/**
* Get the details message in a Promise
*/
async getDetails(): Promise<string> {
const details = await this.findElement(ModalDialog.locators.Dialog.details);
return details.getText();
return await details.getText();
}

/**
Expand All @@ -31,7 +32,7 @@ export class ModalDialog extends AbstractElement {
* @returns Promise resolving to Array of WebElement items representing the buttons
*/
async getButtons(): Promise<WebElement[]> {
return this.findElement(ModalDialog.locators.Dialog.buttonContainer).findElements(ModalDialog.locators.Dialog.button);
return await this.findElement(ModalDialog.locators.Dialog.buttonContainer).findElements(ModalDialog.locators.Dialog.button);
}

/**
Expand All @@ -53,6 +54,6 @@ export class ModalDialog extends AbstractElement {
*/
async close(): Promise<void> {
const btn = await this.findElement(ModalDialog.locators.Dialog.closeButton);
return btn.click();
return await btn.click();
}
}
36 changes: 17 additions & 19 deletions test/test-project/src/test/dialog/dialog-test.ts
Original file line number Diff line number Diff line change
@@ -1,50 +1,48 @@
import { expect } from "chai";
import { EditorView, InputBox, ModalDialog, TextEditor, TitleBar, until, VSBrowser } from 'vscode-extension-tester';
import { By, EditorView, InputBox, ModalDialog, TextEditor, until, VSBrowser, after, before, Workbench } from 'vscode-extension-tester';

(VSBrowser.instance.version >= '1.50.0' && process.platform !== 'darwin' ? describe : describe.skip)('Modal Dialog', () => {
let dialog: ModalDialog;

before(async function() {
this.timeout(15000);
if (VSBrowser.instance.version >= '1.65.0') {
await new TitleBar().select('File', 'New File...');
const input = await InputBox.create();
await input.setText('text');
await input.confirm();
} else {
await new TitleBar().select('File', 'New File');
}
before(async function () {
this.timeout(30000);
await new Workbench().executeCommand('Create: New File...');
await (await InputBox.create()).selectQuickPick('Text File');
await new Promise(res => setTimeout(res, 1000));
const editor = new TextEditor();
await editor.typeTextAt(1, 1, 'text');
await new Promise(res => setTimeout(res, 1000));
await new EditorView().closeEditor(await editor.getTitle());
await new Promise(res => setTimeout(res, 1000));
dialog = new ModalDialog();
await dialog.getDriver().wait(until.elementsLocated(By.className('monaco-dialog-box')), 5000);
});

after(async () => {
after(async function () {
await new Promise(res => setTimeout(res, 1000));
});

it('getMessage works', async () => {
it('getMessage works', async function () {
this.timeout(10000);
const message = await dialog.getMessage();
expect(message).has.string('Do you want to save the changes');
});

it('getDetails works', async () => {
it('getDetails works', async function () {
this.timeout(10000);
const details = await dialog.getDetails();
expect(details).has.string('Your changes will be lost');
});

it('getButtons works', async () => {
it('getButtons works', async function () {
this.timeout(10000);
const buttons = await dialog.getButtons();
expect(buttons.length).equals(3);
});

it('pushButton works', async () => {
const driver = dialog.getDriver();
it('pushButton works', async function () {
this.timeout(10000);
await dialog.pushButton(`Don't Save`);
await driver.wait(until.stalenessOf(dialog), 2000);
await dialog.getDriver().wait(until.stalenessOf(dialog), 2000);
});
});
});

0 comments on commit b68e671

Please sign in to comment.