-
Notifications
You must be signed in to change notification settings - Fork 3.1k
Run local server to test websites locally
This is an installation guide to help developers test locally websites using a local server. In the past, we had many cases where it was easier to test locally to reproduce the bug, debug and fix. We use W3Schools, which allows you to create a space where you can host HTML snippets and preview, but you will need to create an account and we have experienced issues running the snippets and testing on their website. Another solution is to have the HTML code hosted locally on your laptop and run a local server.
Sometimes, use cases for security issues are provided as an HTML page, so we need some way to host it locally to be able to reproduce the issue (either on a simulator or a real device).
-
First, create a folder and save all HTML snippets that you want to be tested. MDN Web Docs is a great resource to learn about the web and W3Schools
-
Navigate to the folder containing the HTML snippets using cd
-
Run the command
python3 -m http.server
in a terminal window where the HTML use case page is located. Leave this running by keeping this terminal page open. -
If you have a test file named
saved.html
, you can then access this file athttp://10.0.0.109:8000/saved.html
. The test can be run locally on a simulator or on a physical device, more details below.
If you want to run it on a real device, your phone and Mac should be on the same Wi-Fi. You can find your Mac Wi-Fi IP address in Network > Wi-Fi. For example: 10.0.0.109 Navigate to http://10.0.0.109:8000/ on your real device. Do not use https as it won’t work.
If you’re running from a simulator on your Mac, navigate to http://127.0.0.1:8000/ instead, which is the local port.
You’ll be able to navigate by clicking the use case on your real device or simulator
