Skip to content

Commit d91c695

Browse files
author
DavertMik
committed
Merge branch '4.x' of github.com:codeceptjs/CodeceptJS into 4.x
2 parents 5afd819 + 9512bb4 commit d91c695

File tree

10 files changed

+216
-1
lines changed

10 files changed

+216
-1
lines changed

docs/helpers/Playwright.md

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -739,6 +739,22 @@ I.dontSeeCookie('auth'); // no auth cookie
739739

740740
Returns **void** automatically synchronized promise through #recorder
741741

742+
### dontSeeCurrentPathEquals
743+
744+
Checks that current URL path does NOT match the expected path.
745+
Query strings and URL fragments are ignored.
746+
747+
```js
748+
I.dontSeeCurrentPathEquals('/form'); // fails for '/form', '/form?user=1', '/form#section'
749+
I.dontSeeCurrentPathEquals('/'); // fails for '/', '/?user=ok', '/#top'
750+
```
751+
752+
#### Parameters
753+
754+
* `path` **[string][9]** value to check.
755+
756+
Returns **void** automatically synchronized promise through #recorder
757+
742758
### dontSeeCurrentUrlEquals
743759

744760
Checks that current url is not equal to provided one.
@@ -1994,6 +2010,22 @@ I.seeCssPropertiesOnElements('h3', { 'font-weight': "bold"});
19942010

19952011
Returns **void** automatically synchronized promise through #recorder
19962012

2013+
### seeCurrentPathEquals
2014+
2015+
Checks that current URL path matches the expected path.
2016+
Query strings and URL fragments are ignored.
2017+
2018+
```js
2019+
I.seeCurrentPathEquals('/info'); // passes for '/info', '/info?user=1', '/info#section'
2020+
I.seeCurrentPathEquals('/'); // passes for '/', '/?user=ok', '/#top'
2021+
```
2022+
2023+
#### Parameters
2024+
2025+
* `path` **[string][9]** value to check.
2026+
2027+
Returns **void** automatically synchronized promise through #recorder
2028+
19972029
### seeCurrentUrlEquals
19982030

19992031
Checks that current url is equal to provided one.

docs/helpers/Puppeteer.md

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -622,6 +622,22 @@ I.dontSeeCookie('auth'); // no auth cookie
622622

623623
Returns **void** automatically synchronized promise through #recorder
624624

625+
### dontSeeCurrentPathEquals
626+
627+
Checks that current URL path does NOT match the expected path.
628+
Query strings and URL fragments are ignored.
629+
630+
```js
631+
I.dontSeeCurrentPathEquals('/form'); // fails for '/form', '/form?user=1', '/form#section'
632+
I.dontSeeCurrentPathEquals('/'); // fails for '/', '/?user=ok', '/#top'
633+
```
634+
635+
#### Parameters
636+
637+
* `path` **[string][6]** value to check.
638+
639+
Returns **void** automatically synchronized promise through #recorder
640+
625641
### dontSeeCurrentUrlEquals
626642

627643
Checks that current url is not equal to provided one.
@@ -1762,6 +1778,22 @@ Returns **void** automatically synchronized promise through #recorder
17621778
This action supports [React locators](https://codecept.io/react#locators)
17631779
17641780
1781+
### seeCurrentPathEquals
1782+
1783+
Checks that current URL path matches the expected path.
1784+
Query strings and URL fragments are ignored.
1785+
1786+
```js
1787+
I.seeCurrentPathEquals('/info'); // passes for '/info', '/info?user=1', '/info#section'
1788+
I.seeCurrentPathEquals('/'); // passes for '/', '/?user=ok', '/#top'
1789+
```
1790+
1791+
#### Parameters
1792+
1793+
* `path` **[string][6]** value to check.
1794+
1795+
Returns **void** automatically synchronized promise through #recorder
1796+
17651797
### seeCurrentUrlEquals
17661798
17671799
Checks that current url is equal to provided one.

docs/helpers/WebDriver.md

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -794,6 +794,22 @@ I.dontSeeCookie('auth'); // no auth cookie
794794

795795
Returns **void** automatically synchronized promise through #recorder
796796

797+
### dontSeeCurrentPathEquals
798+
799+
Checks that current URL path does NOT match the expected path.
800+
Query strings and URL fragments are ignored.
801+
802+
```js
803+
I.dontSeeCurrentPathEquals('/form'); // fails for '/form', '/form?user=1', '/form#section'
804+
I.dontSeeCurrentPathEquals('/'); // fails for '/', '/?user=ok', '/#top'
805+
```
806+
807+
#### Parameters
808+
809+
* `path` **[string][18]** value to check.
810+
811+
Returns **void** automatically synchronized promise through #recorder
812+
797813
### dontSeeCurrentUrlEquals
798814

799815
Checks that current url is not equal to provided one.
@@ -1870,6 +1886,22 @@ I.seeCssPropertiesOnElements('h3', { 'font-weight': "bold"});
18701886
18711887
Returns **void** automatically synchronized promise through #recorder
18721888
1889+
### seeCurrentPathEquals
1890+
1891+
Checks that current URL path matches the expected path.
1892+
Query strings and URL fragments are ignored.
1893+
1894+
```js
1895+
I.seeCurrentPathEquals('/info'); // passes for '/info', '/info?user=1', '/info#section'
1896+
I.seeCurrentPathEquals('/'); // passes for '/', '/?user=ok', '/#top'
1897+
```
1898+
1899+
#### Parameters
1900+
1901+
* `path` **[string][18]** value to check.
1902+
1903+
Returns **void** automatically synchronized promise through #recorder
1904+
18731905
### seeCurrentUrlEquals
18741906
18751907
Checks that current url is equal to provided one.
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)