0

I have filter list (multi-selection) and dashboard to show all items. The 1st time, the dashboard will show all items and then I will chose items in filter list, the dashboard will show items in filter list only.

So my testing is compare no. of item in filter list must equal with no. of item in dashboard.

But dashboard will be reloaded automatically every 3 seconds, the problem is Protractor cannot count elements in dashboard in time and show error that is not equal.

Is it possible to force Protractor to snapshot all elements that are showing in once time to use it to compare?

My application has been coded by AngularJS.

Below is part of code to test

it('show all visibled element', function(){
    browser.get('http://localhost:8080/dashboard/');
    browser.ignoreSynchronization = true;

    // Delay browser 
    // Refer link : http://stackoverflow.com/questions/24960290/can-protractor-be-made-to-run-slowly
    var delayLoad = browser.driver.controlFlow().execute;

    browser.driver.controlFlow().execute = function() {
        var args = arguments;

        delayLoad.call(browser.driver.controlFlow(), function() {
            // delay 500 ms for dashboard renders all items
            return protractor.promise.delayed(500);
        });

        return delayLoad.apply(browser.driver.controlFlow(), args);
    };

    var filter_expand = element(by.css('body > main > div > aside.aside.filter-bar.filters-closed > span'));
    //browser.actions().mouseMove(filter_expand)
    browser.actions().mouseMove(filter_expand).click().perform()
        .then(function(){
            var item_filter = element(by.css('body > main > div > aside.aside.filter-bar.filters-open > ng-include > div > nav > ul:nth-child(1) > li.filter-load > input:nth-child(3)'));

            item_filter.click().then(function(){
                var item_count = element(by.css('#s2id_autogen3 > ul')).all(by.css('li'));
                var dashboard_count = element(by.css('div.dashboard > main > ul')).all(by.css('li'));

                expect(item_count.count()).toEqual(dashboard_count.count());
            });
        });
})
tao hiko
  • 113
  • 1
  • 11

1 Answers1

0

My workaround is I specify the element path (CSS) and call the function that retry to find the element until found it.

See : http://darrellgrainger.blogspot.sg/2012/06/staleelementexception.html

And below is my code

function waitElement(elm,val){
        element(by.css(elm)).getText().then(function(txt){
           console.log(err_num);
           expect(txt).toEqual(val);
        }, function(err){
            if (err_num < 5) {
                err_num ++;
                waitElement(elm,val);
            }
        });
    }

    err_num = 0;
    waitElement('body > main > div > ng-view > div > main > ul > li:nth-child(1) > p.body-large.ng-binding','Found it');
tao hiko
  • 113
  • 1
  • 11