Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Access Angular directive/component instances in Protractor test

I have an Angular application. In Angular unit tests (karma / jasmine) I can access component instances and directives via ComponentFixture / DebugElement.

Is that somehow also possible when running an e2e test via Protractor?

like image 664
Markus Ende Avatar asked Nov 24 '25 23:11

Markus Ende


1 Answers

getDebugNode(domElement) can be used to get debug element inside the application, because it should be imported from @angular/core.

ng.probe(domElement) is global and can be used to get debug element outside the application.

Component instance is available on debug element as debugElement.componentInstance. As for directive instances and other providers, debugElement.injector(SomeClass) can be used to access them, as explained in this answer.

like image 181
Estus Flask Avatar answered Nov 26 '25 13:11

Estus Flask



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!