1// Copyright 2020 The Chromium Authors. All rights reserved. 2// Use of this source code is governed by a BSD-style license that can be 3// found in the LICENSE file. 4 5import {assert} from 'chai'; 6 7import {click, getBrowserAndPages, step} from '../../shared/helper.js'; 8import {describe, it} from '../../shared/mocha-extensions.js'; 9import {CONSOLE_TAB_SELECTOR, focusConsolePrompt, typeIntoConsole, typeIntoConsoleAndWaitForResult} from '../helpers/console-helpers.js'; 10 11describe('The Console Tab', async function() { 12 it('is cleared via the console.clear() method', async () => { 13 const {frontend} = getBrowserAndPages(); 14 await click(CONSOLE_TAB_SELECTOR); 15 await focusConsolePrompt(); 16 17 await step('enter 1 in console', async () => { 18 await typeIntoConsoleAndWaitForResult(frontend, '1;'); 19 }); 20 await step('enter 2 in console', async () => { 21 await typeIntoConsoleAndWaitForResult(frontend, '2;'); 22 }); 23 await step('enter 3 in console', async () => { 24 await typeIntoConsoleAndWaitForResult(frontend, '3;'); 25 }); 26 await step('Check the evaluation results from console', async () => { 27 const evaluateResults = await frontend.evaluate(() => { 28 return Array.from(document.querySelectorAll('.console-user-command-result')).map(node => node.textContent); 29 }); 30 assert.deepEqual(evaluateResults, ['1', '2', '3'], 'did not find expected output in the console'); 31 }); 32 await step('enter console.clear() in console', async () => { 33 await typeIntoConsole(frontend, 'console.clear();'); 34 }); 35 await step('wait for the console to be cleared', async () => { 36 await frontend.waitForFunction(() => { 37 return document.querySelectorAll('.console-user-command-result').length === 1; 38 }); 39 }); 40 await step('check that the remaining text in the console is correct', async () => { 41 const clearResult = await frontend.evaluate(() => { 42 return document.querySelector('.console-user-command-result')!.textContent; 43 }); 44 assert.strictEqual(clearResult, 'undefined', 'the result of clear was not undefined'); 45 }); 46 }); 47}); 48