Get Started
12 min
this guide creates an authenticated client, selects a device, reserves it, starts a session and cleans up the resources before you begin make sure you have installed the java or node js sdk received clientid and clientsecret from your device park administrator access to at least one device park device or pool set the credentials export devicepark client id=your client id export devicepark client secret=your client secret use the java or typescript tab consistently as you move through the lifecycle both tabs perform the same device park operation imports import java nio file files; import java nio file paths; import io testinium devicepark deviceparkapiclient; import io testinium devicepark authentication credentials credentials; import io testinium devicepark model allocation allocation; import io testinium devicepark model allocation deviceallocationrequest; import io testinium devicepark model common pagedto; import io testinium devicepark model devices device; import io testinium devicepark model devices listdevicesrequest; import io testinium devicepark model sessions devicestartsessionrequest; import io testinium devicepark model sessions session; import io testinium devicepark model sessions screenrecord screenrecord; import io testinium devicepark model sessions screenrecord screenrecordpaginationrequest;import { writefile } from "node\ fs/promises"; import { credentials, deviceallocationrequestbuilder, deviceparkapiclient, devicestartsessionrequestbuilder, listdevicesrequestbuilder } from "@devicepark/public sdk"; step 1 create the client create one client and reuse it for the complete flow deviceparkapiclient client = deviceparkapiclient builder() url("https //devicepark testinium io") credentials(credentials of( system getenv("devicepark client id"), system getenv("devicepark client secret"))) build();const client = deviceparkapiclient builder() url("https //devicepark testinium io") credentials(credentials fromenvironment()) build(); the client obtains and renews access tokens automatically step 2 select a device list devices and select a serial from the returned page pagedto\<device> devices = client devices() list( listdevicesrequest builder() page(0) size(20) build()); device selecteddevice = devices data() stream() findfirst() orelsethrow(() > new illegalstateexception("no device is available"));const devices = await client devices() list( new listdevicesrequestbuilder() page(0) size(20) build() ); const selecteddevice = devices data\[0]; if (!selecteddevice? serial) { throw new error("no device is available"); } if the test can use any device from a managed group, list pools and use pool id instead of a serial step 3 create an allocation reserve the selected device allocation allocation = client allocations() create( deviceallocationrequest builder() serial(selecteddevice serial()) priority(3) build()); if (allocation allocationid() == null) { throw new illegalstateexception("allocation id is missing"); }const allocation = await client allocations() create( new deviceallocationrequestbuilder() serial(selecteddevice serial) priority(3) build() ); if (!allocation allocationid) { throw new error("allocation id is missing"); } when deviceserial is null or queue position is greater than zero, inspect the allocation until device park assigns a device reuse the existing allocationid ; do not create duplicate allocations while waiting do not create another allocation while waiting poll or inspect the same allocationid until a device is assigned or your test runner deadline is reached step 4 start a session start the session with the active allocation session session = client sessions() start( devicestartsessionrequest builder() allocationid(allocation allocationid()) videorecording(true) build());const session = await client sessions() start( new devicestartsessionrequestbuilder() allocationid(allocation allocationid) videorecording(true) build() ); if (!session sessionid) { throw new error("session id is missing"); } store sessionid use your appium client to run automation commands for this session step 5 stop the session stop the session after the test finishes client sessions() stop(session sessionid());await client sessions() stop(session sessionid); stopping the session does not release the allocation you can start another session with the same active allocationid step 6 collect artifacts download the appium log when it is needed for troubleshooting byte\[] log = client sessions() logs(session sessionid()); files write(paths get("appium log"), log);const log = await client sessions() logs(session sessionid); await writefile("appium log", log); if recording was enabled, list screen records after the session has finalized pagedto\<screenrecord> records = client sessions() screenrecords( session sessionid(), screenrecordpaginationrequest builder() page(0) size(20) build()); system out println(records data());const records = await client sessions() screenrecords(session sessionid); console log(records data); step 7 release the allocation release the device after the final session client allocations() delete(allocation allocationid()); client close();await client allocations() delete(allocation allocationid); await client close(); production test runners should stop sessions and release allocations from cleanup code so failed tests do not leave resources active the snippets above explain each step separately use the complete examples for a self contained program with imports, validation and cleanup complete node js example /examples/node quickstartcomplete java example /examples/java quickstart next steps understand allocation targeting and queue behavior /allocations/create allocationreuse an allocation for multiple sessions docid\ bmzpbcohqbrc7rfyomonaupload an apk or ipa /applications/upload applicationhandle pagination and filtering /reference/pagination and filteringreview exact sdk method signatures /reference/sdk methodsreview response and request contracts /reference/model contracts
