This project is a tool that uses the Playwright E2E test automation framework to automatically add administrator accounts to the Dify system. You can register administrators listed in admin_list.csv as Dify administrators.
- Automatic addition of administrator accounts to Dify system
- Bulk management of administrator information via CSV file
- Generation of detailed test reports
- Backup of URLs for Dify user invitations
- Generation of SQL commands for forced user deletion in Dify's PostgreSQL
- Node.js (16.x or higher)
- npm (8.x or higher)
- Administrator access to Dify system
- Clone the repository:
git clone [repository-url]
cd playwright- Install dependencies:
npm install- Installing Playwright Dependencies:
npx playwright install --with-deps- Install Playwright browser:
npx playwright install msedge- Prepare configuration files:
cp .env.example .env
cp admin_list.csv.example admin_list.csvCopy .env.example to create .env and configure the following items:
BASE_URL=http://localhost # Dify server base URL
OWNER_EMAIL=hogehoge@gmail.com # Dify owner's email address
OWNER_PASSWORD=hogehoge # Dify owner's password
ADMIN_LISTCSV=admin_list.csv # Administrator list CSV filename
ADMIN_PASSWORD=password # Default password for administrator accounts
REGISTRATION_URL=registration_url.csv # Filename for saving registration URLs
REMOVE_SQL=remove_sql.txt # Filename for user deletion SQLWhen running the tool, administrator account information should be listed in the following format:
| Column | Description | Example |
|---|---|---|
| Administrator's email address | user1@gmail.com | |
| name | Administrator's display name | User1 |
| password | Administrator's password | "user1_passwd" |
E-Mail,name,password
user1@gmail.com,User1,"user1_passwd"
user2@gmail.com,User2,"user2_passwd"When the tool is executed, registration URLs generated during administrator account registration are saved:
E-Mail,registration_url
user1@gmail.com,http://localhost/activate?email=user1%40gmail.com&token=xxxxxSQL commands for administrator account deletion are generated:
delete from accounts WHERE email = 'user1@gmail.com';Around line 59 of AddAdmin2Dify.spec.ts, there is a line of code under "Sign in with an existing admin account" that currently works only if the account name used when creating the owner is "Dify". Therefore, the source code needs to be modified depending on the account name. For example, if the account name is "Automator Dify", the button name should be changed to 'A'.
await page.getByRole('button', { name: 'D', exact: true }).click();
# Run all tests
npx playwright test
# Run a specific test file
npx playwright test tests/AddAdmin2Dify.spec.ts
# Run tests in UI mode
npx playwright test --uiAfter test execution, an HTML report is generated in the playwright-report directory:
npx playwright show-reportdify-admin-automator/
├── tests/ # Test files
│ ├── AddAdmin2Dify.spec.ts # Administrator addition script
│ └── example.spec.ts # Sample test
├── playwright.config.ts # Playwright configuration
├── .env.example # Environment variables template
├── .env # (Note) Copy .env.example and edit according to your environment
├── admin_list.csv.example # Administrator account list template
├── admin_list.csv # Administrator account list
├── registration_url.csv # Registration URL save file (generated when tool is run)
├── remove_sql.txt # User deletion SQL file (generated when tool is run)
└── package.json # Project dependencies
- Dify admin interface only supports user deactivation
- Only users without registered data can be deleted
- Deletion may affect data integrity, use with caution
- Access PostgreSQL container:
docker exec -it docker-db-1 bash- Connect to database:
psql -U postgres -d dify- Check and delete user information:
-- Check user information
select * from accounts;
-- Delete specific user
delete from accounts WHERE email = 'example@gmail.com';