Skip to content

Instantly share code, notes, and snippets.

@bentolor
Created September 10, 2014 16:33
Show Gist options
  • Save bentolor/308fc6ed4fcd9bd64f7a to your computer and use it in GitHub Desktop.
Save bentolor/308fc6ed4fcd9bd64f7a to your computer and use it in GitHub Desktop.
Protractor Example for heise developer
// Calculator test logic - calculator.e2e.js
var CalcPage = require('./calculator.po.js');
describe('Web Calculator', function() {
var calc;
beforeEach(function() {
browser.get('https://juliemr.github.io/protractor-demo/');
calc = new CalcPage();
});
it('should allow to calculate', function() {
calc.firstValue.sendKeys("6");
calc.multiplyOption.click();
calc.secondValue.sendKeys("7");
calc.goButton.click();
expect(calc.resultLabel.getText()).toEqual('42');
});
});
// calculator.po.js - Calculator "Page Objects"
var CalculatorPage = function() {
this.firstValue = element(by.model('first'));
this.secondValue = element(by.model('second'));
this.multiplyOption = element(by.cssContainingText('option', '*'));
this.resultLabel = element(by.binding('{{latest}}'));
this.goButton = element(by.partialButtonText('Go'));
};
module.exports = CalculatorPage;
// protractor-conf.js
exports.config = {
seleniumAddress: 'http://localhost:4444/wd/hub',
specs: ['*.e2e.js'],
multiCapabilities: [
{ browserName: 'firefox' },
{ browserName: 'chrome' }
]
}
// webcalculator.e2e.js
describe('Web Calculator', function() {
beforeEach(function() {
browser.get('https://juliemr.github.io/protractor-demo/');
});
it('should have a page title & Go! button', function() {
expect(browser.getTitle()).toEqual('Super Calculator');
expect(element(by.buttonText('Go!')).isDisplayed()).toBe(true);
})
it('should allow to calculate via keyboard', function() {
var tab = protractor.Key.TAB;
element(by.model('first')).sendKeys("6", tab, tab, "7");
element(by.cssContainingText('option', '*')).click();
element(by.partialButtonText('Go')).click();
expect(element(by.binding('{{latest}}')).getText()).toEqual('42');
});
it('should have two input fields', function() {
var inputs = element.all(by.css("input"));
expect(inputs.count()).toEqual(2)
inputs.first().sendKeys("1");
inputs.get(1).sendKeys("2");
});
it('should maintain a calculation log', function() {
var tab = protractor.Key.TAB;
element(by.model('first')).sendKeys("7", tab, tab, "2");
element(by.buttonText('Go!')).click()
element(by.model('first')).sendKeys("1", tab, tab, "3");
element(by.css('[ng-click="doAddition()"]')).click();
// Auslesen von ng-repeat listen
var selector = by.repeater('result in memory').column('result.value');
expect(element.all(selector).get(0).getText()).toBe('4');
expect(element(selector.row(1)).getText()).toBe('9');
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment