Skip to main content
blog title image

7 minute read - AI

Automating from Console with AI Assistance

Aug 9, 2025

TLDR; Can we use the Chrome Dev Tools AI Assistance to generate code that automates an application from the Javascript console? Answer: Yes we can. Prompt to generate code, iterative amendment of prompts required.

Using AI Assistance to Generate Automated Execution Code

This video shows how I used the Chrome Dev Tools AI Assistance to generate code to automate a simple application from the Javascrip console:

Automating From Console

For years, I have written code to automate and amend applications from the Javascript console. This is actually how I learned Javascript.

I created a free course on Test Automation U that covers the basic Javascript skills around this topic.

testautomationu.applitools.com/automating-in-the-browser-using-javascript/

And a support page with more resources

And a free ebook on the topic

AI Assistance

Chrome Dev tools now has an AI Assitance tab with a chat interface designed to help you debug CSS and DOM issues.

developer.chrome.com/docs/devtools/ai-assistance

There are many use cases listed on the official site:

  • Fix styling issues
  • Fix layout issues
  • Explain and investigate Network calls
  • Explain Javascript source files
  • Improve page performance

And if it can do all that, could it augment my ability to automate applications from the console?

I decided to find out.

7CharVal

The 7CharVal application is a simple application I created with a few bugs in it.

  • it takes an input
  • you click a button
  • the app outputs if the input was a “Valid Value” or “Invalid Value”
  • to be valid the input should be 7 chars

You can find the application here:

The application is surprisingly useful for practicing testing. On Patreon I even released a 200+ page ebook of testing exercises and notes, all built around this tiny application.

Automating 7CharVal from console

I can automate the 7CharVal application from the console:

let validChars = 
    "*0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
let errors = [];

// loop over the ascii chars
for(x=0;x<256;x++){

    let aChar=String.fromCharCode(x);
    let expectValid = false;
    let resultExpected = "Invalid Value";

    // decide if the char should be valid or invalid
    if(validChars.includes(aChar)){
        expectValid=true;
        resultExpected = "Valid Value";
    }

    const checkButton = document.querySelector('input[name="validate"]')

    for(position=0;position<7;position++){

        // create the input string
        let seedString = "0000000";
        let positions = seedString.split("");
        positions[position]=aChar;
        let inputString = positions.join("");

        // input the string
        document.querySelector(
                    'input[name="characters"]').value=inputString;

        // trigger the process
        checkButton.click();

        // get the output
        let result=document.querySelector(
                    'input[name="validation_message"]').value;

        // document the result
        let reportLine = 
            `Input: "${inputString}" Dec: ${x} `+
            `Position:${position} Expected: "${resultExpected}" `+
            `Output: "${result}"`;

        // add an alert in the reportif it is not what we expected
        let resultPrefix = "";
        if(result!==resultExpected){
            resultPrefix = "**ERROR** ";
            reportLine = `${resultPrefix} ` + reportLine;
            // separate errors out into their own report
            errors.push(reportLine);
        }
        // document all the results
        console.log(reportLine);
    }
}
// report on the errors
console.table(errors);

This code:

  • iterates over 256 ascii chars
  • and adds the char into each of the 7 positions of the input string
  • and checks if the generated string is correctly marked as Valid or Invalid

It took me about 20 minutes to write by hand.

Using AI Assistance to write Code

During the iteration of prompts I decided to take a slightly different approach to automating the application and generated a wider range of inputs rather than picking a single character in a single position. This makes isolating single character issues more difficult but can provide a wide set of data inputs to flush out combination issues. e.g. strings like ‘Fe7Nsbb’, ‘znOzzQg’, ‘7O2i29a’, ‘wqOdesY’, ‘ghRGLCO’, ’lLrwH*j’

The full write up of this experiment is on my AI Experiments repo:

I iterated gradually through a series of prompts. e.g.

Create code to run in the Javascript console to enter the string “Aabbccd” into the characters field. Then press the “Check Input” button. Then check that the validation_message field shows the value “Valid Value”.

The full set of prompts can be seen in the experiment.

I tried to avoid relying on the memory context of the AI tooling and kept iterating on the prompt to produce a single output code block.

And my final prompt ended up as:

Create code to generate the list of testStrings. The test strings should be 7 characters long. Generate enough test strings such that each of the valid characters should be used at least once in a generated test string. The valid characters are A-Z, a-z, 0-9 and *. Then create code to run in the Javascript console to enter each of the generated test strings into the input field with name “characters”. Then press the input element of type button with value “Check Input” button. Then check that the validation_message field shows the value “Valid Value”. Add any inputs that pass and generate validation_message “Valid Values” to an array called validInputs. Add any of the input values that fail to generate validation_message “Valid Values” into an array called invalidInputs and throw an exception.

The generated code is below. Copy and paste it into the Javascript console when on the 7charval page and you will automate the application.

const characters = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789*";
const stringLength = 7;
const requiredCharacters = new Set(characters);
const testStrings = [];
const generatedCharacters = new Set();
let attempts = 0;
const maxAttempts = 10000; // Limit attempts to avoid infinite loops in case coverage is hard

// Generate strings until all characters are covered or max attempts reached
while (generatedCharacters.size < requiredCharacters.size && attempts < maxAttempts) {
    let randomString = '';
    let stringContainsNewCharacter = false;
    for (let j = 0; j < stringLength; j++) {
        const randomIndex = Math.floor(Math.random() * characters.length);
        const char = characters[randomIndex];
        randomString += char;
        if (!generatedCharacters.has(char)) {
            generatedCharacters.add(char);
            stringContainsNewCharacter = true;
        }
    }
     if (stringContainsNewCharacter || testStrings.length < requiredCharacters.size / stringLength + 5) {
        testStrings.push(randomString);
    }
    attempts++;
}

console.log(`Generated ${testStrings.length} test strings covering all required characters (attempted ${attempts} times).`);

const validInputs = [];
const invalidInputs = [];
const characterInput = document.querySelector('input[name="characters"]');
const checkButton = document.querySelector('input[type="button"][value="Check Input"]');
const validationMessage = document.querySelector('input[name="validation_message"]');

if (!characterInput) {
    console.error("Character input with name 'characters' not found.");
} else if (!checkButton) {
    console.error("Check Input button not found.");
} else if (!validationMessage) {
    console.error("Validation message element not found.");
} else {
    console.log("Starting validation tests...");
    for (const str of testStrings) {
        characterInput.value = str;
        checkButton.click();
        // In some cases, you might need a small delay here for asynchronous updates:
        // await new Promise(resolve => setTimeout(resolve, 50));
        if (validationMessage.value === "Valid Value") {
            validInputs.push(str);
            console.log(`Input "${str}" passed validation.`);
        } else {
            invalidInputs.push(str);
            console.warn(`Input "${str}" failed validation. Received: "${validationMessage.value}"`);
        }
    }
    console.log('Validation tests complete.');
    console.log("Valid inputs:", validInputs);
    console.log("Invalid inputs:", invalidInputs);


    if (invalidInputs.length > 0) {
        throw new Error("Validation failed for some inputs. See invalidInputs array for details.");
    }
}

Notes

The AI tooling was automating the 7charval application during the prompt and summarizing the results of the execution through the LLM.

I found that the generated code shown to me, was different from the code used by the AI tooling during its execution. The AI tooling liked to put the results in an object but didn’t do that in the code provided to me. There is a risk that its code did something different, but that could be solved by code reviews.

I found the constant reviewing of the code tiresome because each generated block of code was ’new’ and I didn’t have diffing tools in the chat window to see what was different. I could have pasted it into a diffing tool to aid my review but I gave it a cursory review and became more intersted in the output of the execution.

The AI Tooling would gradually add extra chars into the final code output making it impossible to copy and paste into the console without first editing the code. It looked like it was trying to add markdown code formatting into the code formatting.

i.e. the first line of code became

``js

This was a minor annoyance that I could work around.

Conclusion

This feature would have helped me learn Javascript, had it been around when I started automating from the console.

I will certainly use this in the future to help me generate initial code that I can edit and refine myself.

I recommend experimenting with the AI Assistance as a code generator for the use case of automating applications from within the browser itself.