Sample - Mobile Session

The following is a sample Python code for calling QDC public APIs to start and complete interactive session.

  • Available chipsets

Mobile sessions have no chipset restrictions. To get the list of available targets, call this QDC public API.

  • Artifacts limitation
TypeArtifacts NumberSuffix
test packageoptional.apk
test scriptN/A

A sample Python code to start a mobile interactive session


The following steps demonstrate the complete process of creating a new interactive session, including:

  • Preparing the parameters and submitting the session

  • Polling the session status

  • Completing the session

Step 1: Create a new python file

  • Create a file named hello_qdc_session.py

  • Copy and paste the following sample code into hello_qdc_session.py

import time
import logging

from qdc_public_api_client.logging import configure_logging
from qdc_public_api_client.api import qdc_api

from qdc_public_api_client.models import ArtifactType

if __name__ == '__main__':
    configure_logging(
        level=logging.INFO,
        handlers=[
            logging.StreamHandler(), # logs to console
            logging.FileHandler("./qdc.log") # logs to file
        ])

    # Auth
    api_key = "" # copy from user settings
    appname = "appname"
    on_behalf_of = "user_name"

    public_api_client = qdc_api.get_public_api_client_using_api_key(api_key_header=api_key,
                                                                    app_name_header=appname,
                                                                    on_behalf_of_header=on_behalf_of,
                                                                    client_type_header="Python")

    # Section (1): preparing the parameters and submitting the session
    session_device_target = "SM8750"  # device target chipset
    test_package_file = r"test-packages/CalculatorExample.apk"  # optional
    ssh_public_key = "" # User-owned SSH key, copied from UI. Example: ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIFrNJ6oMPD8QsJTXAapo4xFOYiSOFTXYFuq4xEMxG1LE

    test_package_response = qdc_api.upload_file(public_api_client, test_package_file, ArtifactType.TESTPACKAGE) # optional
    session_target_id = qdc_api.get_target_id(public_api_client, session_device_target)

    session_id = qdc_api.submit_session(public_api_client=public_api_client,
                                        target_id=session_target_id,
                                        session_name="Example session",
                                        timeout=600,
                                        session_artifacts=[test_package_response],
                                        ssh_public_key=ssh_public_key)
    print("Session Id: {}".format(session_id))

    # Section (2): polling the session status
    checked = 0
    wait_time_seconds = 15
    while True:
        poll_session_status = qdc_api.get_session_status(public_api_client, session_id)
        if poll_session_status.lower() in { "completed", "canceled", "running" }:
            print(f"Session state is {poll_session_status.lower()}.")
            break
        else:
            checked = checked + 1
            if checked > 20:  # Stop polling after polling 20 times
                print(f"Session state is {poll_session_status.lower()}.")
                break
            print(f"Session state is {poll_session_status.lower()} mode, waiting for {wait_time_seconds} seconds...")
            time.sleep(wait_time_seconds)

    # Section (3): user custom work
    checked = 0
    while True:
        checked = checked + 1
        if checked > 10:
            print(f"Finish user custom work.")
            break
        print(f"Sleep to mock the user work...")
        time.sleep(wait_time_seconds)

    # Section (4): complete the session when finish the user work
    complete_session_result = qdc_api.complete_session(public_api_client, session_id)
    print(f"Complete session {complete_session_result}.")

Step 2: Prepare test package (optional)

Prepare an apk file and move it into the same folder as hello_qdc_session.py. This apk file will be uploaded to remote device during the session.

Step 3: Execute and check the session

  • Run the following command.
python hello_qdc_session.py

SSH Connection


  • SSH connection can refer to SSH.