我有以下代码。有没有更好的方法来使用一次滚动选项并将其用于所有其他功能。我不知道如何将其重新设计为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);
};
String('window.scroll(0,2000)')重复3次,这是你从Sonar得到的抱怨。
您应该在文件顶部定义一个变量:
var js_code = 'window.scroll(0,2000)';
然后使用它作为参数:browser.execute(js_code)