@dfinity/internet-identity-playwright 0.0.4 → 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +1 -1
- package/README.md +35 -1
- package/dist/index.js +1 -1
- package/dist/types/page-objects/InternetIdentityPage.d.ts +5 -3
- package/package.json +15 -13
package/LICENSE
CHANGED
|
@@ -186,7 +186,7 @@
|
|
|
186
186
|
same "printed page" as the copyright notice for easier
|
|
187
187
|
identification within third-party archives.
|
|
188
188
|
|
|
189
|
-
Copyright
|
|
189
|
+
Copyright 2024 DFINITY Foundation.
|
|
190
190
|
|
|
191
191
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
192
|
you may not use this file except in compliance with the License.
|
package/README.md
CHANGED
|
@@ -74,6 +74,26 @@ testWithII('should sign-in with an existing new user', async ({page, iiPage}) =>
|
|
|
74
74
|
});
|
|
75
75
|
```
|
|
76
76
|
|
|
77
|
+
The plugin defaults to an Internet Identity sign-in flow that does not require captcha. If you wish to set up a test that requires this validation, you can pass the option `captcha` set to `true` when initializing a new user:
|
|
78
|
+
|
|
79
|
+
```javascript
|
|
80
|
+
testWithII('should sign-in with a new user when II requires a captcha', async ({page, iiPage}) => {
|
|
81
|
+
await page.goto('/');
|
|
82
|
+
|
|
83
|
+
await iiPage.signInWithNewIdentity({captcha: true});
|
|
84
|
+
});
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
Similarly, you can test a flow where Internet Identity requires the user to create and save a passkey:
|
|
88
|
+
|
|
89
|
+
```javascript
|
|
90
|
+
testWithII('should sign in with a new user when II requires a passkey', async ({page, iiPage}) => {
|
|
91
|
+
await page.goto('/');
|
|
92
|
+
|
|
93
|
+
await iiPage.signInWithNewIdentity({createPasskey: true});
|
|
94
|
+
});
|
|
95
|
+
```
|
|
96
|
+
|
|
77
97
|
### 3. Wait for Internet Identity (optional)
|
|
78
98
|
|
|
79
99
|
You might encounter scenarios where you perform tests against a local replica started in parallel with your tests, commonly when automating the tests in a CI environment. The library also exposes a fixture that lets you wait for Internet Identity to be ready.
|
|
@@ -157,6 +177,20 @@ Then, navigate to the root directory and run the dedicated test:
|
|
|
157
177
|
npm run e2e:captcha
|
|
158
178
|
```
|
|
159
179
|
|
|
180
|
+
### Running Required Passkey Tests Locally
|
|
181
|
+
|
|
182
|
+
The default test suite validates the use of the latest Internet Identity, which does not require the user to complete a specific step to create a passkey. To test a flow where passkey creation is required, run the following command from the `demo` directory:
|
|
183
|
+
|
|
184
|
+
```bash
|
|
185
|
+
docker compose -f docker-compose.passkey.yml up
|
|
186
|
+
```
|
|
187
|
+
|
|
188
|
+
Then, navigate to the root directory and run the dedicated test:
|
|
189
|
+
|
|
190
|
+
```bash
|
|
191
|
+
npm run e2e:passkey
|
|
192
|
+
```
|
|
193
|
+
|
|
160
194
|
## 🚧 Limitations
|
|
161
195
|
|
|
162
196
|
Currently, the library's fixtures cannot be implemented with Playwright's ability to [load existing authenticated state](https://playwright.dev/docs/auth). Playwright currently does not support IndexedDB for such features. This limitation is tracked in their [GitHub issue #11164](https://github.com/microsoft/playwright/issues/11164).
|
|
@@ -166,4 +200,4 @@ While it is technically possible to use local storage instead of IndexedDB, this
|
|
|
166
200
|
## 🧑🤝🧑 Community
|
|
167
201
|
|
|
168
202
|
- [Forum](https://forum.dfinity.org/)
|
|
169
|
-
- [Discord](https://discord.
|
|
203
|
+
- [Discord](https://discord.internetcomputer.org)
|
package/dist/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{test as I}from"@playwright/test";import{expect as a}from"@playwright/test";var n=class{page;browser;context;constructor({page:
|
|
1
|
+
import{test as I}from"@playwright/test";import{expect as a}from"@playwright/test";var n=class{page;browser;context;constructor({page:e,context:i,browser:t}){this.page=e,this.browser=t,this.context=i}waitReady=async({url:e,canisterId:i,timeout:t=6e4})=>{let{host:o,protocol:c}=new URL(e),d=i!==void 0?this.browser.browserType().name()==="webkit"?`${c}//${o}?canisterId=${i}`:`${c}//${i}.${o.replace("127.0.0.1","localhost")}`:e,y=async()=>{try{return(await this.page.goto(d,{waitUntil:"domcontentloaded"}))?.ok()??!1}catch{return!1}},l=500,u=async({count:r})=>{if(await y())return"ready";let w=r-1;return w===0?"timeout":(await new Promise(m=>setTimeout(m,l)),await u({count:w}))},p=await u({count:t/l});a(p).toEqual("ready"),await a(this.page).toHaveTitle("Internet Identity");let g=this.page.locator("#registerButton");a(g).not.toBeNull()};signInWithNewIdentity=async e=>{let i=this.context.waitForEvent("page");await this.page.locator(e?.selector??"[data-tid=login-button]").click();let t=await i;await a(t).toHaveTitle("Internet Identity"),await t.locator("#registerButton").click(),e?.createPasskey===!0&&await t.locator("[data-action=construct-identity]").click(),e?.captcha===!0&&(await t.locator("input#captchaInput").fill("a",{timeout:1e4}),await t.locator("#confirmRegisterButton").click());let o=await t.locator("#userNumber").textContent();return a(o).not.toBeNull(),await t.locator("#displayUserContinue").click(),await t.waitForEvent("close"),a(t.isClosed()).toBe(!0),parseInt(o)};signInWithIdentity=async({selector:e,identity:i})=>{let t=this.context.waitForEvent("page");await this.page.locator(e??"[data-tid=login-button]").click();let o=await t;await a(o).toHaveTitle("Internet Identity"),await o.locator(`[data-anchor-id='${i}']`).click(),await o.waitForEvent("close"),a(o.isClosed()).toBe(!0)}};import{expect as $}from"@playwright/test";var k=I.extend({iiPage:async({page:s,browser:e,context:i},t)=>{let o=new n({page:s,context:i,browser:e});await t(o)}});export{n as InternetIdentityPage,$ as expect,k as testWithII};
|
|
@@ -30,8 +30,8 @@ export declare class InternetIdentityPage {
|
|
|
30
30
|
*/
|
|
31
31
|
waitReady: ({ url: rootUrl, canisterId, timeout }: {
|
|
32
32
|
url: string;
|
|
33
|
-
canisterId?: string
|
|
34
|
-
timeout?: number
|
|
33
|
+
canisterId?: string;
|
|
34
|
+
timeout?: number;
|
|
35
35
|
}) => Promise<void>;
|
|
36
36
|
/**
|
|
37
37
|
* Signs in and create a new user.
|
|
@@ -39,11 +39,13 @@ export declare class InternetIdentityPage {
|
|
|
39
39
|
* @param {Object} [params] - The optional arguments for the sign-in method.
|
|
40
40
|
* @param {string} [params.selector] - The selector for the login button. Defaults to [data-tid=login-button].
|
|
41
41
|
* @param {boolean} [params.captcha] - Set to true if the II login flow requires a captcha.
|
|
42
|
+
* @param {boolean} [params.createPasskey] - Set to true if the II login flow requires the user to create a passkey.
|
|
42
43
|
* @returns {Promise<number>} A promise that resolves to the new identity number.
|
|
43
44
|
*/
|
|
44
45
|
signInWithNewIdentity: (params?: {
|
|
45
46
|
selector?: string;
|
|
46
47
|
captcha?: boolean;
|
|
48
|
+
createPasskey?: boolean;
|
|
47
49
|
}) => Promise<number>;
|
|
48
50
|
/**
|
|
49
51
|
* Signs in with an existing identity.
|
|
@@ -53,7 +55,7 @@ export declare class InternetIdentityPage {
|
|
|
53
55
|
* @returns {Promise<void>} A promise that resolves when the sign-in process is complete.
|
|
54
56
|
*/
|
|
55
57
|
signInWithIdentity: ({ selector, identity }: {
|
|
56
|
-
selector?: string
|
|
58
|
+
selector?: string;
|
|
57
59
|
identity: number;
|
|
58
60
|
}) => Promise<void>;
|
|
59
61
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dfinity/internet-identity-playwright",
|
|
3
|
-
"version": "0.0
|
|
3
|
+
"version": "2.0.0",
|
|
4
4
|
"description": "A Playwright library to simplify the integration of Internet Identity authentication in E2E tests.",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"repository": {
|
|
@@ -44,25 +44,27 @@
|
|
|
44
44
|
"format:check": "prettier --check .",
|
|
45
45
|
"ts-declaration": "tsc --emitDeclarationOnly --outDir dist/types",
|
|
46
46
|
"build": "tsc --noEmit && node rmdir.mjs && node esbuild.mjs && npm run ts-declaration",
|
|
47
|
-
"lint": "eslint --max-warnings 0
|
|
47
|
+
"lint": "eslint --max-warnings 0",
|
|
48
48
|
"dev": "npm --prefix demo run dev",
|
|
49
|
-
"e2e": "NODE_ENV=development playwright test
|
|
50
|
-
"e2e:ci": "playwright test --reporter=html
|
|
49
|
+
"e2e": "NODE_ENV=development playwright test e2e/login.spec",
|
|
50
|
+
"e2e:ci": "playwright test --reporter=html e2e/login.spec",
|
|
51
51
|
"e2e:captcha": "NODE_ENV=development playwright test e2e/captcha.spec",
|
|
52
|
-
"e2e:captcha:ci": "playwright test --reporter=html e2e/captcha.spec"
|
|
52
|
+
"e2e:captcha:ci": "playwright test --reporter=html e2e/captcha.spec",
|
|
53
|
+
"e2e:passkey": "NODE_ENV=development playwright test e2e/passkey.spec",
|
|
54
|
+
"e2e:passkey:ci": "playwright test --reporter=html e2e/passkey.spec"
|
|
53
55
|
},
|
|
54
56
|
"devDependencies": {
|
|
55
|
-
"@dfinity/eslint-config-oisy-wallet": "^0.
|
|
56
|
-
"@types/node": "^
|
|
57
|
-
"esbuild": "^0.
|
|
58
|
-
"prettier": "^3.
|
|
59
|
-
"prettier-plugin-organize-imports": "^4.
|
|
60
|
-
"typescript": "^5.
|
|
57
|
+
"@dfinity/eslint-config-oisy-wallet": "^0.1.10",
|
|
58
|
+
"@types/node": "^22.15.18",
|
|
59
|
+
"esbuild": "^0.25.4",
|
|
60
|
+
"prettier": "^3.5.3",
|
|
61
|
+
"prettier-plugin-organize-imports": "^4.1.0",
|
|
62
|
+
"typescript": "^5.7.3"
|
|
61
63
|
},
|
|
62
64
|
"engines": {
|
|
63
|
-
"node": ">=
|
|
65
|
+
"node": ">=22"
|
|
64
66
|
},
|
|
65
67
|
"peerDependencies": {
|
|
66
|
-
"@playwright/test": "^1.
|
|
68
|
+
"@playwright/test": "^1.52.0"
|
|
67
69
|
}
|
|
68
70
|
}
|