我目前正在从事的项目使用Selenium WebDriver Nightwatch和Cucumber。
问题是项目的文件夹结构发生了变化,现在'page_objects_path'在'nightwatch.conf.js'文件中的样子如下所示:
'page_objects_path':
[
"./componentTests/page-objects",
"./componentTests/page-objects/xxxxxx",
"./componentTests/page-objects/xxxxx xxxx",
"./endToEndTests/page-objects",
"./endToEndTests/page-objects/xxxx",
"./endToEndTests/page-objects/xxxxxxx",
"./endToEndTests/page-objects/xxxx xxxxx",
"./endToEndTests/page-objects/xxxxxx"
"./endToEndTests/page-objects/xxxxxxxxxx"
],Nightwatch是否可以从/page对象/目录读取所有子文件夹,而不必在数组中显式指定为单独的路径?
发布于 2020-04-14 12:17:56
我相信
'page_objects_path':
[
"./componentTests/page-objects",
"./endToEndTests/page-objects",
],应该就够了。page类应该有由结构的子文件夹调用的子类。例如,来自"./endToEndTests/page-objects/mainPage/SubPage.js“的方法getTheCoolElement()应该被调用为:browser.page.mainPage.SubPage().getTheCoolElement()
参见owncloud凤凰项目中的工作示例,该项目具有页面对象的层次结构:https://github.com/owncloud/phoenix/tree/master/tests/acceptance/pageObjects
或者,您可以使用JS以编程方式创建该数组。例如:
const fs = require('fs')
// const path = require('path')
const getAllFolders = function (dirPath, arrayOfFiles) {
const files = fs.readdirSync(dirPath)
arrayOfFiles = arrayOfFiles || []
files.forEach(function (file) {
if (fs.statSync(dirPath + '/' + file).isDirectory()) {
arrayOfFiles = getAllFolders(dirPath + '/' + file, arrayOfFiles)
arrayOfFiles.push(path.join(dirPath, '/', file))
}
})
return arrayOfFiles
}
let allPageObjectPath = getAllFolders(
path.join(__dirname, '/componentTests/page-objects')
)
allPageObjectPath = allPageObjectPath.concat(
getAllFolders(path.join(__dirname, '/endToEndTests/page-objects'))
)
module.exports = {
page_objects_path: allPageObjectPath,
....
}https://stackoverflow.com/questions/61207023
复制相似问题