Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

on_complete called multiple times #533

Open
Sergio-Mira opened this issue Nov 30, 2017 · 1 comment
Open

on_complete called multiple times #533

Sergio-Mira opened this issue Nov 30, 2017 · 1 comment
Labels

Comments

@Sergio-Mira
Copy link

Sergio-Mira commented Nov 30, 2017

We are using PhantomJS and for some reason it is reporting the same result line 3 times, which makes Teaspoon consider that it has results 3 times in a row:
{"type":"result","elapsed":"234.24000","_teaspoon":true}

Unfortunately that means test results are being printed 3 times too and it generates broken JUnit reports as too many closing tags are added.

Is there any possibility that a guard against multiple calls with result could be added to notify_formatters?

@ljluestc
Copy link

var page = require('webpage').create();
var system = require('system');
var url = system.args[1];
var resultProcessed = false;  // Guard to prevent multiple result processing

page.onConsoleMessage = function(msg) {
    system.stdout.writeLine(msg);
};

page.onCallback = function(data) {
    if (resultProcessed) {
        return; // Guard: Exit if results have already been processed
    }

    if (data && data.type === 'result') {
        resultProcessed = true; // Set guard
        var result = JSON.stringify(data);
        system.stdout.writeLine(result);
    }
};

page.open(url, function(status) {
    if (status !== 'success') {
        console.log('Unable to access network');
        phantom.exit(1);
    } else {
        page.evaluate(function() {
            if (typeof window.callPhantom === 'function') {
                window.callPhantom({
                    type: 'result',
                    elapsed: '234.24000',
                    _teaspoon: true
                });
            }
        });
    }
});

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants