Can angularjs apps be automated with selenium? if yes, why should we use protractor?

50,091

Solution 1

Not sure I understand your question. Am I right to assume you'd rather use Selenium - but want to understand what you're missing?

Well - Selenium provides means to automate web browsers - and thus used for automated e2e tests. Selenium API has implementations in several major programming languages - allowing you to write your tests in Java, C#, python, ruby, JavaScript and more.

If you already have a selenium-based e2e testing framework in place - you can use it also for AngularJS web-apps. You can also write the necessary JavaScript scripts that, once ran using the webdriver - will let you do all that Protractor does - but you'll have to do it yourself (just borrow from Protractor source code).

Why is it doable? Because Protractor basically took the JavaScript implementation of Selenium Webdriver and wrapped it in a way that makes your life a bit easier when testing Angular JS web apps.

You can see specific explanations in this old post of mine: http://testautomation.applitools.com/post/94994807787/protractor-vs-selenium-which-is-easier

I'd say that if you: 1. want to write your test code in JavaScript 2. are focused on mainly Angular JS apps

You might want to consider using Protractor. Again - no magic there. Everything they did is there in their source code - so you can just take your picks if you'd rather stick with selenium.

Solution 2

protractor is an end-to-end browser automation testing framework that works through WebDriverJs which is a javascript selenium webdriver.

Quote from How it works? documentation page:

Selenium is a browser automation framework. Selenium includes the Selenium Server, the WebDriver APIs, and the WebDriver browser drivers.

Protractor works in conjunction with Selenium to provide an automated test infrastructure that can simulate a user’s interaction with an Angular application running in a browser or mobile device.

Protractor is a wrapper around WebDriverJS, the JavaScript bindings for the Selenium WebDriver API.

enter image description here

Also see:

Solution 3

With protractor, you can write e2e tests with JavaScript, the language you write with Angular app.

Also, it has Angular-specific features.

  • Its element finders wait for Angular's $digest loop and $http to finish. So you'll have less chance to struggle with sleep and timing issues.
  • You can select elements with some of common directives such as ng-model, ng-repeat, ng-bind and etc. This is somewhat handy because you may have relatively less ids and classes in Angular apps because you need them only for CSS.
Share:
50,091
Admin
Author by

Admin

Updated on July 05, 2022

Comments

  • Admin
    Admin almost 2 years

    I know that we can automate AngularJs apps with Selenium. But we have a separate E2E testing framework that is Protractor for AngularJs apps automation.

    Can anyone help me understand why we should use Protractor? Why not Selenium?