Testing and debugging Shopify Scripts
You can use the debugging features in the Script Editor to test and debug your scripts.
The Script Editor checks your code for basic errors while you're writing a script:
It also reports errors that occur in published scripts, and it sends you an email when these errors occur:
It's a good idea to correct errors, such as errors in syntax, before you test or publish a script. If your script has syntax errors, thentesting your scriptprobably doesn't work.
If you need more information on a script error, then hover over the redx
图标Script Editor's margin:
Duplicating scripts
If you need to test or debug a published script because it contains errors, then duplicate the script and publish the duplicate script. You want to debug the script that was published when the error occurred because this version has the error details attached to it.
Production error details that are attached to a script are not copied when you duplicate a script.
To duplicate a script:
In theScript Editor, click the name of the script that you want to duplicate.
ClickDuplicateto make a copy of the script.
Debug production errors
To debug a production error:
Duplicatethe script that contains the errors.
Publishthe duplicate script so that there is a version of the script that is available to your customers in your store. This step assumes that the script doesn't include so many errors that it needs to be unpublished (removed) from your store.
Debug the original script using the error details that are attached to it.
Test a script
While you are working on a script, you can test it from within the Script Editor to make sure it works before you publish it to your store.
To test a script:
- In the Script Editor, open the script that you want to test.
- To edit a test cart, clickInput. You can also clickBothto see the script code and the test cart at the same time. The input view shows options for editing a cart to test your script. You can add products, customers, discount codes, customer information, and shipping information based on what you want to test your script against.
- Type in theProductssection to search for and add products to the test order.
- Type in theDiscount codesection to search for and add discount codes to the test order.
- Type in theCustomer informationsection to search for and add customers to the test order.
- ClickAddor编辑in theShipping addresssection to change the shipping address for the test order.
ClickRun scriptto see the changes that the script makes to your test cart.
If your script runs successfully, then theOutputsection updates to show the changes applied by the script. If theOutputsection doesn't change, or there are unexpected changes, then there might be errors in your script. Check theConsolebox in theRuby source codesection to resolve any script errors:
TheConsolebox reports the script's resource usage. More complex scripts use more resources. Scripts have alimited amount of CPU and memoryavailable to them.
When you are finished:
- clickSave draftto update and save an unpublished draft of the script
- clickEnableto update and publish the script.
Unsubscribe from error notifications
When you publish a script, you are subscribed automatically to notification emails for that script. Whenever a production error occurs in that script, you receive an email about the error. You can then open the Script Editor to find out more information about the error and debug it.
You can unsubscribe from these emails after you've received one. To unsubscribe, open theProduction Errorpage for the error and clickUnsubscribe.
Next steps
After you are satisfied with a your script, you can发布itto your store. You can alsoupdate your Liquid template filesso that your online store responds to the changes that your scripts make.
Learn more
Learn more about: