Skip to content Skip to sidebar Skip to footer

Where Are Scripts In Injectscripts Injected In Testcafé Tests?

I am setting up TestCafé tests programmatically and I use the injectScripts config on the Runner class to inject functions. According to the documentation, these scripts are added

Solution 1:

You can use the ClientFunction or eval APIs to address injected scripts or any other client script from a test. Please take a look at the following example:

const scriptContent = `
function alertHelloWorld () {
    alert('Hello world!');
}`;

fixture `My fixture`
    .page `https://example.com`
    .clientScripts({ content: scriptContent });

test('New Test', async t => {
    await t.setNativeDialogHandler(() => true);

    await t.eval(() => alertHelloWorld());

    const history = await t.getNativeDialogHistory();

    await t
        .expect(history[0].type).eql('alert')
        .expect(history[0].text).eql('Hello world!');
});

Post a Comment for "Where Are Scripts In Injectscripts Injected In Testcafé Tests?"