How to Test On Mobile Devices - The Easy Way
Tags: webdev, mobile, testing, tooling
Published: 2021-05-19 15:36:13

If you ever worked with React Native’s Expo, you know what a great mobile development experience feels like. But what about Mobile Web? Is there anything more annoying than trying to find your IP or creating an SSH tunnel with ngrok just to load a website on your phone?!

![Expo developer tools lets you scan a QR and see device logs in one place](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/8nydbsq9ascbllnrvd7p.png "Expo developer tools lets you scan a QR and see device logs in one place")
*Expo developer tools lets you scan a QR and see device logs in one place.*

Luckily, there are a few quick features we can use to make our development experience on mobile web just as fun as using Expo (thanks expo crew for pushing on DX front 😍).

While you can easily test on your desktop with `locahost:3000` and have great tools like [LambdaTest](https://www.lambdatest.com/) for side-by-side device testing, to get a true feel you need a physical device. There is something magical about touching your design for the first time and testing gestures becomes easier as well.

![LT Browser testing side by side virtual devices](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/xlwkgfakcxkvk5wo59q4.png)
*LT Browser testing side by side virtual devices*

# QR Codes to the rescue!

Chrome can help us with a new QR code feature. Follow these steps:

1\. Find your local network IP address

```bash
$ ipconfig getifaddr en0
# 192.168.1.140
```

2\. Start your server binding to the local ip

```bash
# Next.js / Node.js Express
yarn dev -H 192.168.1.140

# Rails
rails s -b 192.168.1.140
```

3\. Open chrome and go to the above address adding your port (e.g. [http://192.168.1.140:3000](http://192.168.1.140:3000))

4\. Right-click on the page and `Create QR code for this Page`

![Chrome context menu](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/7g4oxzhnr8m6qybjl6v6.png "Chrome context menu")
*Chrome context menu*

5\. Scan with your phone or tablet. Enjoy!

![Chrome QR code](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/721s0aye47cl4roc9r0a.png "Chrome QR code")
*Chrome QR code*

# Bonus points!

Instead of using chrome’s QR code generation, we can use the terminal. You guessed it, there is an NPM package for that!

1\. Install the package

```bash
$ yarn global add qrcode-terminal
```

2\. Generate QR Code

```bash
$ qrcode-terminal $(printf 'http://%s\n' $(ipconfig getifaddr en0 | tr -d '\n'; echo :3000 ))  \
```

![QRCode in the terminal](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/xpmj2h7q8s5j4876iksr.png "QRCode in the terminal")
*QRCode in the terminal*


3\. Scan with your phone / tablet. Enjoy!

(Yes, you can print QR codes in the terminal! It blew my mind too! 🤯 )

## P.S.

Try creating an alias for your shell (ZSH/Bash/etc)

```bash
# ~/.zshrc
# …

alias ip-lan="ipconfig getifaddr en0"
alias qrcode-lan="qrcode-terminal $(printf 'http://%s\n' $(ip-lan | tr -d '\n'; echo :3000 ))" \
```

![e.g of using aliases to generate the IP and QR Code](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/0dmrara10cs6wvfp3ked.png "e.g of using aliases to generate the IP and QR Code")
*Example of using aliases to generate the IP and QR code*

--

Originally published at [yagudaev.com](https://yagudaev.com/posts/testing-on-mobile-devices-the-easy-way)