Test a live environment
``prompt # Test my live environment Run Cofactor tests against our deployed staging app and prove they sign in. Fetch https://docs.runcofactor.com/live-environments.md (or run cofactor docs get live-environments) and follow it step by step. Ask me for the staging URL, the roles my tests need, and which login each role uses in each environment. Never put passwords in a command or in chat: tell me where to enter them. Finish by telling me the environment, each persona with its logins, and the result of one test run there. ``
A live environment is an app you already deploy, such as staging, that Cofactor tests at its real URL. It is not a sandbox, which is a copy of your app that Cofactor builds for you. Use a live environment when the app depends on something a sandbox can't copy.
Test your staging app
-
Add the environment's URL to the application. An application can hold many environments. A new application starts with one, named
production.bashcofactor application create --name "Acme Web" --base-url https://app.example.com cofactor env create --application "Acme Web" --name staging --stage staging --url https://staging.example.com
If the application already exists, run only the second command. To use another login page, set
cofactor application update "Acme Web" --login-path /login. Cofactor adds that path to the environment's URL, andcofactor env update --login-pathoverrides it for one environment.In the app you can do the same from Applications, then your application, then Environments, then Add Environment.
The Add Environment form filled in with the name staging, the stage Staging, the URL https://staging.example.com and the type Permanent. -
Add test users and say how each signs in. A persona is a role, such as
Acme admin. Each environment gets its own login for it, so one test runs in every environment without changes.bashcofactor persona create --application "Acme Web" --name "Acme admin" --description "Manages the Acme organization"
Then add a login for each environment. Passwords go in the app, never in a command. Open Applications, your application, Test Users, then Add credential on the persona. Choose Enter your own credentials, fill in the username and password, open Persona, environment & defaults, and pick the Environment. Repeat for each environment.
The Add Credential form with the persona Acme admin locked in and the environment set to staging. The Test Users tab. The persona Acme admin holds two credentials, one for staging and one for production. A credential with no environment works in every environment that has no login of its own. Credentials and personas lists the rules.
-
Receive email, if your login or your tests need it. Sign-in codes, invitations and password resets arrive in a test inbox. See Receiving email.
-
Run a test or suite in that environment.
bashcofactor credential test <credential id> cofactor workflow run <test id> --environment staging --stream cofactor test-suite run --suite "Smoke" --application "Acme Web" --environment staging --env-mode force
credential testruns a browser sign-in with one login. A test signs in as a persona through its Login step, and Cofactor picks the login for the environment the run uses. See End-to-end tests.
Check it worked
cofactor env list --application "Acme Web" cofactor persona show --application "Acme Web" <persona id> cofactor workflow runs list <test id>
env list shows the staging URL. persona show lists the persona's logins. The run you started signs in and passes, or fails with a reason you can read. If it fails with CREDENTIAL_TEMPLATE_NOT_BOUND_FOR_ENV, the persona has no login for that environment. Add one in Test Users.