blob: a0cec0dc969f8bbcc3d61af32d52c074877f2549 [file] [log] [blame]
Wolfgang Beyer59566d32020-07-03 12:52:421// 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';
Wolfgang Beyer59566d32020-07-03 12:52:426
7import {getBrowserAndPages, step} from '../../shared/helper.js';
Jack Frankline839c0c2022-05-03 08:47:448import {
9 focusConsolePrompt,
10 navigateToConsoleTab,
11 turnOffHistoryAutocomplete,
12 typeIntoConsole,
13 typeIntoConsoleAndWaitForResult,
14} from '../helpers/console-helpers.js';
Wolfgang Beyer59566d32020-07-03 12:52:4215
Benedikt Meurercb7952f2024-02-21 13:32:2316describe('The Console Tab', () => {
Alex Rudenkoa224c322024-11-27 14:12:2917 it('exposes the last evaluation using "$_"', async () => {
Wolfgang Beyer59566d32020-07-03 12:52:4218 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 Vitkov92b83462025-02-13 12:28:5527 await typeIntoConsoleAndWaitForResult('1+1');
Wolfgang Beyer59566d32020-07-03 12:52:4228 });
29
30 await step('enter "$_" in console', async () => {
Nikolay Vitkov92b83462025-02-13 12:28:5531 await typeIntoConsoleAndWaitForResult('$_');
Wolfgang Beyer59566d32020-07-03 12:52:4232 });
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 Vitkov92b83462025-02-13 12:28:5542 await typeIntoConsole('console.clear();');
Wolfgang Beyer59566d32020-07-03 12:52:4243 });
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 Vitkov92b83462025-02-13 12:28:5552 await typeIntoConsoleAndWaitForResult('$_');
Wolfgang Beyer59566d32020-07-03 12:52:4253 });
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});