首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >您能定义“page_objects_path”目录吗?该目录将从所有子文件夹中读取,而无需显式指定它们?

您能定义“page_objects_path”目录吗?该目录将从所有子文件夹中读取,而无需显式指定它们?
EN

Stack Overflow用户
提问于 2020-04-14 11:51:46
回答 1查看 249关注 0票数 1

我目前正在从事的项目使用Selenium WebDriver Nightwatch和Cucumber。

问题是项目的文件夹结构发生了变化,现在'page_objects_path''nightwatch.conf.js'文件中的样子如下所示:

代码语言:javascript
复制
'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对象/目录读取所有子文件夹,而不必在数组中显式指定为单独的路径?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2020-04-14 12:17:56

我相信

代码语言:javascript
复制
'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以编程方式创建该数组。例如:

代码语言:javascript
复制
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,
....
}
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/61207023

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档