简体   繁体   English

如何使用mocha javascript在module.exports中提供xpath

[英]How to give xpath in module.exports using mocha javascript

I'm using mocha with nodejs and want to use the xpath defined in one test file (verification.js)and use it in another file (test.js).How should i give define the xpath as it contains single quotes inside single quotes ? 我正在使用带有nodejs的mocha,并希望使用在一个测试文件中定义的xpath(verification.js)并在另一个文件(test.js)中使用它。我应该如何定义xpath,因为它在单引号中包含单引号?

I have tried giving \\ before start and end of the code, but when i run the program am getting error "cannot read the property xyz" 我已经尝试在开始和结束代码之前给出\\但是当我运行程序时出现错误“无法读取属性xyz”

verifications.js file verifications.js文件

module.exports={
    loginLocation : 'xpath("//span[text()=\'LOGIN\']")',
}

test.js file test.js文件

const value=require('./verifications.js');
var By=webdriver.By;
before(function(){
    driver.findElement(By.value.loginLocation).click();

});

I want to pass xpath from one file to another 我想将xpath从一个文件传递到另一个文件

Check https://www.sitepoint.com/understanding-module-exports-exports-node-js/ 检查https://www.sitepoint.com/understanding-module-exports-exports-node-js/

fileA.js: fileA.js:

module.exports.loginLoc = 'xpath("//span[text()=\'LOGIN\']")';

fileB.js: fileB.js:

const fileA = require('fileA');
console.log('check out', fileA.loginLoc);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM