AddLocator transcavator: how to get an object for a document
I am trying to create a custom locator in the transport using addLocator
My conf.js
// An example configuration file.
exports.config = {
directConnect: true,
// Capabilities to be passed to the webdriver instance.
capabilities: {
'browserName': 'chrome'
},
//multiCapabilities: [{
// browserName: 'firefox'
// }, {
// browserName: 'chrome'
//}],
// Spec patterns are relative to the current working directly when
// protractor is called.
specs: ['DriverSpec.js'],
onPrepare: function () {
require('tech')(protractor);
}
//function (protractor) {
protractor.by.addLocator('test', function (toState, opt_parentElement) {
var using = opt_parentElement || document;
var possibleAnchors = using.querySelectorAll( toState );
var result = undefined;
if (possibleAnchors.length === 0) {
result = null;
} else if (possibleAnchors.length === 1) {
result = possibleAnchors[0];
} else {
result = possibleAnchors;
}
return result;
});
//};// The protractor object is available here.
// Options to be passed to Jasmine-node.
jasmineNodeOpts: {
showColors: true,
defaultTimeoutInterval: 1000000
}
};
Error shown:
C:\Users\jeevan.s\AppData\Roaming\npm\node_modules\protractor\conf\addLocator\Ne
w folder\conf.js:18
By.addLocator('customLink',
^
SyntaxError: Unexpected token .
at Module._compile (module.js:439:25)
at Object.Module._extensions..js (module.js:474:10)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:312:12)
at Module.require (module.js:364:17)
at require (module.js:380:17)
at ConfigParser.addFileConfig (C:\Users\jeevan.s\AppData\Roaming\npm\node_mo
dules\protractor\lib\configParser.js:183:20)
at Object.init (C:\Users\jeevan.s\AppData\Roaming\npm\node_modules\protracto
r\lib\launcher.js:35:18)
at Object.<anonymous> (C:\Users\jeevan.s\AppData\Roaming\npm\node_modules\pr
otractor\lib\cli.js:129:23)
at Module._compile (module.js:456:26)
Problems:
1) How to create a Protractor object 2) Trying to create an opt_parentElement object using these code strings
var using = browser.driver.findElement(By.css(".nav"));
buttons = using.querySelectorAll('active')
Throwing an error because "querySelectorAll" was not found in "using OBJECT" Could not access the querySelectorAll method. 3). Can anyone help us with addLocator with an executable example. It would be great!
+3
source to share
No one has answered this question yet
Check out similar questions: