Skip to content
This repository was archived by the owner on Jul 29, 2024. It is now read-only.

waitForAngular not waiting #96

Closed
Hardcode37 opened this issue Sep 18, 2013 · 6 comments
Closed

waitForAngular not waiting #96

Hardcode37 opened this issue Sep 18, 2013 · 6 comments

Comments

@Hardcode37
Copy link

I have some tests that fail when filtering by name, address etc..

In my view I display all results using ng-repeat and have some input boxes for filtering the results. My issue is, when the tests run all results are brought back and int one test and this test passes but when filtering the results the filter tests fail. I have tried waitForAngular but this does not work.

My results are brought back using RestAngular and a back end get request. The get request is promise based so I do not understand why I do not get the expect result back.

my test case is

it('should filter results by age: expect result to be 0', function() {
ptor.get('http://localhost:22222/#/users');
ptor.findElement(protractor.By.input('search.age')).sendKeys('29');
ptor.findElement(protractor.By.id('filterBtn')).click();
ptor.findElement(protractor.By.repeater('users in usersList.data').column('{{user.age}}')).then(function(resultingRows) {
expect(resultingRows.length).toBe(0);
});
}, 30000);

Am I doing something wrong here or should I be using webdriver to wait for n time before proceeding.

@juliemr
Copy link
Member

juliemr commented Sep 19, 2013

This looks correct, you shouldn't have to put in a waitForAngular. Not sure what's going on - can you share some more of your code? The template with the buttons and the controller code would be helpful.

@Hardcode37
Copy link
Author

controller:

appControllers.controller('UsersCtrl', ['$scope', '$location', '$dialog', 'Restangular', 'errorDialogOptions', function ($scope, $location, $dialog, Restangular, errorDialogOptions) {

$scope.searchUsers = function () {
Restangular.one("Users").customGET("Search", $scope.search).then(function (result) {
$scope.userList = result;
}, function (error) {
errorDialogOptions.resolve = { error: function () { return error.data; } };
var d = $dialog.dialog(errorDialogOptions);
d.open();
});
};
}]);

template:

            <div class="cpui-frm-row last">
                <label>Address</label>
                <input ng-model="search.address" name="Address" class="cpui-field text inverted" type="text">
            </div><!-- cpui-frm-row -->

            <div class="cpui-frm-row last">
                <label>Age</label>
                <input ng-model="search.age" name="Age" class="cpui-field text inverted" type="text">
            </div><!-- cpui-frm-row -->

            <div class="cpui-frm-row buttons last">
                <button id="searchBtn" ng-click="searchUsers(search)" class="cpui-button blue small">Filter</button>
            </div><!-- cpui-frm-row -->

        </div><!-- filter -->
        <div ng-show="userList.data.length">
            <table cellspacing="0" cellpadding="0" width="100%" class="cpui-table dark">
                <thead>
                    <tr>
                        <td>Name</td>
                        <td>AddressLine1</td>
                        <td>Age</td>
                        <td class="buttons"></td>
                    </tr>
                </thead>
                <tbody>
                    <tr ng-repeat="user in userList.data">
                        <td>{{item.name}}</td>
                        <td>{{item.address}}</td>
                        <td>{{item.age}}</td>
                        <td class="buttons">
                            <a id="editUserDetailsBtn" class="cpui-button grey tiny" ng-href="#/users/user/{{user.id}}">Edit</a>
                            <a id="deleteUserDetailsBtn" class="cpui-button red tiny" ng-click="delete(user.id)">Delete</a>
                        </td>
                    </tr>
                </tbody>
            </table>

            <pagination class="cpui-pagination" on-select-page="paginate(page)" num-pages="userList.numberOfPages" current-page="userList.currentPage" max-size="6" previous-text="&lsaquo;" next-text="&rsaquo;"></pagination>
        </div>
    </div>-->

