Using Code-based Actions
Overview
Some testing scenarios may require additional setup on the virtual machine before you’re able to test your application or website (e.g., changing the time zone or downloading files). You can use code-based actions to simplify these steps to a single executable action.
Code-based actions are only available on Windows virtual machines
How to add a code-based action
To add a code-based action to your test:
- Add a comment action step
- Enter the desired command in the comment section
All commands have a leading rf_vm_command:
, followed by the code-based action and its setting. (Starting with rf_vm_command:
is how we know it’s a code-based action and not a normal comment.)
Supported actions
The following commands are the only supported action types:
- Setting timezone:
rf_vm_command: set_timezone timezone="…"
e.grf_vm_command: set_timezone timezone="Eastern Standard Time"
- For example: Eastern Standard Time, Central Standard Time, Pacific Standard Time
- Time zones need to be supported by Microsoft and written out fully. For a list of supported time zones and formatting, please refer to the timezone column here.
- Setting region:
rf_vm_command: set_region region="…"
e.grf_vm_command: set_region region="United States"
- To see a full list go to settings > regions from within the virtual machine
- Downloading a File:
rf_vm_command: download url="…" destination="..." headers="{'Accept': '...', 'Authorization': '...'}"
- Only
url
is required for this action. Bothdestination
andheaders
don’t need to be passed. - If
destination
is not passed it defaults to theDownloads
folder. - The
headers
option is similar to HTTP headers and was only added for cases where the URL for downloading requires some authorization. - Note: there's a non-code way to do this by adding a download action and uploading the file directly to the test steps to use it within the virtual machine. Learn more here.
- Only
- Downloading and Opening a File:
rf_vm_command: download url="…" destination="..." headers="{'Accept': '...', 'Authorization': '...'}" open=true
- This action is the same as downloading a file, but the option
open
is set totrue
to allow opening the file automatically. - Both
destination
andheaders
don’t need to be passed.
- This action is the same as downloading a file, but the option
- Installing a Chrome extension:
rf_vm_command: install_chrome_extension url="…" headers="{'Accept': '...', 'Authorization': '...'}"
- This action downloads a zipped Chrome extension from a given URL (with optional headers).
- Note: This step will restart Chrome, which might affect the state of your existing tabs.
- Executing a command:
rf_vm_command: execute command='...' elevated=true timeout=30
- This action executes a command in the VM.
elevated=true
makes the command run with administrative privileges. - We will wait for the command to exit before the step moves on. Make sure that your command exits properly. This may require the use of
start /b
or similar to make a program launch in the background, allowing the command to complete successfully. timeout
is optional, and defaults to 30s. If your command runs longer than that of the code-based action, it will return a failure.- Example to open the host file with Notepad as an admin:
rf_vm_command: execute command='cmd /c "start /b notepad.exe c:\windows\system32\drivers\etc\hosts"' elevated=true timeout=30
- This action executes a command in the VM.
If you have any questions or suggestions for additional commands, reach out to us at [email protected].
Updated about 2 months ago