Protractor is an end-to-end test framework developed for Angular and AngularJS applications. It runs tests against the application interacting with it as a real user would, running in a real browser. In this article, we are going to test the name of the tag of an element.
Pre-requisite: Installation and Setup of Protractor
Approach:
- We are going to create a basic test program in which we are going to test the name of the tag of an element.
- All the Protractor tests will have a file that will contain the configuration and this will be the initial file that will initiate the test.
- Let’s create this file with the name conf.js.
conf.js:
Javascript
exports.config = {
capabilities: {
'browserName' : 'chrome'
},
framework: 'jasmine' ,
specs: [ 'test.js' ],
jasmineNodeOpts: {
defaultTimeoutInterval: 30000
},
baseUrl: 'file://' + __dirname + '/' ,
onPrepare: function () {
}
};
|
- Now let’s create our HTML file called test.html which will contain the element to be tested.
HTML
<!DOCTYPE html>
< html lang = "en" >
< head >
< meta charset = "UTF-8" >
< meta name = "viewport" content =
"width=device-width, initial-scale=1.0" >
< title >Testing</ title >
</ head >
< body >
< section id = "sample-element" >
Inner text
</ section >
</ body >
</ html >
|
- Finally, we are ready to run our file using the command given below:
protractor conf.js
- This will run the configuration file and the test will be run as shown in the screenshot below:
Output:
