

本文為英文版的機器翻譯版本，如內容有任何歧義或不一致之處，概以英文版為準。

# AWS Device Farm 中的遠端存取
<a name="remote-access"></a>

 遠端存取可讓您透過 Web 瀏覽器即時使用滑動、手勢與裝置互動，以測試功能並重現客戶問題。您可以與特定裝置互動，方法為利用該裝置建立遠端偵錯工作階段。

Device Farm 中的工作階段是與 Web 瀏覽器中託管的實際實體裝置進行即時互動。工作階段會顯示您在啟動工作階段時選取的單一裝置。使用者可以一次啟動多個工作階段，但同步裝置的總數受到您具有的裝置插槽數目限制。您可以根據裝置系列 (Android 或 iOS 裝置) 購買裝置插槽。如需詳細資訊，請參閱 [Device Farm 定價](https://aws.amazon.com/device-farm/pricing/)。

Device Farm 目前提供一部分裝置進行遠端存取測試。新的裝置始終都會新增到裝置集區。

Device Farm 會擷取每個遠端存取工作階段的影片，並在工作階段期間產生活動日誌。這些結果包含您在工作階段提供的任何資訊。

**注意**  
基於安全性考量，建議您避免提供或輸入敏感資訊，例如帳戶號碼、個人登入資訊，以及遠端存取工作階段的其他詳細資訊。如果可能，請使用專為測試而開發的替代方案，例如測試帳戶。

**Topics**
+ [在 AWS Device Farm 中建立遠端存取工作階段](how-to-create-session.md)
+ [在 AWS Device Farm 中使用遠端存取工作階段](how-to-use-session.md)
+ [在 AWS Device Farm 中擷取遠端存取工作階段的結果](how-to-access-session-results.md)

# 在 AWS Device Farm 中建立遠端存取工作階段
<a name="how-to-create-session"></a>

如需遠端存取工作階段的詳細資訊，請參閱[工作階段](sessions.md)。
+ [先決條件](#how-to-create-session-prerequisites)
+ [建立遠端工作階段](#how-to-create-remote-session)
+ [後續步驟](#how-to-create-session-next-steps)

## 先決條件
<a name="how-to-create-session-prerequisites"></a>
+ 在 Device Farm 中建立專案。請遵循[在 AWS Device Farm 中建立專案](how-to-create-project.md)中的指示，然後返回此頁面。

## 建立遠端工作階段
<a name="how-to-create-remote-session"></a>

------
#### [ Console ]

1. 登入 Device Farm 主控台，網址為 https：//[https://console.aws.amazon.com/devicefarm](https://console.aws.amazon.com/devicefarm)。

1. 在 Device Farm 導覽面板上，選擇**行動裝置測試**，然後選擇**專案**。

1. 如果您已有專案，請從清單中選擇。否則，請依照 中的指示建立專案[在 AWS Device Farm 中建立專案](how-to-create-project.md)。

1. 在**遠端存取**索引標籤上，選擇**建立遠端存取工作階段**。

1. 為您的工作階段選擇一個裝置。您可以從可用裝置清單中選擇，或使用清單頂端的搜尋列搜尋裝置。

1. *（選用）* 在工作階段中包含應用程式和輔助應用程式。這些可以是新上傳的應用程式，或過去 30 天內在此專案中上傳的應用程式 (30 天後，應用程式上傳[將會過期](data-protection.md#data-protection-retention))。

1. 在 **Session name (工作階段名稱)** 中，輸入工作階段的名稱。

1. 選擇 **Confirm and start session (確認並啟動工作階段)**。

------
#### [ AWS CLI ]

*注意：這些指示僅著重於建立遠端存取工作階段。如需如何上傳應用程式以在工作階段期間使用的指示，請參閱[自動化應用程式上傳。](api-ref.md#upload-example)*

首先，[下載並安裝最新版本，以確認您的 AWS CLI 版本](https://docs.aws.amazon.com/cli/latest/userguide/getting-started-install.html)是up-to-date。

**重要**  
本文件中提及的某些命令不適用於舊版的 AWS CLI。

然後，您可以決定要在哪個裝置上測試：

```
$ aws devicefarm list-devices
```

這會顯示如下所示的輸出：

```
{
    "devices":
    [
        {
            "arn": "arn:aws:devicefarm:us-west-2::device:DE5BD47FF3BD42C3A14BF7A6EFB1BFE7",
            "name": "Google Pixel 8",
            "remoteAccessEnabled": true,
            "availability": "HIGHLY_AVAILABLE"
            ...
        },
        ...
    ]
}
```

然後，您可以使用您選擇的裝置 ARN 建立遠端存取工作階段：

```
$ aws devicefarm create-remote-access-session \
  --project-arn arn:aws:devicefarm:us-west-2:111122223333:project:12345678-1111-2222-333-456789abcdef \
  --device-arn arn:aws:devicefarm:us-west-2::device:DE5BD47FF3BD42C3A14BF7A6EFB1BFE7 \
  --app-arn arn:aws:devicefarm:us-west-2:111122223333:upload:12345678-1111-2222-333-456789abcdef/12345678-1111-2222-333-456789abcdef \
  --configuration '{
      "auxiliaryApps": [
          "arn:aws:devicefarm:us-west-2:111122223333:upload:12345678-1111-2222-333-456789abcdef/12345678-1111-2222-333-456789abcde0",
          "arn:aws:devicefarm:us-west-2:111122223333:upload:12345678-1111-2222-333-456789abcdef/12345678-1111-2222-333-456789abcde1"
      ]
  }'
```

這會顯示如下所示的輸出：

```
{
    "remoteAccessSession": {
        "arn": "arn:aws:devicefarm:us-west-2:111122223333:session:abcdef123456-1234-5678-abcd-abcdef123456/abcdef123456-1234-5678-abcd-abcdef123456/00000",
        "name": "Google Pixel 8",
        "status": "PENDING",
        ...
}
```

現在，您可以選擇輪詢並等待工作階段準備就緒：

```
$ POLL_INTERVAL=3
TIMEOUT=600
DEADLINE=$(( $(date +%s) + TIMEOUT ))

while [[ "$(date +%s)" -lt "$DEADLINE" ]]; do

  STATUS=$(aws devicefarm get-remote-access-session \
    --arn "$DEVICE_FARM_SESSION_ARN" \
    --query 'remoteAccessSession.status' \
    --output text)

  case "$STATUS" in
    RUNNING)
      echo "Session is ready with status: $STATUS"
      break
      ;;
    STOPPING|COMPLETED)
      echo "Session ended early with status: $STATUS"
      exit 1
      ;;
  esac

done
```

------
#### [ Python ]

*注意：這些指示僅著重於建立遠端存取工作階段。如需如何上傳應用程式以在工作階段期間使用的指示，請參閱[自動化應用程式上傳。](api-ref.md#upload-example)*

此範例會先在 Device Farm 上尋找任何可用的 Google Pixel 裝置，然後使用它建立遠端存取工作階段，並等待工作階段執行。

```
import random
import time
import boto3

client = boto3.client("devicefarm", region_name="us-west-2")

# 1) Gather all matching devices via paginated ListDevices with filters
filters = [
    {"attribute": "MODEL",        "operator": "CONTAINS", "values": ["Pixel"]},
    {"attribute": "AVAILABILITY", "operator": "EQUALS",   "values": ["AVAILABLE"]},
]

matching_arns = []
next_token = None
while True:
    args = {"filters": filters}
    if next_token:
        args["nextToken"] = next_token
    page = client.list_devices(**args)
    for d in page.get("devices", []):
        matching_arns.append(d["arn"])
    next_token = page.get("nextToken")
    if not next_token:
        break

if not matching_arns:
    raise RuntimeError("No available Google Pixel device found.")

# Randomly select one device from the full matching set
device_arn = random.choice(matching_arns)
print("Selected device ARN:", device_arn)

# 2) Create remote access session and wait until RUNNING
resp = client.create_remote_access_session(
    projectArn="arn:aws:devicefarm:us-west-2:111122223333:project:12345678-1111-2222-333-456789abcdef",
    deviceArn=device_arn,
    appArn="arn:aws:devicefarm:us-west-2:111122223333:upload:12345678-1111-2222-333-456789abcdef/12345678-1111-2222-333-456789abcdef",  # optional
    configuration={
        "auxiliaryApps": [  # optional
            "arn:aws:devicefarm:us-west-2:111122223333:upload:12345678-1111-2222-333-456789abcdef/12345678-1111-2222-333-456789abcde0",
            "arn:aws:devicefarm:us-west-2:111122223333:upload:12345678-1111-2222-333-456789abcdef/12345678-1111-2222-333-456789abcde1",
        ]
    },
)

session_arn = resp["remoteAccessSession"]["arn"]
print(f"Created Remote Access Session: {session_arn}")

poll_interval = 3
timeout = 600
deadline = time.time() + timeout
terminal_states = ["STOPPING", "COMPLETED"]

while True:
    out = client.get_remote_access_session(arn=session_arn)
    status = out["remoteAccessSession"]["status"]
    print(f"Current status: {status}")

    if status == "RUNNING":
        print(f"Session is ready with status: {status}")
        break
    if status in terminal_states:
        raise RuntimeError(f"Session ended early with status: {status}")
    if time.time() >= deadline:
        raise RuntimeError("Timed out waiting for session to be ready.")
    time.sleep(poll_interval)
```

------
#### [ Java ]

*注意：這些指示僅著重於建立遠端存取工作階段。如需如何上傳應用程式以在工作階段期間使用的指示，請參閱[自動化應用程式上傳。](api-ref.md#upload-example)*

*注意：此範例使用適用於 Java v2 的 AWS 開發套件，並與 JDK 第 11 版及更高版本相容。*

此範例會先在 Device Farm 上尋找任何可用的 Google Pixel 裝置，然後使用它建立遠端存取工作階段，並等待工作階段執行。

```
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.concurrent.ThreadLocalRandom;
import software.amazon.awssdk.regions.Region;
import software.amazon.awssdk.services.devicefarm.DeviceFarmClient;
import software.amazon.awssdk.services.devicefarm.model.CreateRemoteAccessSessionConfiguration;
import software.amazon.awssdk.services.devicefarm.model.CreateRemoteAccessSessionRequest;
import software.amazon.awssdk.services.devicefarm.model.CreateRemoteAccessSessionResponse;
import software.amazon.awssdk.services.devicefarm.model.Device;
import software.amazon.awssdk.services.devicefarm.model.DeviceFilter;
import software.amazon.awssdk.services.devicefarm.model.DeviceFilterAttribute;
import software.amazon.awssdk.services.devicefarm.model.GetRemoteAccessSessionRequest;
import software.amazon.awssdk.services.devicefarm.model.GetRemoteAccessSessionResponse;
import software.amazon.awssdk.services.devicefarm.model.ListDevicesRequest;
import software.amazon.awssdk.services.devicefarm.model.ListDevicesResponse;
import software.amazon.awssdk.services.devicefarm.model.RuleOperator;

public class CreateRemoteAccessSession {
  public static void main(String[] args) throws Exception {
    DeviceFarmClient client = DeviceFarmClient.builder()
        .region(Region.US_WEST_2)
        .build();

    String projectArn = "arn:aws:devicefarm:us-west-2:111122223333:project:12345678-1111-2222-333-456789abcdef";
    String appArn     = "arn:aws:devicefarm:us-west-2:111122223333:upload:12345678-1111-2222-333-456789abcdef/12345678-1111-2222-333-456789abcdef";
    String aux1       = "arn:aws:devicefarm:us-west-2:111122223333:upload:12345678-1111-2222-333-456789abcdef/12345678-1111-2222-333-456789abcde0";
    String aux2       = "arn:aws:devicefarm:us-west-2:111122223333:upload:12345678-1111-2222-333-456789abcdef/12345678-1111-2222-333-456789abcde1";

    // 1) Gather all matching devices via paginated ListDevices with filters
    List<DeviceFilter> filters = Arrays.asList(
        DeviceFilter.builder()
            .attribute(DeviceFilterAttribute.MODEL)
            .operator(RuleOperator.CONTAINS)
            .values("Pixel")
            .build(),
        DeviceFilter.builder()
            .attribute(DeviceFilterAttribute.AVAILABILITY)
            .operator(RuleOperator.EQUALS)
            .values("AVAILABLE")
            .build()
    );

    List<String> matchingDeviceArns = new ArrayList<>();
    String next = null;
    do {
      ListDevicesResponse page = client.listDevices(
          ListDevicesRequest.builder().filters(filters).nextToken(next).build());
      for (Device d : page.devices()) {
        matchingDeviceArns.add(d.arn());
      }
      next = page.nextToken();
    } while (next != null);

    if (matchingDeviceArns.isEmpty()) {
      throw new RuntimeException("No available Google Pixel device found.");
    }

    // Randomly select one device from the full matching set
    String deviceArn = matchingDeviceArns.get(
        ThreadLocalRandom.current().nextInt(matchingDeviceArns.size()));
    System.out.println("Selected device ARN: " + deviceArn);

    // 2) Create Remote Access session and wait until it is RUNNING
    CreateRemoteAccessSessionConfiguration cfg = CreateRemoteAccessSessionConfiguration.builder()
        .auxiliaryApps(Arrays.asList(aux1, aux2))
        .build();

    CreateRemoteAccessSessionResponse res = client.createRemoteAccessSession(
        CreateRemoteAccessSessionRequest.builder()
            .projectArn(projectArn)
            .deviceArn(deviceArn)
            .appArn(appArn)       // optional
            .configuration(cfg)   // optional
            .build());

    String sessionArn = res.remoteAccessSession().arn();
    System.out.println("Created Remote Access Session: " + sessionArn);

    int pollIntervalMs = 3000;
    long timeoutMs = 600_000L;
    long deadline = System.currentTimeMillis() + timeoutMs;

    while (true) {
      GetRemoteAccessSessionResponse get = client.getRemoteAccessSession(
          GetRemoteAccessSessionRequest.builder().arn(sessionArn).build());
      String status = get.remoteAccessSession().statusAsString();
      System.out.println("Current status: " + status);

      if ("RUNNING".equals(status)) {
        System.out.println("Session is ready with status: " + status);
        break;
      }
      if ("STOPPING".equals(status) || "COMPLETED".equals(status)) {
        throw new RuntimeException("Session ended early with status: " + status);
      }
      if (System.currentTimeMillis() >= deadline) {
        throw new RuntimeException("Timed out waiting for session to be ready.");
      }
      Thread.sleep(pollIntervalMs);
    }
  }
}
```

------
#### [ JavaScript ]

*注意：這些指示僅著重於建立遠端存取工作階段。如需如何上傳應用程式以在工作階段期間使用的指示，請參閱[自動化應用程式上傳。](api-ref.md#upload-example)*

*注意：此範例使用適用於 JavaScript v3 的 AWS 開發套件。*

此範例會先在 Device Farm 上尋找任何可用的 Google Pixel 裝置，然後使用它建立遠端存取工作階段，並等待工作階段執行。

```
import {
  DeviceFarmClient,
  ListDevicesCommand,
  CreateRemoteAccessSessionCommand,
  GetRemoteAccessSessionCommand,
} from "@aws-sdk/client-device-farm";

const client = new DeviceFarmClient({ region: "us-west-2" });

// 1) Gather all matching devices via paginated ListDevices with filters
const filters = [
  { attribute: "MODEL",        operator: "CONTAINS", values: ["Pixel"] },
  { attribute: "AVAILABILITY", operator: "EQUALS",   values: ["AVAILABLE"] },
];

let nextToken;
const matching = [];

while (true) {
  const page = await client.send(new ListDevicesCommand({ filters, nextToken }));
  for (const d of page.devices ?? []) {
    matching.push(d.arn);
  }
  nextToken = page.nextToken;
  if (!nextToken) break;
}

if (matching.length === 0) {
  throw new Error("No available Google Pixel device found.");
}

// Randomly select one device from the full matching set
const deviceArn = matching[Math.floor(Math.random() * matching.length)];
console.log("Selected device ARN:", deviceArn);

// 2) Create remote access session and wait until RUNNING
const out = await client.send(new CreateRemoteAccessSessionCommand({
  projectArn: "arn:aws:devicefarm:us-west-2:111122223333:project:12345678-1111-2222-333-456789abcdef",
  deviceArn,
  appArn: "arn:aws:devicefarm:us-west-2:111122223333:upload:12345678-1111-2222-333-456789abcdef/12345678-1111-2222-333-456789abcdef", // optional
  configuration: {
    auxiliaryApps: [ // optional
      "arn:aws:devicefarm:us-west-2:111122223333:upload:12345678-1111-2222-333-456789abcdef/12345678-1111-2222-333-456789abcde0",
      "arn:aws:devicefarm:us-west-2:111122223333:upload:12345678-1111-2222-333-456789abcdef/12345678-1111-2222-333-456789abcde1",
    ],
  },
}));

const sessionArn = out.remoteAccessSession?.arn;
console.log("Created Remote Access Session:", sessionArn);

const pollIntervalMs = 3000;
const timeoutMs = 600000;
const deadline = Date.now() + timeoutMs;

while (true) {
  const get = await client.send(new GetRemoteAccessSessionCommand({ arn: sessionArn }));
  const status = get.remoteAccessSession?.status;
  console.log("Current status:", status);

  if (status === "RUNNING") {
    console.log("Session is ready with status:", status);
    break;
  }
  if (status === "STOPPING" || status === "COMPLETED") {
    throw new Error(`Session ended early with status: ${status}`);
  }
  if (Date.now() >= deadline) {
    throw new Error("Timed out waiting for session to be ready.");
  }
  await new Promise((r) => setTimeout(r, pollIntervalMs));
}
```

------
#### [ C\$1 ]

*注意：這些指示僅著重於建立遠端存取工作階段。如需如何上傳應用程式以在工作階段期間使用的指示，請參閱[自動化應用程式上傳。](api-ref.md#upload-example)*

此範例會先在 Device Farm 上尋找任何可用的 Google Pixel 裝置，然後使用它建立遠端存取工作階段，並等待工作階段執行。

```
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using Amazon;
using Amazon.DeviceFarm;
using Amazon.DeviceFarm.Model;

class Program
{
    static async Task Main()
    {
        var client = new AmazonDeviceFarmClient(RegionEndpoint.USWest2);

        // 1) Gather all matching devices via paginated ListDevices with filters
        var filters = new List<DeviceFilter>
        {
            new DeviceFilter { Attribute = DeviceAttribute.MODEL,        Operator = RuleOperator.CONTAINS, Values = new List<string>{ "Pixel" } },
            new DeviceFilter { Attribute = DeviceAttribute.AVAILABILITY, Operator = RuleOperator.EQUALS,   Values = new List<string>{ "AVAILABLE" } },
        };

        var matchingArns = new List<string>();
        string nextToken = null;

        do
        {
            var list = await client.ListDevicesAsync(new ListDevicesRequest
            {
                Filters = filters,
                NextToken = nextToken
            });

            foreach (var d in list.Devices)
                matchingArns.Add(d.Arn);

            nextToken = list.NextToken;
        }
        while (nextToken != null);

        if (matchingArns.Count == 0)
            throw new Exception("No available Google Pixel device found.");

        // Randomly select one device from the full matching set
        var rnd = new Random();
        var deviceArn = matchingArns[rnd.Next(matchingArns.Count)];
        Console.WriteLine($"Selected device ARN: {deviceArn}");

        // 2) Create remote access session and wait until RUNNING
        var request = new CreateRemoteAccessSessionRequest
        {
            ProjectArn = "arn:aws:devicefarm:us-west-2:111122223333:project:12345678-1111-2222-333-456789abcdef",
            DeviceArn  = deviceArn,
            AppArn     = "arn:aws:devicefarm:us-west-2:111122223333:upload:12345678-1111-2222-333-456789abcdef/12345678-1111-2222-333-456789abcdef", // optional
            Configuration = new CreateRemoteAccessSessionConfiguration
            {
                AuxiliaryApps = new List<string>
                {
                    "arn:aws:devicefarm:us-west-2:111122223333:upload:12345678-1111-2222-333-456789abcdef/12345678-1111-2222-333-456789abcde0",
                    "arn:aws:devicefarm:us-west-2:111122223333:upload:12345678-1111-2222-333-456789abcdef/12345678-1111-2222-333-456789abcde1"
                }
            }
        };

        request.Configuration.AuxiliaryApps.RemoveAll(string.IsNullOrWhiteSpace);

        var response = await client.CreateRemoteAccessSessionAsync(request);
        var sessionArn = response.RemoteAccessSession.Arn;
        Console.WriteLine($"Created Remote Access Session: {sessionArn}");

        var pollIntervalMs = 3000;
        var timeoutMs = 600000;
        var deadline = DateTime.UtcNow.AddMilliseconds(timeoutMs);

        while (true)
        {
            var get = await client.GetRemoteAccessSessionAsync(new GetRemoteAccessSessionRequest { Arn = sessionArn });
            var status = get.RemoteAccessSession.Status.Value;
            Console.WriteLine($"Current status: {status}");

            if (status == "RUNNING")
            {
                Console.WriteLine($"Session is ready with status: {status}");
                break;
            }
            if (status == "STOPPING" || status == "COMPLETED")
            {
                throw new Exception($"Session ended early with status: {status}");
            }
            if (DateTime.UtcNow >= deadline)
            {
                throw new TimeoutException("Timed out waiting for session to be ready.");
            }

            await Task.Delay(pollIntervalMs);
        }
    }
}
```

------
#### [ Ruby ]

*注意：這些指示僅著重於建立遠端存取工作階段。如需如何上傳應用程式以在工作階段期間使用的指示，請參閱[自動化應用程式上傳。](api-ref.md#upload-example)*

此範例會先在 Device Farm 上尋找任何可用的 Google Pixel 裝置，然後使用它建立遠端存取工作階段，並等待工作階段執行。

```
require 'aws-sdk-devicefarm'

client = Aws::DeviceFarm::Client.new(region: 'us-west-2')

# 1) Gather all matching devices via paginated ListDevices with filters
filters = [
  { attribute: 'MODEL',        operator: 'CONTAINS', values: ['Pixel'] },
  { attribute: 'AVAILABILITY', operator: 'EQUALS',   values: ['AVAILABLE'] },
]

matching_arns = []
next_token = nil
loop do
  resp = client.list_devices(filters: filters, next_token: next_token)
  resp.devices&.each { |d| matching_arns << d.arn }
  next_token = resp.next_token
  break unless next_token
end

abort "No available Google Pixel device found." if matching_arns.empty?

# Randomly select one device from the full matching set
device_arn = matching_arns.sample
puts "Selected device ARN: #{device_arn}"

# 2) Create remote access session and wait until RUNNING
resp = client.create_remote_access_session(
  project_arn: "arn:aws:devicefarm:us-west-2:111122223333:project:12345678-1111-2222-333-456789abcdef",
  device_arn:  device_arn,
  app_arn:     "arn:aws:devicefarm:us-west-2:111122223333:upload:12345678-1111-2222-333-456789abcdef/12345678-1111-2222-333-456789abcdef", # optional
  configuration: {
    auxiliary_apps: [ # optional
      "arn:aws:devicefarm:us-west-2:111122223333:upload:12345678-1111-2222-333-456789abcdef/12345678-1111-2222-333-456789abcde0",
      "arn:aws:devicefarm:us-west-2:111122223333:upload:12345678-1111-2222-333-456789abcdef/12345678-1111-2222-333-456789abcde1"
    ].compact
  }
)

session_arn = resp.remote_access_session.arn
puts "Created Remote Access Session: #{session_arn}"

poll_interval = 3
timeout = 600
deadline = Time.now + timeout
terminal = %w[STOPPING COMPLETED]

loop do
  get = client.get_remote_access_session(arn: session_arn)
  status = get.remote_access_session.status
  puts "Current status: #{status}"

  if status == 'RUNNING'
    puts "Session is ready with status: #{status}"
    break
  end

  abort "Session ended early with status: #{status}" if terminal.include?(status)
  abort "Timed out waiting for session to be ready." if Time.now >= deadline
  sleep poll_interval
end
```

------

## 後續步驟
<a name="how-to-create-session-next-steps"></a>

Device Farm 會在請求的裝置和基礎設施可用時立即啟動工作階段，通常在幾分鐘內。**裝置請求**對話方塊會出現，直到工作階段啟動為止。若要取消工作階段請求，請選擇 **Cancel request (取消請求)**。

如果選取的裝置無法使用或忙碌，工作階段狀態會顯示為**待定裝置**，表示您可能需要等待一段時間，裝置才能進行測試。

如果您的帳戶已達到公有計量或未計量裝置的並行限制，工作階段狀態會顯示為**待定並行**。對於未計量的裝置插槽，您可以透過[購買更多裝置插槽](how-to-purchase-device-slots.md)來增加並行。對於按pay-as-you-go計費的裝置，請透過支援票證聯絡 AWS，以請求[提高服務配額](limits.md)。

當工作階段設定開始時，它會先顯示**進行中**的狀態，然後在本機 Web 瀏覽器嘗試開啟與裝置的遠端連線時顯示**連線**狀態。

在工作階段開始之後，如果您應該關閉瀏覽器或瀏覽器標籤，而無需停止工作階段，或如果失去瀏覽器與網際網路之間的連線，則工作階段仍有五分鐘保持作用中狀態。之後，Device Farm 會結束工作階段。您的帳戶需要為閒置時間付費。

工作階段開始後，您可以在 Web 瀏覽器中與裝置互動，或使用 [Appium](appium-endpoint.md) 測試裝置。

# 在 AWS Device Farm 中使用遠端存取工作階段
<a name="how-to-use-session"></a>

如需透過遠端存取工作階段執行 Android 和 iOS 應用程式互動式測試的詳細資訊，請參閱[工作階段](sessions.md)。
+ [先決條件](#how-to-use-session-prerequisites)
+ [在 Device Farm 主控台中使用工作階段](#how-to-use-session-console)
+ [後續步驟](#how-to-use-session-next-steps)
+ [秘訣和技巧](#how-to-use-session-tips)

## 先決條件
<a name="how-to-use-session-prerequisites"></a>
+ 建立工作階段。請遵循[建立工作階段](how-to-create-session.md)中的指示，然後返回此頁面。

## 在 Device Farm 主控台中使用工作階段
<a name="how-to-use-session-console"></a>

一旦您針對遠端存取工作階段請求的裝置可供使用，主控台就會顯示裝置畫面。工作階段的長度上限為 150 分鐘。工作階段中剩餘的時間會出現在裝置名稱附近的**左時間**欄位中。

### 安裝應用程式
<a name="how-to-use-session-install-app"></a>

若要在工作階段裝置上安裝應用程式，請在**安裝應用程式**中選取**選擇檔案**，然後選擇您要安裝的 .apk 檔案 (Android) 或 .ipa 檔案 (iOS)。您在遠端存取工作階段中執行的應用程式不需進行任何測試檢測或佈建作業。

**注意**  
當您上傳應用程式時，有時在應用程式可供使用前會發生延遲。系統會顯示確認訊息，讓您知道應用程式是否已成功安裝。

### 控制裝置
<a name="how-to-use-session-control-device"></a>

如同操作實際的實體裝置一般，您可使用滑鼠或相容裝置進行觸控，也可使用裝置的螢幕鍵盤，藉此與主控台中顯示的裝置互動。若為 Android 裝置，**View controls (檢視控制)** 中有按鈕，其功能類似 Android 裝置上的 **Home (首頁)** 和 **Back (返回)** 按鈕。若為 iOS 裝置，有一個 **Home (首頁)** 按鈕，其功能類似 iOS 裝置上的首頁按鈕。您也可以選擇**最近**應用程式，在裝置上執行的應用程式之間切換。

### 在縱向和橫向模式之間切換
<a name="how-to-use-session-switch-between-portrait-landscape-mode"></a>

您也可以為您正在使用的裝置切換縱向 （垂直） 和橫向 （水平） 模式。

## 後續步驟
<a name="how-to-use-session-next-steps"></a>

Device Farm 會繼續工作階段，直到您手動停止或達到 150 分鐘的時間限制為止。若要結束工作階段，請選擇**停止工作階段**。當工作階段停止後，您即可存取擷取的影片或產生的日誌。如需詳細資訊，請參閱[擷取工作階段結果](how-to-access-session-results.md)。

## 秘訣和技巧
<a name="how-to-use-session-tips"></a>

在某些 AWS 區域中，您可能遇到遠端存取工作階段的效能問題。部分原因是某些區域中發生延遲所致。如果您遇到效能問題，請等待遠端存取工作階段追上進度，再重新與應用程式互動。

# 在 AWS Device Farm 中擷取遠端存取工作階段的結果
<a name="how-to-access-session-results"></a>

如需工作階段的詳細資訊，請參閱 [工作階段](sessions.md)。
+ [先決條件](#how-to-access-session-results-prerequisites)
+ [檢視工作階段詳細資訊](#how-to-view-session-details)
+ [下載工作階段影片或日誌](#how-to-access-session-files)

## 先決條件
<a name="how-to-access-session-results-prerequisites"></a>
+ 完成工作階段。請遵循[在 AWS Device Farm 中使用遠端存取工作階段使用工作階段](how-to-use-session.md)中的指示，然後返回此頁面。

## 檢視工作階段詳細資訊
<a name="how-to-view-session-details"></a>

當遠端存取工作階段結束時，Device Farm 主控台會顯示包含工作階段期間活動詳細資訊的資料表。如需詳細資訊，請參閱[分析日誌資訊](how-to-use-reports.md#how-to-use-reports-console-log)。

若之後要回到工作階段的詳細資訊：

1. 在 Device Farm 導覽面板上，選擇**行動裝置測試**，然後選擇**專案**。

1. 選擇包含工作階段的專案。

1. 選擇**遠端存取**，然後從清單中選擇您要檢閱的工作階段。

## 下載工作階段影片或日誌
<a name="how-to-access-session-files"></a>

當遠端存取工作階段結束時，Device Farm 主控台會提供工作階段和活動日誌的影片擷取存取權。在工作階段結果中，選擇 **Files (檔案)** 標籤以取得工作階段影片和日誌的連結。您可以在瀏覽器中檢視這些檔案或將其儲存在本機。