How to perform End to End Testing in Angular

On This Page End to End Testing of Angular Apps expend Protractor

May 26, 2026 · 11 min read · Testing Guide

How to execute End to End Testing in Angular

tests an application entirely, verifying whether its flow from beginning to end behaves as ask or not. Unlike unit testing, which focus on a exceptional unit of the entire product—such as the database, mesh, or file system; E2E testing tests if all these individual units work well when they are desegregate.

E2E examination is important because it exercises the application in the close potential way to a real end-user experience.

End to End Testing of Angular Apps using Protractor

End-to-end examination (E2E) of Angular applications is performed utilize the, which is created by the Angular team themselves. Protractor can perform end to end trial on Angular coating that are running in a real browser by interacting with it, similar to that of an end-user.

How Protractor Framework Works

Protractor is a Node covering pen on top of Selenium ’ s WebDriverJS. You can understand it as a wrapper around WebDriverJS, which provides some extra features to examine Angular applications.

The components of Protractor end to end test architecture are as postdate:

  • Protractor:Wrapper for WebDriverJS
  • WebDriverJS:JavaScript binding for Selenium WebDriver in JavaScript.
  • :such as Jasmine or Mocha.
  • Browser:such as Chrome, Firefox.
  1. End-to-end test scripts are generally compose using the Jasmine framework. After Protractor launches, it hands the execution of your tests over to Jasmine (or Mocha, or, or whichever trial framework you prefer).
  2. Based on the steps defined in Jasmine tests, Protractor uses WebDriverJS to send corresponding commands (text inputs, button clicks, etc) to the Selenium Server.
  3. The Selenium Server find WebDriver dictation from the protractor and consequently command the browser using vendor-specific browser driver (Chrome, Firefox, Safari, etc).

How to Install Protractor

To establish Protractor via npm, you demand to getNode.js installalready. Once NodeJS is establish successfully, open the terminal and run the undermentioned command to instal Protractor:

npm install -g protractor

As soon as the installation finishes, use the following command to verify Protractor ’ s version:

protractor -- version

The above installation command installs two executables, i.e., Protractor and webdriver-manager, an executable for starting the Selenium Server instance.

Create Angular E2E Test using Protractor

The Configuration file configures Protractor, allowing it to locate the test file, and helps understand which framework or web browser to use. When the user in the configuration file does not define a specific configuration, then Protractor uses the nonpayment configuration. While the Spec file is the actual test file containing the affirmation to be verified.

Creating Spec File

To write the initiatory Protractor exam case, let ’ s start with the specification file. Open a text editor, make a new file, and enter the following code snipping on it:

describe ('Protractor Testing ', function () {it ('to check the page rubric ', function () {browser.ignoreSynchronization = true; browser.get ('https: //example.com/ '); browser.driver.getTitle () .then (function (pageTitle) {expect (pageTitle) .toEqual ('Example Domain ');});});});

Save the file gensmyFirstTestSpec.js.

Words describe and itbelong to Jasmine ’ s syntax, wheredescribecontains the whole flow of your test, whileitcontains a specific step or scenario. You can setignoreSynchronization to truewhen the website under trial isn ’ t an Angular coating but a regular website and mistaken when the website under examination is an angular application by using thebrowserglobose to hit the target URL and retrieve the value of its title. Finally, the assertionhereverifies whether the obtained page title is adequate to the expected one.

Creating Configuration File

Again, create a white text file apply any text editor. Then, inscribe the next code snippet in it.

exports.config = {framework: 'jasmine ', seleniumAddress: 'http: //localhost:4444/wd/hub ', capabilities: {browserName: 'chrome ',}, specs: ['myFirstTestSpec.js ']};

Save the file, naming itconf.js.

Here, the initiatory option isframework, with the valuejasmine. Jasmine, as discussed above, is a popular testing framework for JavaScript. Thecapabilitiessubdivision, defines the browser name, which is Chrome here. Thespecssection indicates the route to the spec file.

Read More:

E2E test using Protractor with Selenium

Running a Protractor test but ask executing a single command. But prior to that, the local Selenium server must be set. This can be done by running the undermentioned dictation:

webdriver-manager update

This will download all the necessary binaries needed to start the Selenium server. The future step simply begin the instance:

webdriver-manager start

As the Selenium Server is running at embrasure 4444, the following content is see

Now that Selenium Server is running, the scheme is ready to run the test. Open a new terminal window and enroll the next command:

protractor conf.js

If everything proceed well, a Chrome window will open, with the example.com website opened. In the terminal, the output can be seen as

As seen above, the yield content reads1 specification, 0 failure. This indicates that the code had 1 it block, which was fulfil with 0 failures.

Run End to End Test straight using Protractor

With Protractor, it is also possible to motor the browser directly, without executing the Selenium server explicitly. For doing that, change the shape file and add the following command to it:

directConnect: true

The complete file should look like this:

exports.config = {directConnect: true, framework: 'jasmine ', capabilities: {browserName: 'chrome ',}, specs: ['myFirstTestSpec.js ']};

