@dfinity/internet-identity-playwright 0.0.3 → 0.0.5

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 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 2021 DFINITY LLC.
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,16 @@ 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
+
77
87
  ### 3. Wait for Internet Identity (optional)
78
88
 
79
89
  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.
@@ -126,27 +136,35 @@ Make sure you have Docker installed on your machine ([Windows](https://docs.dock
126
136
  > [!NOTE]
127
137
  > For MacBooks with M processors, it is important to use Docker Desktop version 4.25.0 or later, ideally the latest available version.
128
138
 
129
- 2. Install Juno CLI:
139
+ 2. Start the Demo Application:
140
+
141
+ Navigate to the [demo](./demo) directory and start the application using Docker:
130
142
 
131
143
  ```bash
132
- npm i -g @junobuild/cli
144
+ cd demo
145
+ docker compose up
133
146
  ```
134
147
 
135
- 3. Start the Demo Application:
148
+ 4. Run the Tests:
136
149
 
137
- Navigate to the [demo](./demo) directory and start the application using the Juno CLI:
150
+ Return to the root directory and execute the tests:
138
151
 
139
152
  ```bash
140
- cd demo
141
- juno dev start
153
+ npm run e2e
142
154
  ```
143
155
 
144
- 4. Run the Tests:
156
+ ### Running Captcha Tests Locally
145
157
 
146
- Return to the root directory and execute the tests:
158
+ The default test suite validates the use of Internet Identity without captcha requirements. To test a flow with captcha, run the following command in the `demo` directory:
147
159
 
160
+ ```bash
161
+ docker compose -f docker-compose.captcha.yml up
148
162
  ```
149
- npm run e2e
163
+
164
+ Then, navigate to the root directory and run the dedicated test:
165
+
166
+ ```bash
167
+ npm run e2e:captcha
150
168
  ```
151
169
 
152
170
  ## 🚧 Limitations
@@ -158,4 +176,4 @@ While it is technically possible to use local storage instead of IndexedDB, this
158
176
  ## 🧑‍🤝‍🧑 Community
159
177
 
160
178
  - [Forum](https://forum.dfinity.org/)
161
- - [Discord](https://discord.gg/E9FxceAg2j)
179
+ - [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:i,context:o,browser:t}){this.page=i,this.browser=t,this.context=o}waitReady=async({url:i,canisterId:o,timeout:t=6e4})=>{let{host:e,protocol:c}=new URL(i),d=o!==void 0?this.browser.browserType().name()==="webkit"?`${c}//${e}?canisterId=${o}`:`${c}//${o}.${e.replace("127.0.0.1","localhost")}`:i,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 i=>{let o=this.context.waitForEvent("page");await this.page.locator(i?.selector??"[data-tid=login-button]").click();let t=await o;await a(t).toHaveTitle("Internet Identity"),await t.locator("#registerButton").click(),await t.locator("[data-action=construct-identity]").click(),await t.locator("input#captchaInput").fill("a"),await t.locator("#confirmRegisterButton").click();let e=await t.locator("#userNumber").textContent();return a(e).not.toBeNull(),await t.locator("#displayUserContinue").click(),await t.waitForEvent("close"),a(t.isClosed()).toBe(!0),parseInt(e)};signInWithIdentity=async({selector:i,identity:o})=>{let t=this.context.waitForEvent("page");await this.page.locator(i??"[data-tid=login-button]").click();let e=await t;await a(e).toHaveTitle("Internet Identity"),await e.locator(`[data-anchor-id='${o}']`).click(),await e.waitForEvent("close"),a(e.isClosed()).toBe(!0)}};import{expect as $}from"@playwright/test";var v=I.extend({iiPage:async({page:s,browser:i,context:o},t)=>{let e=new n({page:s,context:o,browser:i});await t(e)}});export{n as InternetIdentityPage,$ as expect,v as testWithII};
1
+ import{test as I}from"@playwright/test";import{expect as a}from"@playwright/test";var n=class{page;browser;context;constructor({page:o,context:i,browser:t}){this.page=o,this.browser=t,this.context=i}waitReady=async({url:o,canisterId:i,timeout:t=6e4})=>{let{host:e,protocol:c}=new URL(o),d=i!==void 0?this.browser.browserType().name()==="webkit"?`${c}//${e}?canisterId=${i}`:`${c}//${i}.${e.replace("127.0.0.1","localhost")}`:o,p=async()=>{try{return(await this.page.goto(d,{waitUntil:"domcontentloaded"}))?.ok()??!1}catch{return!1}},l=500,u=async({count:r})=>{if(await p())return"ready";let w=r-1;return w===0?"timeout":(await new Promise(m=>setTimeout(m,l)),await u({count:w}))},y=await u({count:t/l});a(y).toEqual("ready"),await a(this.page).toHaveTitle("Internet Identity");let g=this.page.locator("#registerButton");a(g).not.toBeNull()};signInWithNewIdentity=async o=>{let i=this.context.waitForEvent("page");await this.page.locator(o?.selector??"[data-tid=login-button]").click();let t=await i;await a(t).toHaveTitle("Internet Identity"),await t.locator("#registerButton").click(),await t.locator("[data-action=construct-identity]").click(),o?.captcha===!0&&(await t.locator("input#captchaInput").fill("a",{timeout:1e4}),await t.locator("#confirmRegisterButton").click());let e=await t.locator("#userNumber").textContent();return a(e).not.toBeNull(),await t.locator("#displayUserContinue").click(),await t.waitForEvent("close"),a(t.isClosed()).toBe(!0),parseInt(e)};signInWithIdentity=async({selector:o,identity:i})=>{let t=this.context.waitForEvent("page");await this.page.locator(o??"[data-tid=login-button]").click();let e=await t;await a(e).toHaveTitle("Internet Identity"),await e.locator(`[data-anchor-id='${i}']`).click(),await e.waitForEvent("close"),a(e.isClosed()).toBe(!0)}};import{expect as $}from"@playwright/test";var v=I.extend({iiPage:async({page:s,browser:o,context:i},t)=>{let e=new n({page:s,context:i,browser:o});await t(e)}});export{n as InternetIdentityPage,$ as expect,v as testWithII};
@@ -38,10 +38,12 @@ export declare class InternetIdentityPage {
38
38
  *
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
+ * @param {boolean} [params.captcha] - Set to true if the II login flow requires a captcha.
41
42
  * @returns {Promise<number>} A promise that resolves to the new identity number.
42
43
  */
43
44
  signInWithNewIdentity: (params?: {
44
45
  selector?: string;
46
+ captcha?: boolean;
45
47
  }) => Promise<number>;
46
48
  /**
47
49
  * Signs in with an existing identity.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dfinity/internet-identity-playwright",
3
- "version": "0.0.3",
3
+ "version": "0.0.5",
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": {
@@ -46,26 +46,21 @@
46
46
  "build": "tsc --noEmit && node rmdir.mjs && node esbuild.mjs && npm run ts-declaration",
47
47
  "lint": "eslint --max-warnings 0 \"src/**/*\"",
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 --grep-invert 'captcha'",
50
+ "e2e:ci": "playwright test --reporter=html --grep-invert 'captcha'",
51
+ "e2e:captcha": "NODE_ENV=development playwright test e2e/captcha.spec",
52
+ "e2e:captcha:ci": "playwright test --reporter=html e2e/captcha.spec"
51
53
  },
52
54
  "devDependencies": {
53
- "@types/node": "^20.14.2",
54
- "@typescript-eslint/eslint-plugin": "^6.20.0",
55
- "esbuild": "^0.23.1",
56
- "eslint": "^8.57.0",
57
- "eslint-config-prettier": "^9.1.0",
58
- "eslint-config-standard-with-typescript": "^43.0.1",
59
- "eslint-plugin-import": "^2.29.1",
60
- "eslint-plugin-n": "^16.6.2",
61
- "eslint-plugin-prettier": "^5.1.3",
62
- "eslint-plugin-promise": "^6.1.1",
63
- "prettier": "^3.3.3",
64
- "prettier-plugin-organize-imports": "^4.0.0",
55
+ "@dfinity/eslint-config-oisy-wallet": "^0.0.6",
56
+ "@types/node": "^22.13.4",
57
+ "esbuild": "^0.25.0",
58
+ "prettier": "^3.5.1",
59
+ "prettier-plugin-organize-imports": "^4.1.0",
65
60
  "typescript": "^5.3.3"
66
61
  },
67
62
  "engines": {
68
- "node": ">=20"
63
+ "node": ">=22"
69
64
  },
70
65
  "peerDependencies": {
71
66
  "@playwright/test": "^1.44.1"