There are many ways to test our application but having a testing with end user feel is the always the important one. The protractor is JS framework built up Selenium JS web driver. It provides ease of End to End (E2E) browser testing with protractor angular and non angular applications. It provides a JS wrapper around Selenium commands. The framework contains many intuitive functions which really speed up writing test cases.
** Protractor doesn’t require your site to be on the Angular framework, You can use it all kind of sites.
In this blog, we are going to cover following points.
What is Protractor and why you need it? Setting up and running Protractor project. Running protractor headless in non-UI Linux kind of environment. Perks- Taking the screenshot.
What is Protractor and why you need it?
The protractor is an end to end browser test automation tool. It emulates user like actions on browsers and is supported by many browsers (chrome, IE, firefox etc). It is a wrapper around selenium web driver commands and much more. Provides automatic wait capabilities for the resource to load and render. Here some points which make Protractor a great framework.
- It is an open source project and has big community support.
- It is well documented.
- Easy to setup and configure.
- Work with almost all the browser.
- Anytime you can take screenshots of the browser.
Setting up and running Protractor project.
Let’s jump into technicals. We are going to install and run one sample Protractor test case.
Download and install Node JS and npm from the following URL.
Install Protractor using npm, Open shall/command prompt.
npm install -g protractor
With above command, you must have web driver-manger command available to your console, Update web driver-managerwebdriver-manager
Start web driver-manager in the separate console.
webdriver-manager start This required when you run you test case. Create a file conf.js for Protractor configurations.
Create First-test.js in the same location.
This is your actual test steps. For now, you can copy paste below code. This script will open google.com and search for ‘abyte.stream’
Run the protractor using the following command and see the protractor driving browser magic.
Running protractor headless in non UI Linux kind of environment.
Till this point, we have successfully achieved running test on the real browser. There are places when we do not have GUI, we just have a black screen server, In this situation, we need to go headless.
Headless browser doesn’t require a graphics driver at all, They just get commands and execute them directly in memory. To achieve this you need to specify headless in cong.js under capabilities.