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 qdc_api
from qdc_public_api_client.models import ArtifactType
if __name__ == '__main__':
api_key = "" # copy from user settings
# Headers are mandatory, please set X-QCOM-OnBehalfOf accordingly
app_name = "appname" # name of the Client
client_type = "Python" # Client code type connecting to QDC
on_behalf_of = "user" # username of the user who is initiating the request.
public_api_client = qdc_api.get_public_api_client_using_api_key(app_name_header=app_name,
on_behalf_of_header=on_behalf_of,
client_type_header=client_type,
api_key_header=api_key)
# Section (1): preparing the parameters and submitting the session
session_device_target = "SM8550" # device target chipset
test_package_file = r"test-packages/CalculatorExample.apk" # optional
ssh_public_key_id = 1001 # ssh key owned by the user, taking 1001 as an example
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_id=ssh_public_key_id)
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.