wswebcreation / protractor-image-comparison

npm-module to compare images with protractor
86 stars 38 forks source link

Possible handle comparison with custom matcher? #98

Closed danielwai closed 5 years ago

danielwai commented 5 years ago

Hi, I am new to this. Now I try to use custom matcher to compare the result and try to catch error if it throw. Something like this.

    var deferred = protractor.promise.defer();

    try{
        expect(await browser.imageComparison.checkScreen("sampleImage", {
            blockOut: blockOutElementsArr,
            hideElements: hideElementArr,
            removeElements: removeElementArr
        })).toMatchImage(0);
        deferred.fulfill();
    } catch (err){
        deferred.reject(err);
    }
    return deferred.promise;  

The matcher is:

toMatchImage: function(){
            return {
                compare: function(actualResult, expectResult){
                    var result = {
                        pass: actualResult === expectResult,
                        message: "Expected image but display incorrect"
                    };

                    if(!result.pass){
                        throw new Error(result.message);
                    }
                    return result;
                }
            };
        }

When I run protractor to process, it throw UnhandledPromiseRejectWarning: CancellationError: There was an uncaught error in the control flow: "Expected image but display incorrect"

wswebcreation commented 5 years ago

Hmm,

Not really understand what you try to do here. This is also not related to the module, I'm going to close it for now because it's not a bug, but it's still open for discussion

danielwai commented 5 years ago

I try to use custom matcher to compare the result. If I perform the checkscreen then compare result using my matcher, it works normally, but if it is handle under block Promise, then it failed and throw the UnhandledPromiseRejectionWarning error.

Sent from Outlookhttp://aka.ms/weboutlook


From: Wim Selles notifications@github.com Sent: 01 July 2019 19:58 To: wswebcreation/protractor-image-comparison Cc: danielwai; Author Subject: Re: [wswebcreation/protractor-image-comparison] Possible handle comparison with custom matcher? (#98)

Hmm,

Not really understand what you try to do here. This is also not related to the module, I'm going to close it for now because it's not a bug, but it's still open for discussion

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHubhttps://github.com/wswebcreation/protractor-image-comparison/issues/98?email_source=notifications&email_token=ADSUPVTOBQKJT7WI6WK6W7DP5HWNVA5CNFSM4H4DMW3KYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGODY54SCI#issuecomment-507234569, or mute the threadhttps://github.com/notifications/unsubscribe-auth/ADSUPVWZB7XAQ3YO3VRCYEDP5HWNVANCNFSM4H4DMW3A.

[https://ipmcdn.avast.com/images/icons/icon-envelope-tick-round-orange-animated-no-repeat-v1.gif]https://www.avast.com/sig-email?utm_medium=email&utm_source=link&utm_campaign=sig-email&utm_content=webmail Virus-free. www.avast.comhttps://www.avast.com/sig-email?utm_medium=email&utm_source=link&utm_campaign=sig-email&utm_content=webmail

wswebcreation commented 5 years ago

Again, not sure what you want to do with your code, it also looks like you mixing up promises with the deferred and the async await. That might cause the problem