How can I add some environment variables through a schema and then retrieve those variables using code?
For example I want to add an environment variable to describe the "exec_mode" like "development" or "production"... and I though to add this variable directly into the schema "environment variables". Now how can I get this variable back into my code in Swift?
Use the jump bar next to the Run and Stop buttons in the project window toolbar to open the scheme editor. Select the Run step on the left side of the scheme editor. Click the Arguments button at the top of the scheme editor to access the environment variables. Use the Add (+) button to add the environment variables.
Set an Environment Variable — temporary or permanent you can set an environment variable for the temporary or permanent use. It depends on the case, if you need a variable for just one time, you can set it up using terminal. Otherwise, you can have it permanently in Bash Shell Startup Script with “Export” command.
Environment variables in UFT/QTP are very special types of variables that are accessible across all actions(either local or external actions), function libraries, and recovery scenarios in a test. UFT environment variables are available only for test script during runtime and can't be accessed by any other program.
You can get the environment variables with NSProcessInfo
:
let env = NSProcessInfo.processInfo().environment
if let mode = env["exec_mode"] as? String {
print(mode)
} else {
// Environment variable not set
}
Swift 3:
let env = ProcessInfo.processInfo.environment
if let mode = env["exec_mode"] {
print(mode)
} else {
// Environment variable not set
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With