Skip to content

Commit e6a9649

Browse files
DavertMikclaude
andcommitted
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>
1 parent f0b4eca commit e6a9649

File tree

4 files changed

+42
-0
lines changed

4 files changed

+42
-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 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

lib/helper/Playwright.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2415,6 +2415,16 @@ class Playwright extends Helper {
24152415
return equals('url path').assert(path, actualPath)
24162416
}
24172417

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+
24182428
/**
24192429
* {{> see }}
24202430
*

lib/helper/Puppeteer.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1694,6 +1694,16 @@ class Puppeteer extends Helper {
16941694
return equals('url path').assert(path, actualPath)
16951695
}
16961696

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+
16971707
/**
16981708
* {{> see }}
16991709
*

lib/helper/WebDriver.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1854,6 +1854,18 @@ class WebDriver extends Helper {
18541854
return assert.equal(path, actualPath, `expected url path to be ${path}, but found ${actualPath}`)
18551855
}
18561856

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+
const errorMessage = `expected url path not to be ${path}, but found ${actualPath}`
1865+
const isEqual = path === actualPath
1866+
if (isEqual) throw new Error(errorMessage)
1867+
}
1868+
18571869
/**
18581870
* Wraps [execute](http://webdriver.io/api/protocol/execute.html) command.
18591871
*

0 commit comments

Comments
 (0)