Nội dung bài viết
I. Download and Setup Nodejs
Down Nodejs từ https://nodejs.org/en/download/
Bạn tự chọn phiên bản phù hợp cho hệ điều hành và cài đặt như bình thường
II. Setup Visual Studio Code (VS Code)
Down từ https://code.visualstudio.com/download và cài đặt như bình thường
III. Create a project
1. Create a folder
Bạn có thể tự tạo folder có dạng như sau:
C:\Users\dunguyen\Projects\CypressAuto
2. Create package.json file
- Mở folder của project bằng VS code

- Mở terminal

- Gõ lệnh
npm init
hoặc
npm init -y

- OK để tạo file package.json

3. Install Cypress
- Vẫn ở màn hình terminal đó, gõ
npm install cypress --save-dev

- Đợi nó chạy xong là OK, kết thúc phần cài đặt môi trường.

IV. Trải nghiệm Cypress Runner
Gõ vào terminal
npx cypress open
Cypress sẽ tạo cho bạn 1 project mẫu có nhiều file testcase để bạn có thể xem thử các tính năng của cypress và cách sử dụng.

Đây là thành quả sau khi run thử 1 file:

npm ERR! code EPERM
npm ERR! syscall open
npm ERR! path C:\Users\duydo\projects\cypressauto\package.json
npm ERR! errno -4048
npm ERR! Error: EPERM: operation not permitted, open ‘C:\Users\duydo\projects\cypressauto\package.json’
npm ERR! [Error: EPERM: operation not permitted, open ‘C:\Users\duydo\projects\cypressauto\package.json’] {
npm ERR! errno: -4048,
npm ERR! code: ‘EPERM’,
npm ERR! syscall: ‘open’,
npm ERR! path: ‘C:\\Users\\duydo\\projects\\cypressauto\\package.json’
npm ERR! }
npm ERR!
npm ERR! The operation was rejected by your operating system.
npm ERR! It’s possible that the file was already in use (by a text editor or antivirus),
npm ERR! or that you lack permissions to access it.
npm ERR!
npm ERR! If you believe this might be a permissions issue, please double-check the
npm ERR! permissions of the file and its containing directories, or try running
npm ERR! the command again as root/Administrator.
npm ERR! A complete log of this run can be found in:
npm ERR! C:\Users\EQ-338\AppData\Roaming\npm-cache\_logs\2021-07-16T09_42_51_104Z-debug.log
PS C:\Users\duydo\projects\cypressauto>
Báo lỗi vầy là sao huynh
1. File (package.json) đang được mở bằng 1 cái khác –> kiểm tra lại
2. Không có permission với file/folder –> run command line bằng quyền Admin thử xem
3. Tạo project ở folder khác, ổ D chẳng hạn.
Em gõ npm init nó hiện lỗi như này ạ 🙁
npm : The term ‘npm’ is not recognized as the name of a cmdlet, function, script file,
or operable program. Check the spelling of the name, or if a path was included, verify
that the path is correct and try again.
At line:1 char:1
+ npm init
+ ~~~
+ CategoryInfo : ObjectNotFound: (npm:String) [], CommandNotFoundExceptio
n
+ FullyQualifiedErrorId : CommandNotFoundException
Bạn cài nodejs trước khi gọi vào `npm`. Nếu cài nodejs rồi mà gõ vào cmd của VS code mà vẫn bị thì tắt VS code đi rồi bật lại.