Message box pop up while during test

I have a test running through test cafe studio that goes to the website, clicks on a page and pauses. During the pause I would like a message box to pop up and display a comment (to be used as a teaching tool explaining what is happening on the site). I have tried several options but they're not working. I'm very new to this and might be missing something?

Thanks in advance! Here's my code for a simple test

import { Selector, ClientFunction } from 'testcafe'; import {popups} from 'popups'; fixture svdemo manager cockpit .page http://localhost/SvManagerCockpit/home .httpAuth({ username: 'myusernamehere', password: 'mypasswordhere', domain: 'mydomainhere' });

test('Pause', async t => { await t .click(Selector('span').withText('Machine OEE Dashboard')) .wait(10000); popup.alert({ content: 'Hello!' }); return 1; });

await t
 .expect(alert()).eql(1);

}); I expect to insert some code in the .js test to produce a message box/dialog box in the browser.

Upvotes: 0

Views: 1447

Answers (2)

Dmitry Ostashev
Dmitry Ostashev

Reputation: 2348

Is your popup.alert a ClientFunction? If so, it should be called with the await keyword. Please take a look at the following example showing how to implement such a test:

import { Selector, ClientFunction } from 'testcafe';

fixture `testcafe`
    .page `https://devexpress.github.io/testcafe/`;

test('Test with message box', async t => {
    const showMessageBox = ClientFunction(message => {
        return new Promise(resolve => {
            var msgBox = document.createElement('div');
            msgBox.textContent = message;
            msgBox.style['top'] = '500px';
            msgBox.style['left'] = '500px';
            msgBox.style['position'] = 'absolute';
            msgBox.style['font-size'] = 'x-large';
            document.body.appendChild(msgBox);
            setTimeout(() => {
                document.body.removeChild(msgBox);
                resolve();
            }, 4000);            
        });
    });

    await t
        .click(Selector('span').withText('Docs'));
    await showMessageBox('Docs link was clicked!');
    await t
        .click(Selector('a').withText('Using TestCafe'));
});

Upvotes: 3

Tori
Tori

Reputation: 65

Just from a super quick glance, you don't have semicolons at the end of your alerts? Maybe try adding those and see what happens.

If that doesn't work, please post your full code so we can take a look!

Upvotes: 1

Related Questions