1

I'm currently writing some Protractor tests for an app. But in the app i'm using controller as syntax as the pieces I want to work on are components. The problem is that when i use the selector of "" $ctrl.functionName"" it's giving me an illegal selector statement.

Anyone have any ideas about this?

let btn = $$("button[ng-click^=$ctrl.initRequest].secondary.bf-btn");
        expect(btn.isDisplayed()).toBe(true);

The error message is

Failed: invalid selector: An invalid or illegal selector was specified
Evan Burbidge
  • 827
  • 9
  • 16
  • Please share Code. – Kishan Patel Mar 20 '17 at 11:04
  • 2
    Why don't you assign a semantic ID or class to your button instead of relying on low-level implementation details to select it? The test shouldn't have to care about controller vs. controllerAs. It should find the button identified by "init-request" (for example), and test whether it's displayed or not. – JB Nizet Mar 20 '17 at 11:25
  • I think we'll have to do that from now on a lot of features on the application haven't been given strict ID's. Must mail the people working on it to start putting id's onto buttons and elements. – Evan Burbidge Mar 20 '17 at 11:33
  • 2
    @JBNizet is right. In addition to it not working, if you couple your tests to internals like that they will break constantly. Maintenance nightmare... – Aluan Haddad Mar 20 '17 at 11:38

1 Answers1

1

If you cannot assign a meaningful id or other attribute to the element, you need to fix your current selector. At the very least, there should be quotes around the ng-click value:

button[ng-click^='$ctrl.initRequest'].secondary.bf-btn

Note that a slightly better version, that would also not require quotes, would be to use a partial match:

button[ng-click*=initRequest].secondary.bf-btn

And, see if you can drop the questionable classes and have just:

button[ng-click*=initRequest]
alecxe
  • 462,703
  • 120
  • 1,088
  • 1,195