Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

System-wide network capture for Appium #2957

Merged
merged 3 commits into from
Oct 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
151 changes: 90 additions & 61 deletions docs/mobile-apps/features/network-capture.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,39 @@
For Android devices, a minor modification in the manifest is necessary, but all required changes will be handled by us. This means no
complete resigning or additional instrumentation is needed, ensuring a smooth feature enablement.

## Using system-wide Network Capture

Check warning on line 43 in docs/mobile-apps/features/network-capture.md

View workflow job for this annotation

GitHub Actions / vale

[vale] docs/mobile-apps/features/network-capture.md#L43

[sauce.Headings] 'Using system-wide Network Capture' should use title case capitalization.
Raw output
{"message": "[sauce.Headings] 'Using system-wide Network Capture' should use title case capitalization.", "location": {"path": "docs/mobile-apps/features/network-capture.md", "range": {"start": {"line": 43, "column": 4}}}, "severity": "WARNING"}

1. In Sauce Labs, from the left navigation, click **App Management**.
<img src={useBaseUrl('img/mobile-apps/app-management.png')} alt="App Management" width="750"/>
2. Upload your mobile app to Sauce Labs [through our UI](/mobile-apps/app-storage/#uploading-apps-via-ui) or [our REST API](/mobile-apps/app-storage/#uploading-apps-via-rest-api).
<img src={useBaseUrl('img/mobile-apps/app-logs-8.png')} alt="App Logs" width="750"/>
3. After you’ve uploaded your app, locate it in the table and select **Settings** from the corresponding row.
<img src={useBaseUrl('img/mobile-apps/app-management-select-settings.png')} alt="Select Settings" width="750"/>
4. Under **Real Device Settings** enable **Network Capture**.
<img src={useBaseUrl('img/mobile-apps/network-capture-app-settings.png')} alt="Network Capture App Setting" width="750"/>

Now you can start your live or automated testing session. Your network logs will be captured and displayed in the test results page as well as during a Live Testing session with the Developer Options window.

:::note Android Only

For Android applications, a minor modification in the manifest is necessary to disable SSL pinning and accept our own certificate by your application.
In addition, we require the debug version of the application. If your application includes SecureSDK, please ensure the repackaging prevention feature is disabled.

Check notice on line 59 in docs/mobile-apps/features/network-capture.md

View workflow job for this annotation

GitHub Actions / vale

[vale] docs/mobile-apps/features/network-capture.md#L59

[sauce.WordsToAvoid] Avoid usage of 'please'.
Raw output
{"message": "[sauce.WordsToAvoid] Avoid usage of 'please'.", "location": {"path": "docs/mobile-apps/features/network-capture.md", "range": {"start": {"line": 59, "column": 103}}}, "severity": "INFO"}

For tests that run on Android devices, enabling network capture may cause issues in third-party SDKs due to SSL pinning.

Check warning on line 61 in docs/mobile-apps/features/network-capture.md

View workflow job for this annotation

GitHub Actions / vale

[vale] docs/mobile-apps/features/network-capture.md#L61

[sauce.EOLWhitespace] Remove whitespace characters from the end of the line.
Raw output
{"message": "[sauce.EOLWhitespace] Remove whitespace characters from the end of the line.", "location": {"path": "docs/mobile-apps/features/network-capture.md", "range": {"start": {"line": 61, "column": 121}}}, "severity": "WARNING"}
:::

### Automated Testing

The [App Settings](/mobile-apps/live-testing/live-mobile-app-testing/#app-settings) act as default configurations, but can be overridden by the capabilities specified in your test script.

Check warning on line 66 in docs/mobile-apps/features/network-capture.md

View workflow job for this annotation

GitHub Actions / vale

[vale] docs/mobile-apps/features/network-capture.md#L66

[sauce.EOLWhitespace] Remove whitespace characters from the end of the line.
Raw output
{"message": "[sauce.EOLWhitespace] Remove whitespace characters from the end of the line.", "location": {"path": "docs/mobile-apps/features/network-capture.md", "range": {"start": {"line": 66, "column": 188}}}, "severity": "WARNING"}
To control whether network capture is enabled or disabled, add the **networkCapture** capability to your test script.

- [Sauce-specific Appium capability networkCapture](/dev/test-configuration-options/#networkcapture)

:::note Coming soon

System-wide network capture for Espresso and XCUITest will be available soon.

:::

### Accessing Network Traffic in real-time (Live Testing)

Expand All @@ -55,21 +88,71 @@

<img src={useBaseUrl('img/mobile-apps/network-capture-2.png')} alt="Start capture" width="700"/>

5. Inspect network logs as they arrive.
5. Inspect network logs in the [Sauce Labs Network Viewer](/mobile-apps/features/network-capture/#sauce-labs-network-viewer) as they arrive.

<img src={useBaseUrl('img/mobile-apps/network-capture-3.png')} alt="Inspect network logs" width="700"/>

### Limitations
:::note Limitations

- iOS network capture is supported on iOS/iPadOS 14.0 and above.
- Android network capture is supported on Android 10 and above.
- Only HTTP/HTTPS network traffic is captured.
- Android Emulators are not supported.
- iOS Simulators are not supported.

:::

## Accessing HAR Files (Live and Automated Testing)

To download HAR files from Sauce Labs:

1. Navigate to **Test Results**.
2. Select the applicable test.
3. Click the **Network** tab on the right panel to preview all captured network requests.

You can also download a HAR file programmatically using the following API request:

<Tabs
groupId="dc-url"
defaultValue="us"
values={[
{label: 'United States', value: 'us'},
{label: 'Europe', value: 'eu'},
]}>

<TabItem value="us">

```jsx title="Sample Request"
curl -u "$SAUCE_USERNAME:$SAUCE_ACCESS_KEY" --location \
--request GET 'https://api.us-west-1.saucelabs.com/v1/rdc/jobs/{JOB_ID}/network.har'
```

</TabItem>

<TabItem value="eu">

```jsx title="Sample Request"
curl -u "$SAUCE_USERNAME:$SAUCE_ACCESS_KEY" --location \
--request GET 'https://api.eu-central-1.saucelabs.com/v1/rdc/jobs/{JOB_ID}/network.har'
```

</TabItem>
</Tabs>

### Sauce Labs Network Viewer
The [Sauce Labs Network Viewer](https://github.com/saucelabs/network-viewer) is a visualization tool for HAR files that presents requests
in a table view with a range of advanced filtering options.

#### Pause / Resume
<p><small><span className="sauceGreen">Live Testing Only</span></small></p>
Pause and resume the display of new network traffic without affecting the **network.har** test asset.
The final **network.har** file contains all network traffic from the moment the network capture was initiated and will be available after the
session is closed.
<img src={useBaseUrl('img/mobile-apps/network-capture-pause-resume.png')} alt="Inspect network logs" width="700"/>

#### Reset
<p><small><span className="sauceGreen">Live Testing Only</span></small></p>
Clear the current state of network logs from the inspector. This does not affect the final **network.har** test asset.
<img src={useBaseUrl('img/mobile-apps/network-capture-reset.png')} alt="Inspect network logs" width="700"/>

Expand Down Expand Up @@ -120,81 +203,27 @@
Page Load, DOMContentLoaded, and Finished time.
<img src={useBaseUrl('img/mobile-apps/network-capture-stats-row.png')} alt="Inspect network logs" width="700"/>

### Limitations
:::note Limitations

- iOS network capture is supported on iOS/iPadOS 14.0 and above.
- Android network capture is supported on Android 10 and above.
- Only HTTP/HTTPS network traffic is captured.

:::

## Accessing HAR Files (Live and Automated Testing)

To download HAR files from Sauce Labs:

1. Navigate to **Test Results**.
2. Select the applicable test.
3. Click the **Network** tab on the right panel to preview all captured network requests.

You can also download a HAR file programmatically using the following API request:

<Tabs
groupId="dc-url"
defaultValue="us"
values={[
{label: 'United States', value: 'us'},
{label: 'Europe', value: 'eu'},
]}>

<TabItem value="us">

```jsx title="Sample Request"
curl -u "$SAUCE_USERNAME:$SAUCE_ACCESS_KEY" --location \
--request GET 'https://api.us-west-1.saucelabs.com/v1/rdc/jobs/{JOB_ID}/network.har'
```

</TabItem>

<TabItem value="eu">

```jsx title="Sample Request"
curl -u "$SAUCE_USERNAME:$SAUCE_ACCESS_KEY" --location \
--request GET 'https://api.eu-central-1.saucelabs.com/v1/rdc/jobs/{JOB_ID}/network.har'
```

</TabItem>
</Tabs>

## Instrumented Network Traffic Capture
<p><small><span className="sauceGreen">Espresso and XCUITest Only</span></small></p>

:::note Android Only

For Android applications, a minor modification in the manifest is necessary to disable SSL pinning and accept our own certificate by your application.
In addition, we require the debug version of the application. If your application includes SecureSDK, please ensure the repackaging prevention feature is disabled.

:::
To use network capture for automated Espresso and XCUITest tests, instrumentation must be enabled.

To enable network traffic capturing in your tests:

1. On Sauce Labs, click **Live** > **Mobile App**.
2. Upload your mobile app to Sauce Labs [through our UI](/mobile-apps/app-storage/#uploading-apps-via-ui) or [our REST API](/mobile-apps/app-storage/#uploading-apps-via-rest-api).
3. After you’ve uploaded your app, return to the **Live** > **Mobile App** page, hover your mouse over your app, then select **Settings**.<br/><img src={useBaseUrl('img/mobile-apps/networkcapturescr.png')} alt="Mobile app settings navigation" width="600"/>
4. Under **Default Settings**, toggle Instrumentation and Network Capture to enable the feature.<br/><img src={useBaseUrl('img/mobile-apps/networkcapturescr2.png')} alt="Mobile app settings navigation" width="800"/>
5. For Automated Testing only: add the networkCapture capability to your test script. Click the link below corresponding to your framework:

- [Appium](/dev/test-configuration-options/#networkcapture)
- [Espresso via saucectl](/mobile-apps/automated-testing/espresso-xcuitest/espresso/#networkcapture)
- [XCUITest via saucectl](/mobile-apps/automated-testing/espresso-xcuitest/xcuitest/#networkcapture)
5. Alternatively, the **networkCapture** capability can be added to your test script:
- [Espresso via saucectl](/mobile-apps/automated-testing/espresso-xcuitest/espresso/#networkcapture)
- [XCUITest via saucectl](/mobile-apps/automated-testing/espresso-xcuitest/xcuitest/#networkcapture)

:::note Coming soon

System-wide network capture for Automated Testing will be available soon.
System-wide network capture for Espresso and XCUITest will be available soon.

:::

Now you can start your live or automated testing session. Your network logs will be captured and displayed in the test results page as well as during a Live Testing session with the Developer Options window.

### Limitations

<!-- prettier-ignore -->
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.