Javascript protractor commands. issue
- Protractor is a Node.js program,To run, you will need to have Node.js installed. You will download Protractor package using npm, which comes with Node.js.
- By default, Protractor uses the Jasmine test framework for its testing interface.
Setup
Use npm to install Protractor globally with:
npm install -g protractor
This will install two command line tools, protractor
and webdriver-manager
. Try running protractor --version
to make sure it's working.
The webdriver-manager
is a helper tool to easily get an instance of a Selenium Server running. Use it to download the necessary binaries with:
webdriver-manager update
Now start up a server with:
webdriver-manager start
This will start up a Selenium Server and will output a bunch of info logs. Your Protractor test will send requests to this server to control a local browser. Leave this server running throughout the tutorial. You can see information about the status of the server at http://localhost:4444/wd/hub
.
// spec.js
describe('Protractor Demo App', function() {
it('should have a title', function() {
browser.get('http://juliemr.github.io/protractor-demo/');
expect(browser.getTitle()).toEqual('Super Calculator');
});
});
The describe
and it
syntax is from the Jasmine framework. browser
is a global created by Protractor, which is used for browser-level commands such as navigation with browser.get
.
Now create the configuration file. Copy the following into conf.js:
// conf.js
exports.config = {
framework: 'jasmine',
seleniumAddress: 'http://localhost:4444/wd/hub',
specs: ['spec.js']
}
This configuration tells Protractor where your test files (specs
) are, and where to talk to your Selenium Server (seleniumAddress
). It specifies that we will be using Jasmine for the test framework. It will use the defaults for all other configuration. Chrome is the default browser.
Now run the test with
protractor conf.js
You should see a Chrome browser window open up and navigate to the Calculator, then close itself (this should be very fast!). The test output should be 1 tests, 1 assertion, 0 failures
. Congratulations, you've run your first Protractor test!
npm install -g protractor
npm install node
webdriver-manager start - selenium server start
webdriver-manager update - selenium server update
execute js file -
node filename.js
exec proc file
protractor configuration.js
issue :
npm install permission denied (macOS)
To check the location of the package:
npm config get prefix
Then run this :
sudo chown -R $(whoami) $(npm config get prefix)/{lib/node_modules,bin,share}
Comments
Post a Comment