ok so visually I see the results on screen during the test, however the test failed with expected 0 to be 1 if set to expect(resultingRows.length).toBe(1); so I am expecting a user to be found. If I expect 0 users the test passes if set to expect(resultingRows.length).toBe(0);

@juliemr
Copy link
Member

juliemr commented Sep 19, 2013

Your code seems to have a typo

ptor.findElement(protractor.By.repeater('users in userList.data').column('{{user.age}}')). // Should be userList.data instead of usersList
  then(function(resultingRows) {
    expect(resultingRows.length).toBe(0);
  });

@Hardcode37
Copy link
Author

Sorry for the delayed response. I have only just come back into work. I have checked the code and there is no typo in my original test code, it must have been a typo by me when placing the code here. I have run through other tests and they seem to be having the same issue. They are not waiting for angular to resolve before proceeding. I have placed a ptor.sleep() in the test to see if that would help but it doesn't. The tests are very sporadic, some times they pass other times they do not.

@Hardcode37
Copy link
Author

here is actual code from a failing test and the controller, service and html below

it('should accept input and redirect to /bookquote/quotes', function () {
        ptor = protractor.getInstance();
        driver = ptor.driver;
        ptor.findElement(protractor.By.input('collection.deliveryPostcode')).sendKeys('FY7 8NW');
        ptor.findElement(protractor.By.input('collection.collectionPostcode')).sendKeys('FY6 8TT');
        ptor.findElement(protractor.By.input('parcel.weight')).sendKeys('0.8');
        ptor.findElement(protractor.By.input('parcel.width')).sendKeys('25');
        ptor.findElement(protractor.By.input('parcel.height')).sendKeys('13');
        ptor.findElement(protractor.By.input('parcel.length')).sendKeys('4');

        driver.findElement(protractor.By.id('getQuoteBtn')).click().then(function () {
            ptor.sleep(10000);
            expect(driver.getCurrentUrl()).toContain('#!/bookquote/quotes');
        });
    }, 40000);

controller:

appControllers.controller('ServiceQuotesCtrl', ['$scope', '$location', '$dialog', 'QuotesService', 'errorDialogOptions', function ($scope, $location, $dialog, QuotesService, errorDialogOptions) {

$scope.select = function (index) {
        QuotesService.selectService($scope.quotes[index]).then(function (result) {
            if (result.authorised) {
                $location.path('/bookquote/booking');
            } else {
                window.location = '/Account/Login?returnUrl=' + encodeURIComponent('/#/bookquote/booking');
            }
        }, function(error) {
            errorDialogOptions.resolve = { error: function () { return error.data; } };
            var d = $dialog.dialog(errorDialogOptions);
            d.open().then(function () {
                $location.path('/');
            });
        });
    };
}]);

service:

self.selectService = function (service) { //updates the saved quote with the selected service
        self.events.loading = true;
        var webcall = Restangular.one('quotes').customPUT('updateservice', {}, {}, service);
        webcall.then(function (result) {
            self.serviceSelected = service;
            buildBooking(result.savedAddresses);
            self.events.loading = false;
            return result;
        }, function (error) {
            self.events.loading = false;
            return error;
        });
        return webcall;
    };

HTML:

