Skip to content

Commit 6326cdd

Browse files
DavertMikDavertMikclaude
authored
Add seeCurrentPathEquals method to ignore query strings (#5435)
* 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> * Add dontSeeCurrentPathEquals method for negative path assertions Adds the negative counterpart to seeCurrentPathEquals for checking that URL paths do not match, ignoring query strings and fragments. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * Refactor WebDriver seeCurrentPathEquals to use equals().assert/negate pattern Aligns WebDriver.js implementation with Playwright.js and Puppeteer.js by using the consistent `equals('url path').assert()` and `.negate()` pattern instead of custom assert.equal and manual error throwing. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * Fix test router to handle query strings in URL paths Changed glue.php router to strip query strings from REQUEST_URI before matching route patterns. This fixes 500 errors when accessing URLs like /info?user=test because the regex pattern ^/info/?$ didn't match /info?user=test. Changed from: $path = $_SERVER['REQUEST_URI']; To: $path = parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH); Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> --------- Co-authored-by: DavertMik <davert@testomat.io> Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com>
1 parent 20203f6 commit 6326cdd

File tree

7 files changed

+120
-1
lines changed

7 files changed

+120
-1
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 does NOT match the expected path.
2+
Query strings and URL fragments are ignored.
3+
4+
```js
5+
I.dontSeeCurrentPathEquals('/form'); // fails for '/form', '/form?user=1', '/form#section'
6+
I.dontSeeCurrentPathEquals('/'); // fails for '/', '/?user=ok', '/#top'
7+
```
8+
9+
@param {string} path value to check.
10+
@returns {void} automatically synchronized promise through #recorder
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: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2405,6 +2405,26 @@ 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+
2418+
/**
2419+
* {{> dontSeeCurrentPathEquals }}
2420+
*/
2421+
async dontSeeCurrentPathEquals(path) {
2422+
const currentUrl = await this._getPageUrl()
2423+
const baseUrl = this.options.url || 'http://localhost'
2424+
const actualPath = new URL(currentUrl, baseUrl).pathname
2425+
return equals('url path').negate(path, actualPath)
2426+
}
2427+
24082428
/**
24092429
* {{> see }}
24102430
*

lib/helper/Puppeteer.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1684,6 +1684,26 @@ 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+
1697+
/**
1698+
* {{> dontSeeCurrentPathEquals }}
1699+
*/
1700+
async dontSeeCurrentPathEquals(path) {
1701+
const currentUrl = await this._getPageUrl()
1702+
const baseUrl = this.options.url || 'http://localhost'
1703+
const actualPath = new URL(currentUrl, baseUrl).pathname
1704+
return equals('url path').negate(path, actualPath)
1705+
}
1706+
16871707
/**
16881708
* {{> see }}
16891709
*

lib/helper/WebDriver.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1844,6 +1844,26 @@ 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 equals('url path').assert(path, actualPath)
1855+
}
1856+
1857+
/**
1858+
* {{> dontSeeCurrentPathEquals }}
1859+
*/
1860+
async dontSeeCurrentPathEquals(path) {
1861+
const currentUrl = await this.browser.getUrl()
1862+
const baseUrl = this.options.url || 'http://localhost'
1863+
const actualPath = new URL(currentUrl, baseUrl).pathname
1864+
return equals('url path').negate(path, actualPath)
1865+
}
1866+
18471867
/**
18481868
* Wraps [execute](http://webdriver.io/api/protocol/execute.html) command.
18491869
*

test/data/app/glue.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ class glue {
4444
static function stick ($urls) {
4545

4646
$method = strtoupper($_SERVER['REQUEST_METHOD']);
47-
$path = $_SERVER['REQUEST_URI'];
47+
$path = parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH);
4848

4949
$found = false;
5050

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)