Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions lib/helper/Playwright.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import {
clearString,
requireWithFallback,
normalizeSpacesInString,
normalizePath,
relativeDir,
} from '../utils.js'
import { isColorProperty, convertColorToRGBA } from '../colorUtils.js'
Expand Down Expand Up @@ -2412,7 +2413,7 @@ class Playwright extends Helper {
const currentUrl = await this._getPageUrl()
const baseUrl = this.options.url || 'http://localhost'
const actualPath = new URL(currentUrl, baseUrl).pathname
return equals('url path').assert(path, actualPath)
return equals('url path').assert(normalizePath(path), normalizePath(actualPath))
}

/**
Expand All @@ -2422,7 +2423,7 @@ class Playwright extends Helper {
const currentUrl = await this._getPageUrl()
const baseUrl = this.options.url || 'http://localhost'
const actualPath = new URL(currentUrl, baseUrl).pathname
return equals('url path').negate(path, actualPath)
return equals('url path').negate(normalizePath(path), normalizePath(actualPath))
}

/**
Expand Down
5 changes: 3 additions & 2 deletions lib/helper/Puppeteer.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import {
isModifierKey,
requireWithFallback,
normalizeSpacesInString,
normalizePath,
} from '../utils.js'
import { isColorProperty, convertColorToRGBA } from '../colorUtils.js'
import ElementNotFound from './errors/ElementNotFound.js'
Expand Down Expand Up @@ -1691,7 +1692,7 @@ class Puppeteer extends Helper {
const currentUrl = await this._getPageUrl()
const baseUrl = this.options.url || 'http://localhost'
const actualPath = new URL(currentUrl, baseUrl).pathname
return equals('url path').assert(path, actualPath)
return equals('url path').assert(normalizePath(path), normalizePath(actualPath))
}

/**
Expand All @@ -1701,7 +1702,7 @@ class Puppeteer extends Helper {
const currentUrl = await this._getPageUrl()
const baseUrl = this.options.url || 'http://localhost'
const actualPath = new URL(currentUrl, baseUrl).pathname
return equals('url path').negate(path, actualPath)
return equals('url path').negate(normalizePath(path), normalizePath(actualPath))
}

/**
Expand Down
16 changes: 13 additions & 3 deletions lib/helper/WebDriver.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,17 @@ import output from '../output.js'
const { debug } = output
import { empty } from '../assert/empty.js'
import { truth } from '../assert/truth.js'
import { xpathLocator, fileExists, decodeUrl, chunkArray, convertCssPropertiesToCamelCase, screenshotOutputFolder, getNormalizedKeyAttributeValue, modifierKeys } from '../utils.js'
import {
xpathLocator,
fileExists,
decodeUrl,
chunkArray,
convertCssPropertiesToCamelCase,
screenshotOutputFolder,
getNormalizedKeyAttributeValue,
modifierKeys,
normalizePath,
} from '../utils.js'
import { isColorProperty, convertColorToRGBA } from '../colorUtils.js'
import ElementNotFound from './errors/ElementNotFound.js'
import ConnectionRefused from './errors/ConnectionRefused.js'
Expand Down Expand Up @@ -1851,7 +1861,7 @@ class WebDriver extends Helper {
const currentUrl = await this.browser.getUrl()
const baseUrl = this.options.url || 'http://localhost'
const actualPath = new URL(currentUrl, baseUrl).pathname
return equals('url path').assert(path, actualPath)
return equals('url path').assert(normalizePath(path), normalizePath(actualPath))
}

/**
Expand All @@ -1861,7 +1871,7 @@ class WebDriver extends Helper {
const currentUrl = await this.browser.getUrl()
const baseUrl = this.options.url || 'http://localhost'
const actualPath = new URL(currentUrl, baseUrl).pathname
return equals('url path').negate(path, actualPath)
return equals('url path').negate(normalizePath(path), normalizePath(actualPath))
}

/**
Expand Down
7 changes: 7 additions & 0 deletions lib/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,13 @@ export const decodeUrl = function (url) {
return decodeURIComponent(decodeURIComponent(decodeURIComponent(url)))
}

export const normalizePath = function (path) {
if (path === '' || path === '/') return '/'
return path
.replace(/\/+/g, '/')
.replace(/\/$/, '') || '/'
}

export const xpathLocator = {
/**
* @param {string} string
Expand Down
36 changes: 36 additions & 0 deletions test/helper/webapi.js
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,42 @@ export function tests() {
await I.seeCurrentPathEquals('/info')
await I.dontSeeCurrentPathEquals('/info#section')
})

it('should normalize trailing slashes in path comparison', async () => {
await I.amOnPage('/info/')
await I.seeCurrentPathEquals('/info')
await I.seeCurrentPathEquals('/info/')

await I.amOnPage('/users/')
await I.seeCurrentPathEquals('/users')
await I.seeCurrentPathEquals('/users/')
})

it('should normalize multiple consecutive slashes in path', async () => {
await I.amOnPage('/users//1')
await I.seeCurrentPathEquals('/users/1')
await I.seeCurrentPathEquals('/users//1')

await I.amOnPage('/info///test')
await I.seeCurrentPathEquals('/info/test')
})

it('should handle root path correctly', async () => {
await I.amOnPage('/')
await I.seeCurrentPathEquals('/')
await I.seeCurrentPathEquals('')
await I.dontSeeCurrentPathEquals('/info')
})

it('should normalize both expected and actual paths', async () => {
await I.amOnPage('/users/')
await I.seeCurrentPathEquals('/users/')
await I.seeCurrentPathEquals('/users')

await I.amOnPage('/users//1/')
await I.seeCurrentPathEquals('/users/1')
await I.seeCurrentPathEquals('/users/1/')
})
})

describe('#waitInUrl, #waitUrlEquals', () => {
Expand Down
Loading