@@ -3,7 +3,7 @@ title: Promise Chains
33layout : sidebar
44---
55
6- # [ ` Testium -driver-wd` ] ( https://www.npmjs.com/package/Testium -driver-wd )
6+ # [ ` testium -driver-wd` ] ( https://www.npmjs.com/package/testium -driver-wd )
77
88## General Notes
99
@@ -44,7 +44,7 @@ before(function requiresAlerts() {
4444Returns ` browser.capabilities ` .
4545
4646``` js
47- const capabilities = await browser .sessionCapabilities ()
47+ const capabilities = await browser .sessionCapabilities ();
4848```
4949
5050### browser.getConsoleLogs([ logLevel: string] ): Promise\< ConsoleLogObj[ ] \>
@@ -54,15 +54,14 @@ Returns all log events for `logLevel` `all`(default) `log`,`warn`, `error`, `deb
5454``` js
5555const errorLogs = await browser .getConsoleLogs (' error' );
5656```
57- ** Warnings :**
57+ ** ⚠️ Warning :**
5858- Each browser implements this differently against the WebDriver spec.
5959- Logs are not persistent, and can't be retrieved multiple times.
6060
6161``` js
62+ const errorLogs = await browser .getConsoleLogs (' error' ); // retrieve existing errors
6263
63- const errorLogs = await browser .getConsoleLogs (' error' ); // some errors exists
64- // get error logs once more. It will not contain the previous errors logs
65- const emptyErrors = await browser .getConsoleLogs (' error' );
64+ const emptyErrors = await browser .getConsoleLogs (' error' ); // Will not contain the previous errors logs
6665```
6766
6867### browser.getScreenshot(): Promise\< string\>
@@ -109,6 +108,8 @@ e.g. `http://localhost:1234/some/route`.
109108const url = await browser .getUrl ();
110109
111110assert .ok (/ ^ https:/ .test (url));
111+
112+ assert .match (url, / ^ https:/ ); // Node v12.16.0+
112113```
113114
114115### browser.getUrlObject(): Promise\< URLObject\>
@@ -119,8 +120,8 @@ Returns a [WHATWG URL instance](https://nodejs.org/dist/latest-v13.x/docs/api/ur
119120``` js
120121const urlObj = browser
121122 .loadPage (' /#abc' )
122- .clickOn (' #something' ) // do something that changes the url
123- .getUrlObject ()
123+ .clickOn (' #something' ) // do something that changes the url
124+ .getUrlObject ();
124125```
125126
126127### browser.getStatusCode(): Promise\< number\>
@@ -137,7 +138,7 @@ Navigates the browser to the specified relative or absolute url.
137138
138139``` js
139140await browser
140- .loadPage (' /products' ); // implies assertStatusCode(200)
141+ .loadPage (' /products' ); // implies assertStatusCode(200)
141142```
142143
143144The following ` loadPageOpts ` options are supported:
@@ -188,37 +189,23 @@ await browser
188189 .loadPage (' /products' , { headers: { ' x-custom-header' : ' Some-Value' } });
189190```
190191
191- #### Example: Absolute URL
192-
193- If the url is absolute, any methods that depend on the proxy (` getStatusCode ` and ` getHeaders ` )
194- will not work.
195- This is a bug and will be fixed.
196-
197- ``` js
198- await browser
199- // Navigates to https://www.google.com/?q=Testium+api
200- .loadPage (' http://www.google.com' , { query: { q: ' Testium api' } })
201- // But this will fail because the URL was absolute:
202- .getStatusCode ();
203- ```
204-
205192### browser.refresh(): Promise\< void\>
206193
207194Refresh the current page.
208195
209196``` js
210197await browser
211198 .loadPage (' /' )
212- .clickOn (' #something' ) // does something that changes the page
213- .refresh (); // reload the current page
199+ .clickOn (' #something' ) // does something that changes the page
200+ .refresh (); // reload the current page
214201```
215202
216203### browser.waitForPath(path: string|RegExp, timeout=5000: number): Promise\< void\>
217204
218205Waits ` timeout ` ms for the browser to be at the specified ` path ` .
219206``` js
220207await browser .waitForPath (' /foo' );
221- await browser .waitForPath (' /foo' , 10000 ); // with increased timeout
208+ await browser .waitForPath (' /foo' , 10000 ); // with increased timeout
222209```
223210### browser.waitForUrl(url: string|RegExp, query?: Record\< string, string|number\> , timeout=5000: number): Promise\< void\>
224211
@@ -440,7 +427,7 @@ await browser.assertElementDoesntExist('.user-name');
440427
441428Asserts that ` selector ` matches exactly ` number ` elements.
442429``` js
443- await browser .assertElementsNumber (' .foo' , 3 ) // must have exactly 3 elements
430+ await browser .assertElementsNumber (' .foo' , 3 ); // must have exactly 3 elements
444431```
445432### browser.assertElementsNumber(selector: string , {min?: number, max?: number, equal?: number}): Promise\< Element[ ] \>
446433<span class =" new-in " >Added in: Testium-driver-wd v3.0.0</span >
@@ -452,9 +439,9 @@ Asserts that `selector` matches element numbers:
452439- ` equal ` : exactly ` equal ` amount of elements
453440
454441``` js
455- await browser .assertElementsNumber (' .foo' , { min: 1 }); // must have at least 5 elements
456- await browser .assertElementsNumber (' .bar' , { max: 5 }); // can have up to 5 elements
457- await browser .assertElementsNumber (' .elm' , { equal: 3 }); // must have exactly 3 elements
442+ await browser .assertElementsNumber (' .foo' , { min: 1 }); // must have at least 5 elements
443+ await browser .assertElementsNumber (' .bar' , { max: 5 }); // can have up to 5 elements
444+ await browser .assertElementsNumber (' .elm' , { equal: 3 }); // must have exactly 3 elements
458445```
459446
460447
@@ -737,7 +724,7 @@ Sets a cookie on the current page's domain to the value given.
737724
738725``` js
739726browser
740- .setCookieValue (' userId' , ' 3' ) // set before loading the page
727+ .setCookieValue (' userId' , ' 3' ) // set before loading the page
741728 .loadPage (' /' );
742729```
743730
@@ -900,7 +887,7 @@ browser
900887
901888Change focus to another frame on the page.
902889``` js
903- browser .switchToFrame (' some-frame' )
890+ browser .switchToFrame (' some-frame' );
904891```
905892
906893### browser.switchToDefaultWindow(): Promise\< void\>
@@ -1002,7 +989,7 @@ before(async () => {
1002989 lhResults = await browser
1003990 .loadPage (' /path' )
1004991 .runLighthouseAudit ({
1005- chromeFlags: [' --disable-device-emulation' ], // To run audit in Desktop mode
992+ chromeFlags: [' --disable-device-emulation' ], // To run audit in Desktop mode
1006993 });
1007994});
1008995
@@ -1040,14 +1027,14 @@ const issues = await browser
10401027 .loadPage (' /path' )
10411028 .a11yAudit ();
10421029
1043- assert .strictEqual (issues .length , 0 )
1030+ assert .strictEqual (issues .length , 0 );
10441031```
10451032
10461033``` js
10471034const issues = await browser
10481035 .loadPage (' /path' )
10491036 .a11yAudit ({
1050- ignore: [' color-contrast' , ' meta-viewport' ], // ignore 'color-contrast' and 'meta-viewport'
1037+ ignore: [' color-contrast' , ' meta-viewport' ], // ignore 'color-contrast' and 'meta-viewport'
10511038 });
10521039
10531040assert .strictEqual (issues .length , 0 );
0 commit comments