Search code examples
javascriptprotractorjasmine-nodejasmine2.0

How to report posted payment is completed or skipped or failed in protractor


As my application has a payment status that changes every time based on settings, i wanted to publish in a report that for this test cases payment made is completed. Here is the code-

<td class="" ng-switch="" on="lineItem.statusString" ng-show="lineItem.statusString" style="">
<!-- ngSwitchWhen: Unknown -->
<!-- ngSwitchWhen: Initiated -->
<!-- ngSwitchWhen: Validating -->
<!-- ngSwitchWhen: Processing -->
<!-- ngSwitchWhen: Failed -->
<!-- ngSwitchWhen: Cancelled -->
<!-- ngSwitchWhen: Refunded -->
<!-- ngSwitchWhen: Ready -->
<!-- ngSwitchWhen: Completed -->
<div class="ng-scope" ng-switch-when="Completed" style="">
<!-- end ngSwitchWhen: -->
<!-- ngSwitchWhen: Skipped -->
<!-- ngSwitchWhen: Errored -->
</td>
<td class="ng-binding ng-hide" ng-show="!lineItem.statusString" ng-bind-html="receiptTemplate.ready" style="">Ready</td>
<div class="ng-scope" ng-switch-when="Completed" style="">
<img src="/images/success.gif"/>
<span class="ng-binding" ng-bind-html="receiptTemplate.complete">Completed</span>
</div>
<!-- end ngSwitchWhen: -->
<!-- ngSwitchWhen: Skipped -->
<!-- ngSwitchWhen: Errored -->
</td>

Here is the code snippet that i have tried using Protractor,

element(by.css('[ng-bind-html="receiptTemplate.ready"]')).isPresent().then(function () {
            browser.sleep(5000);
            (element.all(by.binding('receiptTemplate.skip'))).isPresent().then(function (skip) {

                if (skip) {
                    console.log('Payment is Skipped');
                }
            });
            element.all(by.binding('receiptTemplate.complete')).isPresent().then(function (complete) {
                if (complete) {
                    console.log('Payment is Completed');
                }
            });
        });

Please let me know how i can make my code more sequential and better reporting. Thanks!


Solution

  • If all statuses are in span and it could be only one status on one time, you can try that:

    element(by.css('[ng-bind-html="receiptTemplate.ready"]')).isPresent().then(function () {
        browser.sleep(5000);
        element.all(by.css('span')).getText().then(function (currentText) {
            console.log(currentText);
        });
    });