$ npm install -g protractor $ webdriver-manager update
$ webdriver-manager start
// spec.js
describe('Protractor Demo App', function() {
it('should have a title', function() {
browser.get('http://127.0.0.1:8080/index.html');
expect(browser.getTitle()).toEqual('Super Calculator');
});
});
// conf.js
exports.config = {
framework: 'jasmine2',
seleniumAddress: 'http://localhost:4444/wd/hub',
specs: ['spec.js']
}
$ protractor conf.js
$ protractor conf.js --elementExplorer
https://angular.github.io/protractor/#/locators Locator tell protractor how to find certain DOM Element
// find an element using a css selector
by.css('.myclass')
// find an element with the given id
by.id('myid')
// find an element with a certain ng-model
by.model('name')
// find an element bound to the given variable
by.binding('bindingname')
The locator are passed to the element function, as below.
element(by.css('some-css'));
When using CSS Selectors as a locator, you can use the shortcut $() notation:
$('my-css');
// Is the same as
element(by.css('my-css'));
The element()
function returns an ElementFinder object. The ElementFinder knows how to locate the DOM element using the locator you passed in as a parameter.
var el = element(locator);
// Click on the element
el.click();
// Send keys to the element (usually an input)
el.sendKeys('my text');
// Clear the text in an element (usually an input)
el.clear();
// Get the value of an attribute, for example, get the value of an input
el.getAttribute('value');
browser.ignoreSynchronization = true;