对于测试,我有一个这样的目录结构:
习惯
自由
测试
.pages
在"custom"目录中编写的每个JavaScript函数都可以通过"浏览器"对象由"test"目录访问。
这是由 lib 目录中的 "testutils.js" 文件完成的。
同样
是否可以检索"pages"目录中的JavaScript函数,可以通过路径"browser.pages.function-name()"访问"test"目录?
看起来您正在尝试使用 WebdriverIO 实现 PageObject 模式。您可以在 WebdriverIO 示例中找到这方面的示例。
不过,我会说我已经尝试过这条路线,我更喜欢不同的方法。使用 WebdriverIO,您可以将自定义命令添加到 Web 驱动程序客户端。所以你可以在一个对象中列出你的命令:
module.exports = {
searchGoogle: function (searchString) {
return this
.url('http://www.google.com')
.click('input[name="q"]')
.keys(searchString)
.pause(2000)
.keys(['Enter']); //press Enter Key
}
};
然后,您可以将这些命令绑定到客户端:
var client = webdriverio.remote(options);
client.addCommand('searchGoogle',searchGoogle.bind(client));