Skip to content

Commit

Permalink
Console input smoke test - enter your name (#4022)
Browse files Browse the repository at this point in the history
This is a simple console user input test. In both Python and R, the
"user" is prompted to enter their name and "Hello ${name}" is echoed
back. The test waits until the echo is received in the console output to
determine pass/fail. This PR also adds in a pasteToConsole function that
simulates a user pasting code as opposed to entering code via a command
(to use the console itself more).

### QA Notes

All smoke tests should pass!
  • Loading branch information
testlabauto authored Jul 17, 2024
1 parent 73063f2 commit 58e22e1
Show file tree
Hide file tree
Showing 5 changed files with 102 additions and 16 deletions.
37 changes: 27 additions & 10 deletions test/automation/src/positron/positronConsole.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ import { QuickInput } from '../quickinput';
import { InterpreterType } from './positronStartInterpreter';
import { PositronBaseElement } from './positronBaseElement';


const CONSOLE_INPUT = '.console-input';
const ACTIVE_CONSOLE_INSTANCE = '.console-instance[style*="z-index: auto"]';
const MAXIMIZE_CONSOLE = '.bottom .codicon-positron-maximize-panel';
const CONSOLE_BAR_POWER_BUTTON = 'div.action-bar-button-icon.codicon.codicon-positron-power-button-thin';
Expand All @@ -28,6 +30,8 @@ export class PositronConsole {
barClearButton: PositronBaseElement;
consoleRestartButton: PositronBaseElement;

activeConsole = this.code.driver.getLocator(ACTIVE_CONSOLE_INSTANCE);

constructor(private code: Code, private quickaccess: QuickAccess, private quickinput: QuickInput) {
this.barPowerButton = new PositronBaseElement(CONSOLE_BAR_POWER_BUTTON, this.code);
this.barRestartButton = new PositronBaseElement(CONSOLE_BAR_RESTART_BUTTON, this.code);
Expand Down Expand Up @@ -84,22 +88,15 @@ export class PositronConsole {
}

async typeToConsole(text: string) {
const activeConsole = this.getActiveConsole();
await activeConsole?.click();
await activeConsole?.pressSequentially(text, { delay: 30 });
await this.activeConsole.click();
await this.activeConsole.pressSequentially(text, { delay: 30 });
}

async sendEnterKey() {
const activeConsole = this.getActiveConsole();
await activeConsole?.click();
await this.activeConsole.click();
await this.code.driver.getKeyboard().press('Enter');
}

getActiveConsole(): Locator | undefined {
const activeConsole = this.code.driver.getLocator(ACTIVE_CONSOLE_INSTANCE);
return activeConsole;
}

async waitForReady(prompt: string) {
// Wait for the prompt to show up.
await this.code.waitForTextContent(`${ACTIVE_CONSOLE_INSTANCE} .active-line-number`, prompt);
Expand All @@ -118,4 +115,24 @@ export class PositronConsole {
async maximizeConsole() {
await this.code.waitAndClick(MAXIMIZE_CONSOLE);
}

async pasteCodeToConsole(code: string) {
const consoleInput = this.activeConsole.locator(CONSOLE_INPUT);
await this.pasteInMonaco(consoleInput!, code);
}

async pasteInMonaco(
locator: Locator,
text: string
): Promise<void> {

await locator.locator('textarea').evaluate(async (element, evalText) => {
const clipboardData = new DataTransfer();
clipboardData.setData('text/plain', evalText);
const clipboardEvent = new ClipboardEvent('paste', {
clipboardData,
});
element.dispatchEvent(clipboardEvent);
}, text);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ export function setup(logger: Logger) {
async function testBody(app: Application) {
await app.workbench.quickaccess.runCommand('workbench.action.toggleAuxiliaryBar');

const activeConsole = app.workbench.positronConsole.getActiveConsole();
await activeConsole?.click();
const activeConsole = app.workbench.positronConsole.activeConsole;
await activeConsole.click();

await app.workbench.positronConsole.typeToConsole('a = 1');

Expand Down
67 changes: 67 additions & 0 deletions test/smoke/src/areas/positron/console/consoleInput.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
/*---------------------------------------------------------------------------------------------
* Copyright (C) 2024 Posit Software, PBC. All rights reserved.
* Licensed under the Elastic License 2.0. See LICENSE.txt for license information.
*--------------------------------------------------------------------------------------------*/


import { Application, Logger, PositronPythonFixtures, PositronRFixtures } from '../../../../../automation';
import { installAllHandlers } from '../../../utils';

export function setup(logger: Logger) {
describe('Console Input', () => {
// Shared before/after handling
installAllHandlers(logger);

describe('Console Input - Python', () => {
before(async function () {
await PositronPythonFixtures.SetupFixtures(this.app as Application);
});

it('Python - Get Input String Console [C667516]', async function () {
const app = this.app as Application;

const inputCode = `val = input("Enter your name: ")
print(f'Hello {val}!')`;

await app.workbench.positronConsole.pasteCodeToConsole(inputCode);

await app.workbench.positronConsole.sendEnterKey();

await app.workbench.positronConsole.waitForConsoleContents((contents) => contents.some((line) => line.includes('Enter your name:')) );

await app.workbench.positronConsole.typeToConsole('John Doe');

await app.workbench.positronConsole.sendEnterKey();

await app.workbench.positronConsole.waitForConsoleContents((contents) => contents.some((line) => line.includes('Hello John Doe!')) );

});
});

describe('Console Input - R', () => {
before(async function () {
await PositronRFixtures.SetupFixtures(this.app as Application);
});

it('R - Get Input String Console [C667517]', async function () {
const app = this.app as Application;

const inputCode = `val <- readline(prompt = "Enter your name: ")
cat(sprintf('Hello %s!\n', val))`;

await app.workbench.positronConsole.pasteCodeToConsole(inputCode);

await app.workbench.positronConsole.sendEnterKey();

await app.workbench.positronConsole.waitForConsoleContents((contents) => contents.some((line) => line.includes('Enter your name:')) );

await app.workbench.positronConsole.typeToConsole('John Doe');

await app.workbench.positronConsole.sendEnterKey();

await app.workbench.positronConsole.waitForConsoleContents((contents) => contents.some((line) => line.includes('Hello John Doe!')) );

});
});
});
}
8 changes: 4 additions & 4 deletions test/smoke/src/areas/positron/output/consoleOutputLog.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ export function setup(logger: Logger) {
it('Python - Verify Console Output Log Contents [C667518]', async function () {
const app = this.app as Application;

const activeConsole = app.workbench.positronConsole.getActiveConsole();
await activeConsole?.click();
const activeConsole = app.workbench.positronConsole.activeConsole;
await activeConsole.click();

await app.workbench.positronConsole.typeToConsole('a = b');
await app.workbench.positronConsole.sendEnterKey();
Expand Down Expand Up @@ -59,8 +59,8 @@ export function setup(logger: Logger) {
it('R - Verify Console Output Log Contents [C667519]', async function () {
const app = this.app as Application;

const activeConsole = app.workbench.positronConsole.getActiveConsole();
await activeConsole?.click();
const activeConsole = app.workbench.positronConsole.activeConsole;
await activeConsole.click();

await app.workbench.positronConsole.typeToConsole('a = b');
await app.workbench.positronConsole.sendEnterKey();
Expand Down
2 changes: 2 additions & 0 deletions test/smoke/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ import { setup as setupHelpTest } from './areas/positron/help/help.test';
import { setup as setupClipboardTest } from './areas/positron/console/consoleClipboard.test';
import { setup as setupLayoutTest } from './areas/positron/layouts/layouts.test';
import { setup as setupTopActionBarTest } from './areas/positron/top-action-bar/top-action-bar.test';
import { setup as setupConsoleInputTest } from './areas/positron/console/consoleInput.test';
import { setup as setupConsoleOutputLogTest } from './areas/positron/output/consoleOutputLog.test';
// --- End Positron ---

Expand Down Expand Up @@ -447,6 +448,7 @@ describe(`VSCode Smoke Tests (${opts.web ? 'Web' : 'Electron'})`, () => {
setupClipboardTest(logger);
setupTopActionBarTest(logger);
setupLayoutTest(logger);
setupConsoleInputTest(logger);
setupConsoleOutputLogTest(logger);
// --- End Positron ---
});

0 comments on commit 58e22e1

Please sign in to comment.