diff --git a/lib/container.js b/lib/container.js index 66c7c1610..badc08ad9 100644 --- a/lib/container.js +++ b/lib/container.js @@ -469,7 +469,7 @@ function loadGherkinSteps(paths) { loadSupportObject(path, `Step Definition from ${path}`) } } else { - const folderPath = paths.startsWith('.') ? path.join(global.codecept_dir, paths) : '' + const folderPath = paths.startsWith('.') ? normalizeAndJoin(global.codecept_dir, paths) : '' if (folderPath !== '') { globSync(folderPath).forEach(file => { loadSupportObject(file, `Step Definition from ${file}`) @@ -562,3 +562,16 @@ function getHelperModuleName(helperName, config) { // built-in helpers return `./helper/${helperName}` } +function normalizeAndJoin(basePath, subPath) { + // Normalize and convert slashes to forward slashes in one step + const normalizedBase = path.posix.normalize(basePath.replace(/\\/g, '/')) + const normalizedSub = path.posix.normalize(subPath.replace(/\\/g, '/')) + + // If subPath is absolute (starts with "/"), return it as the final path + if (normalizedSub.startsWith('/')) { + return normalizedSub + } + + // Join the paths using POSIX-style + return path.posix.join(normalizedBase, normalizedSub) +} \ No newline at end of file diff --git a/lib/helper/Appium.js b/lib/helper/Appium.js index 2519d68eb..eb26ca56f 100644 --- a/lib/helper/Appium.js +++ b/lib/helper/Appium.js @@ -383,8 +383,10 @@ class Appium extends Webdriver { _buildAppiumEndpoint() { const { protocol, port, hostname, path } = this.browser.options + // Ensure path does NOT end with a slash to prevent double slashes + const normalizedPath = path.replace(/\/$/, ''); // Build path to Appium REST API endpoint - return `${protocol}://${hostname}:${port}${path}/session/${this.browser.sessionId}` + return `${protocol}://${hostname}:${port}${normalizedPath}/session/${this.browser.sessionId}` } /**