What is protractor?
The protractor is an end to end testing framework for Angular JS based applications. It is not just for testing Angular JS application but also used for writing automated test cases for other web applications.
The protractor is a NodeJS program which along with Node identifies web element in a web application, and it also uses web driver to control browser with user actions.
Why use Protractor?
- Simple syntax to write
- No need for sleep or waits
- Has multiple browser support
- Can be run in multiple platforms
- Ability to run in multiple browsers
Setup necessary to run Protractor
As protractor is a node.js program, install node.js
Install Selenium server and chrome driver if you want your test case to run in Chrome browser.
Since Vyper is built on top of the protractor, I only had to install Node and rest were already present.
Files that are necessary to run the test case
- The configuration file or conf file.
The conf file provides information about the location of the test case, which framework to use(Ex, Jasmine), which browser (Ex, Chrome). If the configuration is not defined, the default settings will be used.
- Spec file.
This file has the code to identify the web element to interact with the application.
Commonly used functions in Protractor
- Describe
Syntax: describe(‘text’, function()
Describe is a global function present in Jasmine which as two parameters, a string and a function. The string is used for describing the name for the test case and the function contains all the code that will implement the logic to execute the test case.
- It
Syntax : it(‘text’, function()
It is a function present in Jasmine which as two parameters, a string and a function. The string is used for describing the name for the test step and the function contains the logic to execute the test step.
- Expect
Syntax: expect(comparing value).not.toBe(comparedto)
expect(comparing value).toBe(comparedto)
This function is called expectation. For each condition, there has to be an appropriate value to compare to complete an assertion. This is usually returned inside the function it().
- beforeEach and afterEach
These functions are executed before or after every execution of function it(), and is executed even if the test step pass or not.
References:
https://www.protractortest.org/#/toc
https://medium.com/@bhageerathreddy/understanding-the-basics-of-jasmine-framework-effa5c75719b