How It Differs From Normal Web Application For Automation Testers?
There are some common attributes like ID, name, and value for HTML elements which are used for locating. But Angular extends HTML and assigns new attributes called directives which create dynamic HTML content with the help of these attributes. It uses variable functionalities where sometimes we are not able to find the value of the attribute using inspector. This causes us to search in source code for the HTML page. Some angular attribute names are ng-bind, ng-class, ng-model, ng-options…etc. But Selenium provides element locating techniques using ID name and class attributes which may not be there in Angular applications.
( Learn Why Selenium is Most Widely Used Test Automation Tool? )
Is Protractor Only Choice to Automate Angular Applications?
Protractor is an end-to-end test framework designed specially to automate Angular and AngularJS applications. It supports Angular-specific locator strategies, which allows you to test Angular-specific elements without any setup effort on your part. It can automatically execute next steps in your tests the moment the web page finishes its pending tasks-so you don’t have to worry about waiting for your test and web page to sync.
- LOC (lines of code) for test designing is higher
- Advanced features available in java unit testing frameworks like TestNG, JUnit
- At least 60% of companies are using Selenium with Java and so more support is available through blogs/communities/forums/GitHub
But Selenium with Java doesn’t have the features that are available in Protractor when automating Angular applications.
How to Get Protractor Features in Selenium With Java Test Development?
With the help of this library:
- It provides new locating techniques to use Angular Specific Attributes
- It also provides FindBy annotations for creating Page Object Factories
The above features provide more ease in automating Angular Applications using Selenium with Java.
Creating Tests Using ngWebDriver
The first is to import ngWebDriver library from maven or attach ngWebDriver jar file to projects build path.
Maven Dependency XML Code
Now with the help of ngDriver variable we can handle angular specific waiting issues. The above code will wait for angular requests to finish.
Creating Locators Using Angular Attributes
Similar to By class in WebDriver, there is ByAngular class in ngWebdriver which has all the locators related to use angular attributes.
ByAngular class having methods like binding, model, options, repeater to use attributes ng-bind, ng-model, ng-options, ng-repeat. It also provide all protractor locator strategies which are useful to find buttons with text/partial text using buttonText and partialButtonText locators. One more great feature is to find elements using css selectors with containing text using cssContainingText locator.
Creating Page Object Factories using ngWebDriver Locators
Page Object Factories or Models can be created with the same technique like how they will be created for non-angular applications by just importing ngWebDriver’s Angular locators.
What About Support?
You need to follow the same way of selenium like how we get support through Selenium GitHub Issue log, there is an issue log for ngWebDriver in GitHub. So we can expect similar kind of support.
This article is to explain how Angular Applications can be automated using Selenium with Java without using Protractor. Please do remember that ngWebDriver is created by having java Script that is created for Protractor Test Automation.