我有以下代码。有没有更好的方法可以一次使用滚动选项并将其用于所有其他功能。我不确定如何将其重新设计为const。
module.exports.xyz = function (browser, done) {
browser
.execute('window.scroll(0,2000)')
.clickWaitForElementByCssWithCatch(css, isDisplayed, 30000, 1000)
.nodeify(done);
};
module.exports.abc = function (browser, done) {
browser
.execute('window.scroll(0,2000)')
.clickWaitForElementByCssWithCatch(css, isDisplayed, 30000, 1000)
.nodeify(done);
};
module.exports.efg = function (browser, done) {
browser
.execute('window.scroll(0,2000)')
.clickWaitForElementByCssWithCatch(css, isDisplayed, 30000, 1000)
.nodeify(done);
};
答案 0 :(得分:-1)
字符串('window.scroll(0,2000)')重复了3次,这就是您从Sonar得到的投诉。
您应该在文件顶部定义一个变量:
var js_code = 'window.scroll(0,2000)';
然后将其用作参数:browser.execute(js_code)