Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Test if <span> is visible with ng-show attribute

In my view I need to test if ng-show="showMsgRoundDownToHours" makes a span visible. This is the view:

<div class="highlight">
    ...     
    <span class="MsgRoundDownToHours" ng-show="showMsgRoundDownToHours">
       {{msgRoundDownToHours}}
    </span><br>
    ...
</div>

This is my Protractor Test for that scenario:

describe('c2g test', function() {
  ...
  var showMsgRoundDownToHours = element(by.css('.MsgRoundDownToHours'));
  ...
  // 10km and 229 minutes)
  it('10km, 229 minutes', function() {
    ...
    expect(showMsgRoundDownToHours).toBe(false);
    ...
  });
});

I don't know how to select that particular span. I've tried making the span a div, but this breaks the layout. I've tried assigning it a css class MsgRoundDownToHours, but this makes my console explode with errors. Is there any other way to select that span? I'm happy to do css modifications as well.

like image 872
mles Avatar asked Dec 29 '25 21:12

mles


1 Answers

Find the element and check the visibility using isDisplayed():

expect(element(by.css('span.MsgRoundDownToHours')).isDisplayed()).toBe(true);
like image 159
alecxe Avatar answered Jan 01 '26 11:01

alecxe



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!