Stop hard-coding test data in your Maestro flows
Đừng gõ cứng dữ liệu test trong flow Maestro
The fastest way to break a test suite is to commit inputText: "Secret123". The password changes, the account gets locked, or worse, the secret leaks through your repository. Maestro already supports variables; the hard part is using them consistently while you record.
1. Define the variables once
In AppFlight open Settings → Environment and add your keys, or import an existing .env file:
EMAIL=qa@example.com PASSWORD=•••••••• OTP_CODE=000000
2. Fill fields while recording
Tap a text field in the preview. The Fill with bar lists your variables, best match first (an email field suggests EMAIL). Click one: the real value is typed into the app, but the step is saved with the variable name.
- tapOn: id: "email_input" - inputText: ${EMAIL} - inputText: ${PASSWORD}
3. Pass values in CI
When the flow runs elsewhere, provide the values from your CI secrets:
maestro test .maestro/login.yaml -e EMAIL="$EMAIL" -e PASSWORD="$PASSWORD"
Password fields are turned into variables automatically, and when a project is shared through git only the variable names are written. Each teammate keeps their own values on their own Mac.
Cách nhanh nhất để làm hỏng bộ test là commit inputText: "Secret123". Mật khẩu đổi, tài khoản bị khoá, tệ hơn là bí mật bị lộ qua repository. Maestro đã hỗ trợ biến; cái khó là dùng biến đều tay trong lúc ghi test.
1. Khai báo biến một lần
Trong AppFlight mở Settings → Environment rồi thêm các khoá, hoặc import file .env có sẵn:
EMAIL=qa@example.com PASSWORD=•••••••• OTP_CODE=000000
2. Điền ô nhập khi đang ghi
Chạm vào một ô nhập trên màn hình xem trước. Thanh Fill with liệt kê các biến, khớp nhất đứng đầu (ô email sẽ gợi ý EMAIL). Bấm một biến: giá trị thật được gõ vào app, còn bước được lưu bằng tên biến.
- tapOn: id: "email_input" - inputText: ${EMAIL} - inputText: ${PASSWORD}
3. Truyền giá trị trên CI
Khi flow chạy ở nơi khác, lấy giá trị từ secret của CI:
maestro test .maestro/login.yaml -e EMAIL="$EMAIL" -e PASSWORD="$PASSWORD"
Ô mật khẩu tự động thành biến, và khi chia sẻ project qua git thì chỉ tên biến được ghi ra. Mỗi người trong team giữ giá trị riêng trên máy Mac của mình.