Skip to content

Instantly share code, notes, and snippets.

@liveweird
Created March 20, 2014 06:39
Show Gist options
  • Save liveweird/9658464 to your computer and use it in GitHub Desktop.
Save liveweird/9658464 to your computer and use it in GitHub Desktop.
E2E tests in Protractor
// conditional test logic
function clearFilter() {
var filter = element(by.id('serviceCodeClearFilter'));
filter.getAttribute('disabled').then (function (val) {
if (!val) {
filter.click();
}
});
};
// keyboard short-cuts in automated test
describe("Shortcuts", function () {
it("opens the level 2 menu after typing the shortcut for level 1 menu item", function() {
var item = get1stLMenuItem(0);
expect(item.elem.getAttribute('class')).not.toContain('open');
browser.actions().keyDown(protractor.Key.CONTROL)
.sendKeys('a')
.keyUp(protractor.Key.CONTROL)
.perform();
expect(item.elem.getAttribute('class')).toContain('open');
browser.actions().keyDown(protractor.Key.CONTROL)
.sendKeys('a')
.keyUp(protractor.Key.CONTROL)
.perform();
expect(item.elem.getAttribute('class')).not.toContain('open');
});
});
// querying DOM using angular abstracts
describe("Display", function() {
it("has an item named 'AB' that doesn't have a default item", function() {
var category = element(by.repeater('category in categories').row(0));
var subcategory = category.element(by.repeater('subcategory in category.subcategories').row(1));
expect(subcategory.element(by.binding('subcategory.label')).getInnerHtml()).toEqual('AB_');
expect(subcategory.$('a').getAttribute('href')).toMatch('#/A/AB$');
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment