We currently have automation framework using selenium Webdriver C# bindings .The application under test is being re-written in angular.The QA team is familiar with C# and selenium , so we are considering using a .net port/package for protractor.Greatly appreciate any recommendations
4 Answers
Protractor is just selenium in Taxedo:
When working with Protractor, it’s important to keep the following in mind:
- Protractor is a wrapper around WebDriverJS, the JavaScript bindings for the Selenium WebDriver API (before writing any tests, skim through the WebDriverJS Users Guide).
- WebDriver commands are asynchronus. They are scheduled on a control flow and return promises, not primitive values (see The WebDriver Control Flow).
- Your test scripts send commands to the Selenium Server, which in turn communicates with the browser driver. Read on for more details.
https://www.protractortest.org/#/infrastructure
Why you will fall in love with protractor:
- Really simple to set up ( just config file)
- Easy integration with CI/CD (runs using protractor run filename.config)
- Easy reporting ( community reports are available for jasmine framework)
- Amazing handling of asynchronous calls , you don't have to use any explicit wait in most cases if you are using a pure angular website
- Introduction of await allows to write simple synchronous step like any other language ( Turn selenium control follow of in config file using SELENIUM_PROMISE_MANAGER: false)
- In built Parallel execution support using max instance , no need to implement any complex thread safety designs like in other frameworks
- Same methods and syntax like selenium as its just a wrapper around selenium , so lesser learning curve
How to write script in protractor:
it('should find an element by text input model', async function() {
await browser.get('app/index.html#/form');
var username = await element(by.model('username'));
await username.clear();
await username.sendKeys('Jane Doe');
var name = await element(by.binding('username'));
expect(await name.getText()).toEqual('Jane Doe');
});
In protractor all protractor methods returns a promise , meaning it promises that the action will be executed but there is no promise when will it be executed.
For example :
if you do ,
uploadfile()
deletefile()
In other programing languages the code will first uploads the file and then deletes the file
But in asynchronous javascript , uploadfile() will initiate the upload action and runs it in background . And suddently goes to second line of code and tries to delete the file before its even uploaded.
Before ES6 javascript versions we handled this as :
uploadfile().then(funtion(value){
deletefile()
})
This is called chaining . Here we tell javascript to execute deletefile() only if uploadfile() operation is completed.
BUt from ES6 we have await , which does the same thing but the syntax is:
await uploadfile()
await deletefile()
so here code pointer goes to next line only if uploadfile() action completes ( it can be success or fail )
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/await
so after introduction of await, protractor is the simplest tool to be used for angular website. It supports all selenium methods so you don't have to learn anything new
The application under test is being re-written in angular
It really doesn't matter in functional UI automation since you are testing the rendered DOM.
The QA team is familiar with C# and selenium
You will lose considerable time due to retraining. You might also have a harder time staffing the more you go into specific tools.
We are considering using a .net port/package for protractor
Switch if your Devs are going to contribute to the automated functional tests (like in BDD).
IMO, Changing the any Automation tech because of some minor or big bang changes in Application under test doesn't really make sense or gives you good ROI.
But consider following scenario
- The current Automation framework is not that great and not serving all of the Testing team's purpose.
- The current Automation framework is an existing one and everyone always wanted to replace it but couldn't justify the ROI of rewriting it
- Consider the bandwidth assigned to rewriting it and the available help in the Project team ( dev + architects ) , don't take as overhead if team is not agreed on time in rewriting it
- Writing new Framework is easier than training new QA's on old one
While @ErrorHunter gives a good general answer it actually implies that you should use Protractor.
The plain Selenium doesn't have good support for Angular applications, especially for the asynchronous nature of Angular while Protractor natively supports wait functions, so if we examine @ErrorHunter points:
The current automation framework will break and have a hard time handling Angular
It is easy to justify the ROI for replacing the automation framework, the effort to stabilize, fix and maintain the old framework will be considerable. It will also suffer from a lot of downtime due to Selenium's sensitivity to timing.
Converting from Selenium to Protractor is not a full re-write, you don't have to convert a poorly written Selenium test to Protractor test with POM in one go, you can simply add wait()'s where necessary and so on. The conversion will also greatly assist in testing a developed application, for example by verifying new behavior as kind of automation assisted exploratory testing, especially if the conversion is done in parallel or by the same developers.