Q: What is better for testing a web application: Protractor or Selenium?
A:
Every time I’ve automated Web Applications, when coding in JavaScript, I have used the ‘core’ JavaScript library provided by the WebDriver team WebDriverJS:
- link is on the downloads page from seleniumhq http://www.seleniumhq.org/download/
- https://www.npmjs.com/package/selenium-webdriver
I use this because it keeps up to date with the main selenium code base and if you want help on the Selenium forums this one is likely to receive answers there.
This is not your only choice when working with JavaScript:
- Protractor http://www.protractortest.org/#/
- created by the Angular JS team
- designed to be used for Angular apps because it has built in synchronization for Angular applications
- protractor is built on WebDriverJS
- If your application is written using Angular, and you are writing your test execution code in JavaScript and you don’t have much experiencing automating web applications then this might be a good choice because of the default synchronisation and the documentation is based around Angular applications.
This might not be the best choice for non-angular applications because you may prefer more specific synchronisation approaches and the API might not be as flexible as you need.
If you want to use the most up to date version of WebDriverJS then you have a dependency on Protractor updating to use it, but I think this usually happens fairly quickly.
You also have:
- WebDriverIO - http://webdriver.io/
- WD.js https://github.com/admc/wd
- LeadFoot - https://theintern.github.io/leadfoot/index.html
- there are probably others
You will have to evaluate them to see which:
- works best in your environment
- offers and API that fits your coding style
Generally I try to work as close to the core library as possible to have as few dependencies on other projects as I can, and also I don’t find the main WebDriver API hard to use.
You can test Angular applications without Protractor, but you have to write code to synchronise your application effectively.
Since Protractor is open source you can read the source to understand their synchronisation mechanisms if you choose to use a different JavaScript library.
If you prefer coding in another language e.g. Java or C# then look at the download page on selenium hq and start with the official bindings.
If you find them hard to use then you might want to look for a library that sits on top of WebDriver, for that language, which offers a ‘framework’ or higher level abstraction to work with.
The benefits of sticking as close to ‘core’ library as possible are that you will find it easier to switch between different languages when coding WebDriver tests as the APIs are very similar, and you are learning WebDriver, rather than learning a separate framework or library.
You will need a Github account to comment. Or you can contact me with your comment.
I reserve the right to delete spam comments e.g. if your comment adds no value and its purpose is simply to create a backlink to another site offering training, or courses, etc.