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
Type | Artifacts Number | Suffix |
---|---|---|
test package | optional | .apk |
test script | N/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 timeimport qdc_apifrom qdc_public_api_client.models import ArtifactTypeif __name__ == '__main__':api_key = "" # copy from user settings# Headers are mandatory, please set X-QCOM-OnBehalfOf accordinglyapp_name = "appname" # name of the Clientclient_type = "Python" # Client code type connecting to QDCon_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 sessionsession_device_target = "SM8550" # device target chipsettest_package_file = r"test-packages/CalculatorExample.apk" # optionalssh_public_key_id = 1001 # ssh key owned by the user, taking 1001 as an exampletest_package_response = qdc_api.upload_file(public_api_client, test_package_file, ArtifactType.TESTPACKAGE) # optionalsession_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 statuschecked = 0wait_time_seconds = 15while 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()}.")breakelse:checked = checked + 1if checked > 20: # Stop polling after polling 20 timesprint(f"Session state is {poll_session_status.lower()}.")breakprint(f"Session state is {poll_session_status.lower()} mode, waiting for {wait_time_seconds} seconds...")time.sleep(wait_time_seconds)# Section (3): user custom workchecked = 0while True:checked = checked + 1if checked > 10:print(f"Finish user custom work.")breakprint(f"Sleep to mock the user work...")time.sleep(wait_time_seconds)# Section (4): complete the session when finish the user workcomplete_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.