Skip to content

Instantly share code, notes, and snippets.

@dddent
Last active January 26, 2016 12:56
Show Gist options
  • Save dddent/73e086a6556da69626fc to your computer and use it in GitHub Desktop.
Save dddent/73e086a6556da69626fc to your computer and use it in GitHub Desktop.
exports.config = {
seleniumAddress: 'http://localhost:4444/wd/hub',
specs: ['beispieltest.js'],
onPrepare: function() {
browser.manage().window().setSize(1600, 1000);
}
}
// END2END TEST INSTRUCTIONS
// base frame:
describe('[epic]', function() {
it('[test description]', function() {
st.login(function() {
[the test]
});
});
});
// Finding an Element (can be used wherever [element] is required
st.byTestTag('[test-tag]'); // by test tag
st.byId('[id]'); // by id
// saving elements in variables
var element = [search query];
// example:
var patientenSuchfeld = st.byTestTag('patientenSuchfeld');
// >> after declaring a variable, it can be used wherever [element] is required
// Interacting with Elements
// clicking
[element].click().then(function() {
[what happens after the click]
});
// sending keystrokes
[element].sendKeys([keys]).then(function() {
[what happens after sending the keystrokes]
});
// Getting data about an element
// check if the element is present
[element].isPresent(); // beomes true or false
// get the text in a text field
st.getValue([element]).then(function(value) {
[value contains the value of the element]
});
// example:
st.getValue(st.byTestTag('patientenSuchfeld')).then(function(value) {
expect(value).toEqual('Franz Schubert');
});
// get the text in any other element:
st.getText([element]).then(function(text) {
[text contains the value of the element]
});
// specifying test expectations
expect([value to test against]).toBe([true / false]);
expect([value to test against]).toEqual([text]);
// example:
st.getText(st.byTestTag('patientenName')).then(function(text) {
expect(text).toEqual('Peter Lustig');
});
var exp = module.exports;
function byTestTag(tag) {
return element(by.css('[test-tag="' + tag + '"]'));
}
function byHref(href) {
return element(by.css('[href="' + href + '"]'));
}
function byId(id) {
return element(by.id(id));
}
function byType(type) {
return element(by.css('[type="' + type + '"]'));
}
function byAttribute(attributeName, value) {
if(value)
return element(by.css('[' + attributeName + '="' value + '"]'));
else
return element(by.css('[' + attributeName ']'));
}
function getValue(element) {
return element.getAttribute('value');
}
function getText(element) {
return element.getText();
}
function login(then) {
byTestTag('login-link').click().then(function() {
expect(byId('UserName').isPresent()).toBe(true);
byId('UserName').sendKeys('Protractor').then(function() {
byId('Password').sendKeys('Protractor123!').then(function() {
then();
});
});
});
}
function waitForElement(element, maxTime) {
if(!maxTime) maxTime = 5000;
return browser.wait(function() { return element.isPresent(); }, maxTime);
}
exp.byTestTag = byTestTag;
exp.byHref = byHref;
exp.byId = byId;
exp.byType = byType;
exp.byAttribute = byAttribute;
exp.getValue = getValue;
exp.getText = getText;
exp.login = login;
exp.waitForElement = waitForElement;
var st = require('../simple-test.js');
describe('epic', function() {
it('was es machen soll', function() {
browser.get('http://die/adresse/zum/testen');
expect(true).toBe(true);
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment