Skip to content

Instantly share code, notes, and snippets.

@danielabar
Created May 21, 2016 16:44
Show Gist options
  • Save danielabar/8b25a328f5aa974827e648f5ab8c4979 to your computer and use it in GitHub Desktop.
Save danielabar/8b25a328f5aa974827e648f5ab8c4979 to your computer and use it in GitHub Desktop.
Extensions to Aurelia Protractor Plugin, adding additional Locators
/* Aurelia Protractor Plugin */
/* eslint-disable no-var, no-console */
function addValueBindLocator() {
by.addLocator('valueBind', function(bindingModel, optParentElement) {
var using = optParentElement || document;
var matches = using.querySelectorAll('*[value\\.bind="' + bindingModel + '"]');
var result;
if (matches.length === 0) {
result = null;
} else if (matches.length === 1) {
result = matches[0];
} else {
result = matches;
}
return result;
});
}
function addSrcBindLocator() {
by.addLocator('srcBind', function(bindingModel, optParentElement) {
var using = optParentElement || document;
var matches = using.querySelectorAll('*[src\\.bind="' + bindingModel + '"]');
var result;
if (matches.length === 0) {
result = null;
} else if (matches.length === 1) {
result = matches[0];
} else {
result = matches;
}
return result;
});
}
function addShowBindLocator() {
by.addLocator('showBind', function(bindingModel, optParentElement) {
var using = optParentElement || document;
var matches = using.querySelectorAll('*[show\\.bind="' + bindingModel + '"]');
var result;
if (matches.length === 0) {
result = null;
} else if (matches.length === 1) {
result = matches[0];
} else {
result = matches;
}
return result;
});
}
function addOptionBindLocator() {
by.addLocator('optionBind', function(bindingModel, optParentElement) {
var using = optParentElement || document;
var matches = using.querySelectorAll('option[value\\.bind="' + bindingModel + '"]');
var result;
if (matches.length === 0) {
result = null;
} else if (matches.length === 1) {
result = matches[0];
} else {
result = matches;
}
return result;
});
}
function addClickTriggerLocator() {
by.addLocator('clickTrigger', function(bindingModel, optParentElement) {
var using = optParentElement || document;
var matches = using.querySelectorAll('*[click\\.trigger="' + bindingModel + '"]');
var result;
if (matches.length === 0) {
result = null;
} else if (matches.length === 1) {
result = matches[0];
} else {
result = matches;
}
return result;
});
}
function addHrefLocator() {
by.addLocator('href', function(bindingModel, optParentElement) {
var using = optParentElement || document;
var matches = using.querySelectorAll('*[href="' + bindingModel + '"]');
var result;
if (matches.length === 0) {
result = null;
} else if (matches.length === 1) {
result = matches[0];
} else {
result = matches;
}
return result;
});
}
function loadAndWaitForAureliaPage(pageUrl) {
browser.get(pageUrl);
return browser.executeAsyncScript(
'var cb = arguments[arguments.length - 1];' +
'document.addEventListener("aurelia-composed", function (e) {' +
' cb("Aurelia App composed")' +
'}, false);'
).then(function(result) {
return result;
});
}
function waitForRouterComplete() {
return browser.executeAsyncScript(
'var cb = arguments[arguments.length - 1];' +
'document.querySelector("[aurelia-app]")' +
'.aurelia.subscribeOnce("router:navigation:complete", function() {' +
' cb(true)' +
'});'
).then(function(result) {
return result;
});
}
/* Plugin hooks */
exports.setup = function(config) {
// Ignore the default Angular synchronization helpers
browser.ignoreSynchronization = true;
// custom locators
addValueBindLocator();
addSrcBindLocator();
addShowBindLocator();
addOptionBindLocator();
addHrefLocator();
addClickTriggerLocator();
// attach a new way to browser.get a page and wait for Aurelia to complete loading
browser.loadAndWaitForAureliaPage = loadAndWaitForAureliaPage;
// wait for router navigations to complete
browser.waitForRouterComplete = waitForRouterComplete;
};
exports.teardown = function(config) {};
exports.postResults = function(config) {};
@ianrosario
Copy link

this is my protractor.conf.js

// An example configuration file.
exports.config = {
directConnect: false, //browserName (phantomjs) is not supported with directConnect.
getPageTimeout: 60000,
allScriptsTimeout: 500000,

// Capabilities to be passed to the webdriver instance.
capabilities: {
'browserName': 'phantomjs'//,
// //'phantomjs.binary.path': './node_modules/phantomjs/bin/phantomjs',
// //'phantomjs.ghostdriver.cli.args': ['--loglevel=DEBUG']
},

//baseURL: 'http://localhost/NewPortalWeb/#/portal/1d4be414-c941-4f4a-b88c-532d85bcc1e1/login',
//baseUrl: 'localhost/NewPortalWeb',
//framework: 'jasmine2',

onPrepare: function () {
},

specs: ['test/e2e/src/*.js'],

plugins: [{
path: 'aurelia.protractor.js'
}],

// Options to be passed to Jasmine-node.

jasmineNodeOpts: {
isVerbose: true,
showColors: true,
includeStackTrace: true,
defaultTimeoutInterval: 30000
}
};

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment