0
votes

On the bellow code, how can i get the value "Start test"?

<div class="nea-sidebar" _ngcontent-c2="">
<a class="sidebar-item active" href="#/test" _ngcontent-c2="" routerlinkactive="active" ng-reflect-router-link="test" ng-reflect-router-link-active="active">
<i class="sidebar-icon fas fa-play" _ngcontent-c2="" ng-reflect-klass="sidebar-icon fas" ng-reflect-ng-class="fa-play"></i>
<span class="sidebar-label" _ngcontent-c2="">Start Test</span></a>

<a class="sidebar-item" href="#/sequences" _ngcontent-c2="" routerlinkactive="active" ng-reflect-router-link="sequences" ng-reflect-router-link-active="active">
<i class="sidebar-icon fas fa-project-diagram" _ngcontent-c2="" ng-reflect-klass="sidebar-icon fas" ng-reflect-ng-class="fa-project-diagram"></i>
<span class="sidebar-label" _ngcontent-c2="">Sequences</span></a>

.
.
.
/>

I'm using: element(by.className('sidebar-label')).isDisplayed().then(function(isVisible) { if (isVisible) { // tests -- validar caminho, icon ... label sidebar-label expect(element(by. className('sidebar-label')).getAttribute('_ngcontent-c2')).toBe('Start Test'); }

But it returns failed due " - Expected '' to be 'Start Test'.

1
Don't post screenshots of code, copy the relevant bit of code into your question body. - Haem
I just changed it. Thank you. - Carlos Rodrigues

1 Answers

0
votes

You can do this:

element(by.css('.nea-sidebar '))
.element(by.cssContainingText('.sidebar-label', 'Start Test')).isDisplayed()
   .then(function(isDisplayed) {
     expect(isDisplayed).toBeTruthy();
 });

by.cssContainingText(selector, text) looks for an element with given selector containing a given text. If that element is displayed, that means protractor actually found such element containing such text.