2

I'm having following simple paper-tabs element and I'd like to be able to assert on this on a protractor test:

<paper-tabs>
    <paper-tab ng-repeat='tab in tabs'>
        {{tab.title}}
    </paper-tab>
</paper-tabs>

On a protractor test I'd like to be able to do something like the following:

it('url to tab', function() {
    browser.get('#/my/url');
    var tabs = element(by.css('header paper-tabs'));
    tabs.getElement()(function(elem) {
        expect(elem.selected).toBe(0);

    });
});

Please note that selected is a JS property and not an HTML attribute, as stated in the polymer documentation as well:

Use selected property to get or set the selected tab.

And thus following is just returning null:

tabs.getAttribute('selected')

Isn't there a way to get to the underlying JS object? For example just as I'd type in to the Chrome-Console:

> document.getElementsByTagName('paper-tabs')[0].selected
0

I could not find anything in Protractor's API that would serve my purpose and I wonder how others are doing this?

Thanks!

amit
  • 1,991
  • 1
  • 18
  • 29
  • Does this help http://stackoverflow.com/questions/20619225/accessing-angular-inside-protractor-test – Chandermani Nov 06 '14 at 09:08
  • I was kinda hoping to be able to access the DOM element itself, rather then injecting JS via String, which is not the most elegant solution IMO. However if this the only way that works? Maybe I'm having the whole approach wrong? Thanks. – amit Nov 06 '14 at 13:48

1 Answers1

1

Try this:

it('url to tab', function() {
  browser.get('#/my/url');
  // Get all the tabs.
  var tabs = $$('[paper-tab]');    
  // select the first tab.
  expect(tabs.get(0).getAttribute('selected')).toBe(0);    
});
Andres D
  • 8,910
  • 2
  • 26
  • 31
  • 1
    Thanks but that doesn't seem to work. I think it fetches the html-attribute rather than the DOM object itself. I'm starting to realise there is no way to assert on DOM object which is a pain /: – amit Feb 12 '15 at 15:59