I am testing an Angular site. I had been using Webdriver in Java but I was not able to identify elements on the page with normal IDs, xpaths or classes.

I did additional research and it looks like I may be forced to go the JavaScript route. I looked into Protractor and Jasmine but I am not a fan of the Jasmine syntax.

Are there alternative solutions to testing Angular sites without the use of Protractor/Jasmine? I am not interested in Cucumber or Mocha or any solution that resembles that syntax or those frameworks.

If I can use Java somehow that would be great. I am a big fan of Selenium Webdriver and prefer any solution with that tool. On a side note, I have looked into NodeJS and WebdriverJS, it seems rather fragile but I am looking into that at the moment.

Any input is appreciated.

网友答案:

What makes Protractor the perfect choice for AngularJS end-to-end testing automation is that it was made and designed specifically for testing AngularJS apps - it works in sync with Angular knowing when Angular is ready to be interacted with eliminating all of the unnecessary delays and waits you might have added to wait for the page to load or specific elements to be shown:

You no longer need to add waits and sleeps to your test. Protractor
can automatically execute the next step in your test the moment the
webpage finishes pending tasks, so you don’t have to worry about
waiting for your test and webpage to sync.

There are also AngularJS-specific locators like by.binding, by.model, by.repeater etc.

It's also important to understand that Protractor is just a convenient wrapper around WebDriverJS - javascript selenium bindings.

Sure, you can use bare java selenium bindings to test an Angular app, but you'll have to handle all of the waits manually yourself which would at least make your test codebase more complicated and less readable. The test flow would not be as natural as it could've been with Protractor.

Additionally, there are similar to Protractor packages in other languages:

pytractor (Python)

protractor-net (C#)

网友答案:

We are using Selenium Webdriver / Java to develop test scripts for Angular JS web application. I can relate to your dislike of Jasmine syntax.

The procedure we are following is to have a standard set for attribute
Ids attached to the web components using which we are able to identify
the element. (By.id) (For this you will need support of Development team)

Other than that , even when element ids are not available and web
components contain attributes like ng-bind , ng-model etc.,I have been
successful in identifying elements using xpath.

Can you please put little more details of the detailed html where you are unable to identify using xpath.