04 First Test - biswajitsundara/Protractor GitHub Wiki
The best practice is to install all dependencies at project level. Now configure the below three commands in package.json file.
"scripts": {
"test": "./node_modules/.bin/protractor conf.js",
"update": "./node_modules/.bin/webdriver-manager update",
"start": "./node_modules/.bin/webdriver-manager start"
},
The first step is to update the webdriver manager. Execute the command npm run update
The below test will simply open the website and print the heading text.
const { browser, element } = require("protractor");
describe('Protractor Demo App', function () {
it('should have a title', function () {
browser.get('http://juliemr.github.io/protractor-demo/');
element(by.css('h3')).getText().then((text) => {
console.log('text--->' + text);
})
});
});
In the conf.js file, provide the spec file name to run.
exports.config = {
framework: 'jasmine',
seleniumAddress: 'http://localhost:4444/wd/hub',
specs: ['spec.js']
}
To start the webdriver execute the command npm run start
To execute the test execute the command npm run test