How to globally add a custom locator to Protractor? -


i wrote custom locator protractor finds anchor elements ui-sref value. in specs used by.addlocator add custom locator, figured might cool thing publish , have other people use it.

the goal add custom locator global protractor object can used in of specs.

my initial approach add functionality in onprepare block of protractor config. pseudocode below:

onprepare: function () {   require('ui-sref-locator')(protractor); // protractor object available here. } 

that require statement execute function:

function (ptorinstance) {   ptorinstance.by.addlocator('uisref', function (tostate, opt_parentelement) {     var using = opt_parentelement || document;     var possibleanchors = using.queryselectorall('a[ui-sref="' + tostate +'"]');     var result = undefined;      if (possibleanchors.length === 0) {       result = null;     } else if (possibleanchors.length === 1) {       result = possibleanchors[0];     } else {       result = possibleanchors;     }      return result;   }); }; 

the problem by not defined on protractor object available in onprepare block. means cannot use .addlocator method.

try following:

function () {   by.addlocator('uisref', function (tostate, opt_parentelement) {   ... 

by should in global scope.


Comments

Popular posts from this blog

javascript - RequestAnimationFrame not working when exiting fullscreen switching space on Safari -

Python ctypes access violation with const pointer arguments -