How to Connect with NativeBridge Using ADB: Advanced Testing Capabilities in Your Browser

How to Connect with NativeBridge Using ADB: Advanced Testing Capabilities in Your Browser

NativeBridge transforms mobile app testing by allowing you to access native mobile apps directly through your browser. While our browser-based interface is robust on its own, advanced users can enhance their testing experience by linking their local development environment to NativeBridge's remote devices using the Android Debug Bridge (ADB).

 This guide will help you set up an ADB connection with devices running on NativeBridge, providing you with advanced testing and debugging features that effectively connect your local development setup with our cloud-hosted devices.

 What is ADB and Why Use It with NativeBridge?

Android Debug Bridge (ADB) is a flexible command-line tool that facilitates direct communication between your development machine and Android devices. When used with NativeBridge, ADB offers powerful functionalities:

 - Execute automated tests directly on remote devices

- Transfer files between your local machine and the remote device

- Install APKs straight from your development pipeline

- Access device logs for more in-depth debugging

- Utilize tools like scrcpy for improved device controls

Prerequisites

Before getting started, ensure you have:

  1. An active NativeBridge account with a running device session
  2. ADB installed on your local machine
  • For Windows: Install via Android Studio or download the Platform Tools directly
  • For macOS: Install via brew install android-platform-tools
  • For Linux: Install via your package manager or download Platform Tools

Connecting to a NativeBridge Device via ADB

Step 1: Launch Your Device Session

Start by launching a device session in NativeBridge. This can be either an emulated device or a real physical device.

Step 2: Access the ADB Connection Details

  1. In your active device session, locate and click the "Connect With ADB" button in the device control panel.
  2. A modal will appear displaying a connection command in the format: adb connect <deviceURL>
  3. This URL is a unique identifier for your specific device session.

Step 3: Establish the ADB Connection

  1. Copy the entire adb connect <deviceURL> command from the modal.
  2. Open your terminal or command prompt.
  3. Paste and execute the command:
adb connect device-id-12345.devices.nativebridge.io:7000
  1. If successful, you should see a confirmation message: connected to device-id-12345.devices.nativebridge.io:7000

Step 4: Verify the Connection

To confirm your device is properly connected, run:

adb devices

You should see your NativeBridge device listed in the output, showing the status as "device":

List of devices attached
device-id-12345.devices.nativebridge.io:7000    device

Leveraging scrcpy for Enhanced Control

While NativeBridge provides a full browser-based interface, you can also use scrcpy (screen copy) for an alternative way to view and control your remote device with potentially lower latency.

Setting Up scrcpy

1.Install scrcpy on your local machine:

For Windows: Use Chocolatey: choco install scrcpy

For macOS: Use Homebrew: brew install scrcpy

For Linux: Use your package manager (e.g., apt install scrcpy)

Connecting with scrcpy

  1. With your ADB connection established, run the following command:
scrcpy -s device-id-12345.devices.nativebridge.io:7000
  1. A new window will open displaying your remote device screen, which you can control using your mouse and keyboard.

Common ADB Commands for NativeBridge Testing Workflows

Once connected, you can use standard ADB commands to interact with your NativeBridge device:

Installing Apps

adb -s device-id-12345.devices.nativebridge.io:7000 install path/to/your/app.apk

Pushing Files

adb -s device-id-12345.devices.nativebridge.io:7000 push local/path/file.txt /sdcard/

Pulling Files (like screenshots or logs)

adb -s device-id-12345.devices.nativebridge.io:7000 pull /sdcard/screenshots/screen.png ./local/path/

Running Shell Commands

adb -s device-id-12345.devices.nativebridge.io:7000 shell dumpsys battery

Capturing a Screen Recording

adb -s device-id-12345.devices.nativebridge.io:7000 shell screenrecord /sdcard/recording.mp4

(Press Ctrl+C to stop recording, then pull the file to your local machine)

Troubleshooting ADB Connections

Connection Failed or "Failed to Connect" Errors

If you encounter connection failures, this might be due to your IP address being temporarily blocked by our security system. Here's how to resolve this:

  1. Access the Connection Troubleshooter: When you click the "Connect With ADB" button and the modal opens, look for the "Having trouble connecting?" link or button.
  2. Check Your IP Status: Click on the troubleshooting option to open the IP status checker. This will show you:
    • Your current IP address
    • Whether your IP is blocked or allowed
    • Connection status information
  3. Manual IP Entry: If you're connected through a different IP , you can manually enter your actual IP address in the provided field.
  4. Unblock Your IP: If the system shows your IP is blocked:
    • First, run the disconnect command on terminal: adb disconnect
    • Then click the "Unblock My IP" button in the troubleshooter
    • Retry the connection with the same ADB connect string
  5. IP Whitelisting: For frequent users or enterprise customers, we also support IP whitelisting. Contact support for more information about adding your IP addresses to the whitelist.

Important: Always remember to run adb disconnect when you're finished with your testing session. This helps prevent your IP from being temporarily blocked and ensures smooth connections in future sessions.

Connection Refused or Timeout

If you encounter connection issues:

  1. Ensure your NativeBridge session is active and not timed out
  2. Attempt the connection again

Try restarting ADB with:

adb kill-server
adb start-server

Benefits for Team Collaboration

ADB connectivity in NativeBridge enhances collaboration between individual developers and the wider team:

 Developers can execute automated tests on shared devices without needing physical access.

QA Engineers can confirm issues found during browser sessions using advanced ADB diagnostics.

DevOps can seamlessly incorporate NativeBridge devices into CI/CD pipelines through ADB connections.

Conclusion

By connecting to NativeBridge.io devices via ADB, you merge the ease of browser-based testing with the power and flexibility of local development tools. This hybrid approach offers the best of both worlds: the accessibility of cloud testing combined with the capabilities of local device testing.

Begin integrating NativeBridge's remote devices into your development workflow today, and discover a new level of efficiency in mobile app testing and debugging.