Skip to content

Commit f0b4eca

Browse files
DavertMikclaude
andcommitted
Add seeCurrentPathEquals method to ignore query strings
Adds new assertion method to check URL path equality while ignoring query parameters and URL fragments. - I.seeCurrentPathEquals('/info') passes for '/info?user=1', '/info#section' - I.seeCurrentPathEquals('/') passes for '/', '/?user=ok', '/#top' Implemented in Playwright, Puppeteer, and WebDriver helpers using native URL class for pathname extraction. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
1 parent bb6410e commit f0b4eca

File tree

5 files changed

+79
-0
lines changed

5 files changed

+79
-0
lines changed
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
Checks that current URL path matches the expected path.
2+
Query strings and URL fragments are ignored.
3+
4+
```js
5+
I.seeCurrentPathEquals('/info'); // passes for '/info', '/info?user=1', '/info#section'
6+
I.seeCurrentPathEquals('/'); // passes for '/', '/?user=ok', '/#top'
7+
```
8+
9+
@param {string} path value to check.
10+
@returns {void} automatically synchronized promise through #recorder

lib/helper/Playwright.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2405,6 +2405,16 @@ class Playwright extends Helper {
24052405
urlEquals(this.options.url).negate(url, await this._getPageUrl())
24062406
}
24072407

2408+
/**
2409+
* {{> seeCurrentPathEquals }}
2410+
*/
2411+
async seeCurrentPathEquals(path) {
2412+
const currentUrl = await this._getPageUrl()
2413+
const baseUrl = this.options.url || 'http://localhost'
2414+
const actualPath = new URL(currentUrl, baseUrl).pathname
2415+
return equals('url path').assert(path, actualPath)
2416+
}
2417+
24082418
/**
24092419
* {{> see }}
24102420
*

lib/helper/Puppeteer.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1684,6 +1684,16 @@ class Puppeteer extends Helper {
16841684
urlEquals(this.options.url).negate(url, await this._getPageUrl())
16851685
}
16861686

1687+
/**
1688+
* {{> seeCurrentPathEquals }}
1689+
*/
1690+
async seeCurrentPathEquals(path) {
1691+
const currentUrl = await this._getPageUrl()
1692+
const baseUrl = this.options.url || 'http://localhost'
1693+
const actualPath = new URL(currentUrl, baseUrl).pathname
1694+
return equals('url path').assert(path, actualPath)
1695+
}
1696+
16871697
/**
16881698
* {{> see }}
16891699
*

lib/helper/WebDriver.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1844,6 +1844,16 @@ class WebDriver extends Helper {
18441844
return urlEquals(this.options.url).negate(url, decodeUrl(res))
18451845
}
18461846

1847+
/**
1848+
* {{> seeCurrentPathEquals }}
1849+
*/
1850+
async seeCurrentPathEquals(path) {
1851+
const currentUrl = await this.browser.getUrl()
1852+
const baseUrl = this.options.url || 'http://localhost'
1853+
const actualPath = new URL(currentUrl, baseUrl).pathname
1854+
return assert.equal(path, actualPath, `expected url path to be ${path}, but found ${actualPath}`)
1855+
}
1856+
18471857
/**
18481858
* Wraps [execute](http://webdriver.io/api/protocol/execute.html) command.
18491859
*

test/helper/webapi.js

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,45 @@ export function tests() {
7575
const url = await I.grabCurrentUrl()
7676
assert.equal(url, `${siteUrl}/info`)
7777
})
78+
79+
it('should check for equality with query strings', async () => {
80+
await I.amOnPage('/info?user=test')
81+
// Query strings matter for exact equality
82+
await I.seeCurrentUrlEquals('/info?user=test')
83+
await I.dontSeeCurrentUrlEquals('/info')
84+
// But substring check works
85+
await I.seeInCurrentUrl('/info')
86+
await I.seeInCurrentUrl('user=test')
87+
})
88+
89+
it('should handle root path with query strings', async () => {
90+
await I.amOnPage('/?user=ok')
91+
// Query strings matter - exact equality requires query string
92+
await I.seeCurrentUrlEquals('/?user=ok')
93+
await I.dontSeeCurrentUrlEquals('/')
94+
// But substring check works for path fragment
95+
await I.seeInCurrentUrl('/')
96+
})
97+
98+
it('should check path equality ignoring query strings', async () => {
99+
await I.amOnPage('/info?user=test')
100+
// Path equality ignores query strings
101+
await I.seeCurrentPathEquals('/info')
102+
await I.dontSeeCurrentPathEquals('/form')
103+
await I.dontSeeCurrentPathEquals('/info?user=test')
104+
})
105+
106+
it('should check root path equality ignoring query strings', async () => {
107+
await I.amOnPage('/?user=ok')
108+
await I.seeCurrentPathEquals('/')
109+
await I.dontSeeCurrentPathEquals('/info')
110+
})
111+
112+
it('should check path equality ignoring hash fragments', async () => {
113+
await I.amOnPage('/info#section')
114+
await I.seeCurrentPathEquals('/info')
115+
await I.dontSeeCurrentPathEquals('/info#section')
116+
})
78117
})
79118

80119
describe('#waitInUrl, #waitUrlEquals', () => {

0 commit comments

Comments
 (0)