Wolfgang Beyer | 59566d3 | 2020-07-03 12:52:42 | [diff] [blame] | 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 | |
| 5 | import {assert} from 'chai'; |
Wolfgang Beyer | 59566d3 | 2020-07-03 12:52:42 | [diff] [blame] | 6 | |
| 7 | import {getBrowserAndPages, step} from '../../shared/helper.js'; |
Jack Franklin | e839c0c | 2022-05-03 08:47:44 | [diff] [blame] | 8 | import { |
| 9 | focusConsolePrompt, |
| 10 | navigateToConsoleTab, |
| 11 | turnOffHistoryAutocomplete, |
| 12 | typeIntoConsole, |
| 13 | typeIntoConsoleAndWaitForResult, |
| 14 | } from '../helpers/console-helpers.js'; |
Wolfgang Beyer | 59566d3 | 2020-07-03 12:52:42 | [diff] [blame] | 15 | |
Benedikt Meurer | cb7952f | 2024-02-21 13:32:23 | [diff] [blame] | 16 | describe('The Console Tab', () => { |
Alex Rudenko | a224c32 | 2024-11-27 14:12:29 | [diff] [blame] | 17 | it('exposes the last evaluation using "$_"', async () => { |
Wolfgang Beyer | 59566d3 | 2020-07-03 12:52:42 | [diff] [blame] | 18 | const {frontend} = getBrowserAndPages(); |
| 19 | |
| 20 | await step('turn off "Autocomplete from history"', async () => { |
| 21 | await navigateToConsoleTab(); |
| 22 | await turnOffHistoryAutocomplete(); |
| 23 | await focusConsolePrompt(); |
| 24 | }); |
| 25 | |
| 26 | await step('enter "1+1" in console', async () => { |
Nikolay Vitkov | 92b8346 | 2025-02-13 12:28:55 | [diff] [blame] | 27 | await typeIntoConsoleAndWaitForResult('1+1'); |
Wolfgang Beyer | 59566d3 | 2020-07-03 12:52:42 | [diff] [blame] | 28 | }); |
| 29 | |
| 30 | await step('enter "$_" in console', async () => { |
Nikolay Vitkov | 92b8346 | 2025-02-13 12:28:55 | [diff] [blame] | 31 | await typeIntoConsoleAndWaitForResult('$_'); |
Wolfgang Beyer | 59566d3 | 2020-07-03 12:52:42 | [diff] [blame] | 32 | }); |
| 33 | |
| 34 | await step('check the evaluation results from console', async () => { |
| 35 | const evaluateResults = await frontend.evaluate(() => { |
| 36 | return Array.from(document.querySelectorAll('.console-user-command-result')).map(node => node.textContent); |
| 37 | }); |
| 38 | assert.deepEqual(evaluateResults, ['2', '2'], 'did not find expected output in the console'); |
| 39 | }); |
| 40 | |
| 41 | await step('enter "console.clear()" in console', async () => { |
Nikolay Vitkov | 92b8346 | 2025-02-13 12:28:55 | [diff] [blame] | 42 | await typeIntoConsole('console.clear();'); |
Wolfgang Beyer | 59566d3 | 2020-07-03 12:52:42 | [diff] [blame] | 43 | }); |
| 44 | |
| 45 | await step('wait for the console to be cleared', async () => { |
| 46 | await frontend.waitForFunction(() => { |
| 47 | return document.querySelectorAll('.console-user-command-result').length === 1; |
| 48 | }); |
| 49 | }); |
| 50 | |
| 51 | await step('enter "$_" in console', async () => { |
Nikolay Vitkov | 92b8346 | 2025-02-13 12:28:55 | [diff] [blame] | 52 | await typeIntoConsoleAndWaitForResult('$_'); |
Wolfgang Beyer | 59566d3 | 2020-07-03 12:52:42 | [diff] [blame] | 53 | }); |
| 54 | |
| 55 | await step('check the evaluation results from console', async () => { |
| 56 | const evaluateResults = await frontend.evaluate(() => { |
| 57 | return Array.from(document.querySelectorAll('.console-user-command-result')).map(node => node.textContent); |
| 58 | }); |
| 59 | assert.deepEqual(evaluateResults, ['undefined', 'undefined'], 'did not find expected output in the console'); |
| 60 | }); |
| 61 | }); |
| 62 | }); |