I want to use Protractor on Java and not on Node.js. Is it possible to use Protractor with Java or Python? We do not want to add another technology for testing and want to use existing technologies.
相关问题
- Delete Messages from a Topic in Apache Kafka
- Jackson Deserialization not calling deserialize on
- How to maintain order of key-value in DataFrame sa
- StackExchange API - Deserialize Date in JSON Respo
- Difference between Types.INTEGER and Types.NULL in
To add something to Tom's answer above, you can even test non-angular based apps/websites with Protractor. But there is still no way, you can write Protractor tests using Java or Python as Protractor's core is built on Javascript(node.js) and is purely Javascript. Hope it helps.
There is already a library in Java for automating Angular stuffs. Its built based on Protractor called "ngWebDriver"
The best way to use protractor is , have protractor tests separately written in javascript, and call those tests from java/python when ever required. Thats what we are currently doing!
As of 2017, I have found these Protractor libraries for Java:
Code Snippet:
Unfortunately you don't have much of a choice in the matter, as Protractor is a JavaScript Testing framework for AngularJS, it is distributed via Node.js.
Protractor is customized for angularJS applications. So if your application was created using AngularJS, Protractor will help as it has inbuilt support for AngularJS page load and actions.
If your application is not built on top of Angular, you can use Selenium WebDriver on top of any other languages you prefer.
Selenium provides users with documentation on using Python as a medium to write tests, read more about this here.
Protractor is a JS library so you can't run it in Java and testing Angular apps without Protractor is difficult because your tests code needs to wait for Angular processes to complete before interactions like clicking occur.
Fortunately, Angular has made it easy to identify when it's done processing.
There is a JS function that takes a callback and will notify you once the Angular is ready.
NOTE: That this works with Angular 1.4.8. Some other versions of Angular have a different method that is similar.
You can invoke the testability method from your Java test code using the following simple method or something similar.
Call waitForAngular() before interacting with the driver with a method like click.
You may want a different rootSelector from 'body' and you may want to throw an error if angular doesn't exist but this works well for my needs.
Protractor provides other selectors which may make testing an Angular app easier but personally I use ID and Class selectors so I don't need them.