The issue
I’ve encountered the following issue:
PS C:\Users\38163\Desktop\BrowserStack Test\cypress-example-kitchensink> browserstack-cypress init
>>
browserstack-cypress : File C:\Users\38163\AppData\Roaming\npm\browserstack-cypress.ps1 cannot be loaded because running scripts is disabled on this system. For more information, see
about_Execution_Policies at https:/go.microsoft.com/fwlink/?LinkID=135170.
At line:1 char:1
+ browserstack-cypress init
+ ~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : SecurityError: (:) [], PSSecurityException
+ FullyQualifiedErrorId : UnauthorizedAccess
The error encountered is related to PowerShell’s execution policy, which is preventing us from running scripts like browserstack-cypress.ps1
due to security settings on your system.
Solution: Change Execution Policy
To fix this, you’ll need to change your PowerShell Execution Policy to allow scripts to be run. Here’s how you can do it:
Step 1: Open PowerShell as Administrator
- Search for PowerShell in your Start menu.
- Right-click on Windows PowerShell and select Run as Administrator.
Step 2: Check the Current Execution Policy
In the administrator PowerShell window, type the following command and press Enter:
Get-ExecutionPolicy
You might see something like Restricted
or RemoteSigned
, which is why scripts are blocked.
Step 3: Change the Execution Policy
To allow running scripts, you’ll need to change the execution policy. You can do this by running:
Set-ExecutionPolicy RemoteSigned -Scope CurrentUser
RemoteSigned
allows local scripts to run and requires downloaded scripts to have a valid signature.-Scope CurrentUser
ensures this change only affects your user account, not the entire system.
Step 4: Confirm the Change
When prompted with a confirmation message, type Y
and press Enter.
Step 5: Verify the Change
You can verify the change by running the command again:
Get-ExecutionPolicy
It should now show RemoteSigned
or another less restrictive policy.
Step 6: Run the BrowserStack Cypress CLI Again
Now that the execution policy is updated, go back to your original terminal and run:
browserstack-cypress init
This should work without the security error.
Important Note:
Once you’re done running the necessary scripts, if you’d like to revert the execution policy for extra security, you can do so with:
Set-ExecutionPolicy Restricted -Scope CurrentUser