This allow executing the tests directly, without having to start the Selenium host at porthole 4444.

Protractor Alternatives

According to the Protractor ’ s announcement on Github, the Angular squad will stop the evolution of Protractor by the end of 2022 in conjunction with Angular v15.

This intend that users demand to migrate from Protractor since there will not be any farther update to the framework.

This also mean the Angular squad will not consider bug or characteristic requests.

For autonomous testing across multiple user personas, check out SUSATest — it explores your app like 10 different real users.

Users may end up with disruption in their automation playscript by proceed to use Protractor.

​​Top 6 to migrate Protractor tryout to:

Protractor Alternatives:

End to End Testing in Angular using Nightwatch.js

Nightwatchis built in Node.js and allows you to write tests even if you don ’ t have any experience with it. Nightwatch.js enables you to write end-to-end tests in Node.js quickly and effortlessly that run against a Selenium/WebDriver server ”.

Nightwatch usageW3C WebDriver API() for controlling DOM elements and browser interface to make testing as smooth as possible.

Core features of Nightwatch.js

  • A clean syntax that help write tests rapidly.
  • Allows using and selector for locating elements.
  • It integrates seamlessly with cloud-based testing platforms like BrowserStack.
  • Supports CI by mix the end to end angular examination with CI pipelines like Teamcity, Hudson, Jenkins.
  • It has Built-in Test Runner that indorse sequential or in sorted and tagged exam suites.
  • It has automatic control over,, and other WebDrivers in a freestanding child process for improved performance.

How to Install Nightwatch

For lead Nightwatch, you need a local standalone Selenium host, as good as WebDriver, to use Chrome/Firefox for end to end examine Angular applications locally.

The factor of Protractor end to end test architecture are as follows:

To configure Nightwatch use the next step:

Step 1: Add Nightwatch

Adding Nightwatch to the project by escape the below command

npm install nightwatch -- save-dev

This command places the Nightwatch executable in the./node_modules/.binfolder so that there is no need to instal it globally.

Step 2: Download Selenium

Selenium is an open-source project for a range of tools and libraries aimed at supporting. The prerequisite for Selenium is to have JDK 7 or high installed. The Selenium Server is a Java application that Nightwatch uses to connect with various browsers.

Download the Selenium JAR. After that, create a bin folder inside the project and place the JAR file in the bin folder.

Step 3: Download ChromeDriver

Download the ChromeDriverplace it in the like bin booklet created in the premature pace. It is a standalone waiter, implementing the W3C WebDriver wire protocol for Chromium.

Step 4: Configuring Nightwatch.js

The basic Nightwatch shape is done through a JSON configuration file. To make a nightwatch.json file, recruit the below code snip in a text file