<!-- <div class="cpui-content page-bookquote">
    <section ng-show="events.loading" class="section get-quote">
        <loading loading-show="events.loading" header="@QuoteStrings.Header_LoadingQuotes" message="@QuoteStrings.Info_LoadingQuotes"></loading>
    </section>
    <section ng-hide="events.loading" class="section">
        <header>
            <h2>@QuoteStrings.Header_ChooseQuote</h2>
            <p>@QuoteStrings.Info_ChooseQuote</p>
        </header>

        <div class="section-body" id="avaliableServices">
            <div ng-show="quotes.length">
                <div class="cpui-quote-cont cf" ng-repeat="quote in quotes">
                    <div class="cpui-quote cf has-3-icons">
                        <div class="partner">
                            <img ng-src="../Images/services/{{quote.courier}}.png">
                            <span class="saturday" ng-show="quote.saturday">@QuoteStrings.Saturday</span>
                        </div><span class="divider">
                                 </span>
                                      <div class="service-info">
                            <strong>{{quote.serviceName}}</strong>
                            <small>{{quote.description}}</small>
                            <div ng-click="viewIcons()" class="icons" style="cursor: pointer;">
                                <div ng-show="quote.printLabel" class="cpui-icon-cont">
                                    <i class="cpui-icon printer-required"></i>
                                    <span class="cpui-tooltip">@QuoteStrings.Printer</span>
                                </div>

                               <div ng-show="!quote.printLabel" class="cpui-icon-cont">
                                    <i class="cpui-icon printer-not-required"></i>
                                    <span class="cpui-tooltip">@QuoteStrings.NoPrinter</span>
                                </div>

                               <div ng-show="!quote.dropOff" class="cpui-icon-cont">
                                    <i class="cpui-icon collection"></i>
                                    <span class="cpui-tooltip">@QuoteStrings.Collected</span>
                                </div>

                                <div ng-show="quote.dropOff" class="cpui-icon-cont">
                                    <i class="cpui-icon drop-off"></i>
                                    <span class="cpui-tooltip">@QuoteStrings.DropAtDepot</span>
                                </div>

                                <div ng-show="quote.clickNCollect" class="cpui-icon-cont">
                                    <i class="cpui-icon click-collect"></i>
                                    <span class="cpui-tooltip">@QuoteStrings.LocalCollect</span>
                                </div>
                            </div>
                        </div>
                        <span class="divider"></span>
                        <div class="price">
                            <strong>{{quote.cost | currency:"£"}}</strong>
                            <small>{{quote.cost + quote.vat | currency:"£"}} @Labels.IncVat</small>
                        </div>
                        <span class="divider"></span>
                        <div class="buttons">
                            <a ng-click="select($index)" class="cpui-button blue"><span>@ButtonStrings.BookNow</span><i class="arrow-right"></i></a>
                            @{ 
                                var moreInfoBtn = "moreInfoBtn" + i; 
                                i++; 
                            }   
                            <a ng-click="isCollapsed = !isCollapsed" class="cpui-button green"><span>@ButtonStrings.MoreInfo</span><i class="arrow-down"></i></a> 
                        </div>
                    </div>
                    <div id="@moreInfoBtn"  ng-show="isCollapsed" class="cpui-quote-info">
                        <a ng-click="isCollapsed = !isCollapsed" class="close-button"></a>
                        <div class="info-section">
                            <div class="heading">@QuoteStrings.Header_MoreInfo</div>
                            <span ng-bind-html-unsafe="quote.serviceInfo"></span>
                        </div>

                        <div ng-show="!quote.printLabel" class="info-section">
                            <div class="heading">@QuoteStrings.NoPrinter</div>
                            <p>@QuoteStrings.NoPrinter_Info</p>
                        </div>

                        <div ng-show="quote.printLabel" class="info-section">
                            <div class="heading">@QuoteStrings.Printer</div>
                            <p>@QuoteStrings.Printer_Info</p>
                            <p>@QuoteStrings.Printer_Extra_Info</p>
                        </div>
                    </div>
                </div>
            </div>
            <div ng-show="!quotes.length" class="cpui-quote-error">
                <img src="/images/design/oh-no-percy.png" alt="">
                <h2>@QuoteStrings.NoServices</h2>
                <h3>@QuoteStrings.NoServicesInfo</h3>
            </div>  
        </div>
    </section>
</div>-->

hopefully this is something easy to fix

@juliemr
Copy link
Member

juliemr commented Sep 24, 2013

Ah, looks like this is an instance of #92. That has been fixed in master and the fix should be pushed in 0.10.0 later today.

@juliemr juliemr closed this as completed Sep 24, 2013
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants