-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #132 from Marketionist/get-page-objects
Separate and expose getting page objects
- Loading branch information
Showing
2 changed files
with
56 additions
and
48 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
'use strict'; | ||
|
||
// ############################################################################# | ||
|
||
const path = require('path'); | ||
const { readDirectories } = require('js-automation-tools'); | ||
|
||
const spacesToIndent = 4; | ||
|
||
const isCalledExternally = __dirname.includes('node_modules'); | ||
|
||
const pageObjectsFolderPathes = 'PO_FOLDER_PATH' in process.env ? | ||
process.env.PO_FOLDER_PATH.replace(/\s+/g, '').split(',') : | ||
[path.join('tests', 'page-model')]; | ||
|
||
const fullPageObjectsFolderPathes = isCalledExternally ? | ||
pageObjectsFolderPathes.map((pageObjectsFolderPath) => { | ||
return path.join(__dirname, '..', '..', '..', pageObjectsFolderPath) | ||
}) : | ||
pageObjectsFolderPathes.map((pageObjectsFolderPath) => { | ||
return path.join(__dirname, '..', pageObjectsFolderPath) | ||
}); | ||
|
||
// Require all Page Object files in directory | ||
let pageObjects = {}; | ||
|
||
/** | ||
* Requires Page Object files | ||
* @returns {Array} allRequiredPageObjects | ||
*/ | ||
(async function requirePageObjects () { | ||
const allPageObjectFiles = await readDirectories( | ||
fullPageObjectsFolderPathes); | ||
const allRequiredPageObjects = allPageObjectFiles.filter( | ||
(value) => { | ||
return value.includes('.js'); | ||
} | ||
).map((file) => { | ||
const fileName = path.basename(file, '.js'); | ||
|
||
pageObjects[fileName] = require(file); | ||
|
||
return file; | ||
}); | ||
|
||
console.log( | ||
'\nPage Objects from PO_FOLDER_PATH:', | ||
`\n${JSON.stringify(pageObjects, null, spacesToIndent)}\n\n` | ||
); | ||
|
||
return pageObjects; | ||
})(); | ||
|
||
module.exports = pageObjects; |