{'' src_folders '': [`` tests ''], '' output_folder '': `` report '', '' selenium '': {'' start_process '': true, '' server_path '': `` ./bin/selenium-server-standalone-3.3.1.jar '', '' log_path '': `` '', '' porthole '': 4444, '' cli_args '': {'' webdriver.chrome.driver '': `` ./bin/chromedriver ''}}, '' test_settings '': {'' nonremittal '': {'' launch_url '': `` http: //localhost '', '' selenium_port '': 4444, '' selenium_host '': `` localhost '', '' desiredCapabilities '': {'' browserName '': `` chrome '', '' javascriptEnabled '': true, '' acceptSslCerts '': true}}}}

This constellation file provide Nightwatch information regarding the location of the binary files of Selenium Server and ChromeDriver, along with the location of the trial to be run.

Talk to an Expert

Create Angular E2E Test employ Nightwatch

Compared to other frameworks, testing on Nightwatch is a little different because here, the features are phone by chaining them, similar to how js async ring with CSS and XPath selectors.

In NightwatchJS, every file in thetestsfolder is a entourage in itself that must use the nodemodule.exports. However, it can have any bit of steps or substantiation in the form of functions, as shown below:

module.exports = {'Demo test Google ': function (client) {client .url ('http: //www.google.com ') .waitForElementVisible ('body ', 1000) .assert.title ('Google ') .assert.visible ('input [type=text] ') .setValue ('input [type=text] ', 'rembrandt van rijn ') .waitForElementVisible ('button [name=btnG] ', 1000) .click ('button [name=btnG] ') .pause (1000) .assert.containsText ('ol # rso li: first-child ', 'Rembrandt - Wikipedia ') .end ()}}

Running Angular End to End Test with NightwatchJS

To run Nightwatch, add a new script into the scripts section of package.json scripts subdivision and enter the below code snippet in it:

`` script '': {'' test-e2e '': `` nightwatch ''}

Run the angular e2e tests in Nightwatch using this command:

npm run test-e2e

If everything goes well, the examination will open up Chrome browser, then Google and Wikipedia.

Interactions with Nightwatch

Nightwatch offers an interesting feature: Interactions, which let you to click, press keys, set value, control if it display correct data, and the main elements are loading well. Below is a sample case that demonstrates how you can use Interactions for some of your uses instance.

module.exports = {'Input data testing # 2 ' (browser) {const searchInputSelector = ' # algolia-doc-search '; const searchText = `` state ''; const editSelector = '.css-1x091gh '; browser .url ('https: //reactjs.org ') .waitForElementVisible (searchInputSelector) .setValue (searchInputSelector, searchText) .waitForElementVisible ('.ds-dataset-1 ') .keys (browser.Keys.ENTER) .assert.containsText (editSelector, 'Edit ') .click (editSelector) .assert.urlContains ('https: //github.com/reactjs/reactjs.org/blob/master/content/docs/ ') .pause (1000)}}

Hooks with Nightwatch

Hooks are another feature of Nightwatch that can make the unscathed process sander. These can be used for basic activities like logging, post messages, and even some asynchronous tasks. Below is a sample of how you can use Hooks:

module.exports = {'Input data testing # 2 ' (browser) {const searchInputSelector = ' # algolia-doc-search '; const searchText = `` state ''; const editSelector = '.css-1x091gh '; browser .url ('https: //reactjs.org ') .waitForElementVisible (searchInputSelector) .setValue (searchInputSelector, searchText) .waitForElementVisible ('.ds-dataset-1 ') .keys (browser.Keys.ENTER) .assert.containsText (editSelector, 'Edit ') .click (editSelector) .assert.urlContains ('https: //github.com/reactjs/reactjs.org/blob/master/content/docs/ ') .pause (1000)}, after: function (browser, done) {browser.end (function () {console.log (`` Test complete, ending browser connector ''); done ();});},}

Read More:

End to End Testing in Angular using Cypress

Given below are the steps to deal end-to-end examination in Angular using Cypress:

Setting up Cypress

1. Install Cypress

npm install cypress -- save-dev

2. Unfastened Cypress UI

npx cypress open

This will scaffold the cypress/ directory in your undertaking.

Creating Your First E2E Test

  1. Go to cypress/e2e/
  2. Create a file like home-page.cy.ts
describe ('Home Page ', () = & gt; {it ('should load the home page ', () = & gt; {cy.visit ('http: //localhost:4200 '); cy.contains ('Welcome '); // replace with text on your homepage});});

Run the Test

Headless

npx cypress run

Interactive

npx cypress unfastened

Integrate with Angular CLI

Update angular.json to add a new npm script:

`` scripts '': {'' cypress: open '': `` cypress open '', '' cypress: run '': `` cypress run ''}

Protractor vs Nightwatch vs Cypress: Better Framework for E2E Angular Testing

Here is a detailed comparison of the three frameworks to aid you choose the rightfield one for E2E Angular testing:

Feature / ToolProtractorNightwatch.jsCypress
StatusDeprecatedActiveActive
Designed for AngularYesNoWorks well with Angular
SpeedModerateModerateFast
Ease of SetupComplexMediumSimple
Debugging ToolsBasicConsole logs onlyAdvanced (time-travel, auto-reload)
Test ExecutionWebDriver-basedWebDriver-basedRuns directly in browser
Cross-Browser SupportYesYesLimited (but improving)
CI/CD IntegrationSupportedSupportedSupported
Community SupportDecliningModerateStrong and grow
Best ForLegacy Angular applicationSelenium/WebDriver usersModern Angular and JS fabric

Read More:

Why Run Angular E2E Tests using Nightwatch on Real Device Cloud?

Here ’ s why you should run your Nightwatch, tests on:

  • Diverse Environment Testing: Execute exam across a wide scope of browsers and operate system without maintaining local infrastructure, insure consistent performance across platforms.
  • Concurrent Test Execution: Run multiple test befit simultaneously to reduce total testing time, enabling quicker feedback and faster deployment cycle.
  • CI/CD Integration: Seamlessly integrate with major CI/CD systems like Jenkins, Travis CI, CircleCI, and GitHub Actions to automate testing within your ontogenesis pipeline.
  • Symptomatic Tools for Better Debugging: Access detailed logs, screenshots, and video recordings of test session to cursorily identify and resolve issues.
  • Testing on Existent Devices: Test on real devices and browsers in the cloud for precise and real-world outcomes.
  • Customizable Test Execution: Tailor exam run through BrowserStack ’ s user interface or APIs to meet specific needs.

Conclusion

However, one must understand the development technique and testing criteria involved before selecting a framework. This makes it easier to choose the good framework that suits our requirements.

No matter which framework you choose, it is important to perform tests on existent devices and browsers over emulators and simulators for precise results. Using, you can admittance 3500+ browser-device combinations offering a across-the-board coverage, allow you to test end to end under.

Tags
30,000+ Views

# Ask-and-Contributeabout this subject with our Discord community.

Related Guides

Automate This With SUSA

Upload your APK or URL. SUSA explores like 10 real users — finds bugs, accessibility violations, and security issues. No scripts needed.

Try SUSA Free

Test Your App Autonomously

Upload your APK or URL. SUSA explores like 10 real users — finds bugs, accessibility violations, and security issues. No scripts.

Try SUSA Free