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

Sauce Visual Espresso docs #2988

Merged
merged 16 commits into from
Dec 10, 2024
246 changes: 246 additions & 0 deletions docs/visual-testing/integrations/espresso.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,246 @@
---
sidebar_label: Espresso
---

import ClippingDescription from '../_partials/_clipping-description.md';

# Espresso Integration

## Introduction

This guide requires an existing Android JUnit setup.

Check warning on line 11 in docs/visual-testing/integrations/espresso.md

View workflow job for this annotation

GitHub Actions / vale

[vale] docs/visual-testing/integrations/espresso.md#L11

[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/visual-testing/integrations/espresso.md", "range": {"start": {"line": 11, "column": 53}}}, "severity": "WARNING"}

You can alternatively take a look to our [example repository](#examples).

Sauce Visual Espresso plugin provides a library exposing a `VisualClient` object that provides the method

Check warning on line 15 in docs/visual-testing/integrations/espresso.md

View workflow job for this annotation

GitHub Actions / vale

[vale] docs/visual-testing/integrations/espresso.md#L15

[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/visual-testing/integrations/espresso.md", "range": {"start": {"line": 15, "column": 106}}}, "severity": "WARNING"}
kb-kerem marked this conversation as resolved.
Show resolved Hide resolved
`sauceVisualCheck()` to take a screenshot and send it to Sauce Visual for comparison.

## Quickstart

### Step 1: Add Sauce Visual dependency

Add [Sauce Visual](https://central.sonatype.com/artifact/com.saucelabs.visual/visual-espresso) dependency to your build.gradle

```groovy reference
https://github.com/saucelabs/visual-examples/blob/main/espresso/app/build.gradle#L106
```

_Note: You can find the latest versions available [here](https://central.sonatype.com/artifact/com.saucelabs.visual/visual-espresso)._

Check warning on line 28 in docs/visual-testing/integrations/espresso.md

View workflow job for this annotation

GitHub Actions / vale

[vale] docs/visual-testing/integrations/espresso.md#L28

[sauce.MeaningfulLinkWords] Improve SEO and accessibility by rewriting 'here' in the link text.
Raw output
{"message": "[sauce.MeaningfulLinkWords] Improve SEO and accessibility by rewriting 'here' in the link text.", "location": {"path": "docs/visual-testing/integrations/espresso.md", "range": {"start": {"line": 28, "column": 52}}}, "severity": "WARNING"}

### Step 2: Configure Visual Testing integration

Declare a VisualClient instance as class variable

```java
import com.saucelabs.visual.VisualClient;

static VisualClient visual = VisualClient.builder(sauceUsername, sauceAccessKey)
.buildName("Sauce Demo Test")
.build();
```

To enhance efficiency in managing tests, it's important to provide a specific test name and suite name for each test. This practice allows Sauce Visual to effectively organize snapshots into coherent groups. As a result, it simplifies the review process, saving time and effort in navigating through test results and understanding the context of each snapshot.

Moreover, our Espresso binding offers an automated solution to this process. By integrating the following code snippet into your tests, the Java Binding can automatically assign appropriate test names and suite names, streamlining your testing workflow.

```java
import com.saucelabs.visual.junit.TestMetaInfoRule;

import org.junit.Rule;

public class MyJunitTestClass {

Check warning on line 52 in docs/visual-testing/integrations/espresso.md

View workflow job for this annotation

GitHub Actions / vale

[vale] docs/visual-testing/integrations/espresso.md#L52

[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/visual-testing/integrations/espresso.md", "range": {"start": {"line": 52, "column": 1}}}, "severity": "WARNING"}
@Rule
public TestMetaInfoRule testMetaInfoRule = new TestMetaInfoRule();
}
```

Don't forget to finish the build

```java
import org.junit.AfterClass;

@AfterClass
public static void tearDown() {
if (visual != null) {
visual.finish();
}
}
```

### Step 3: Add visual tests in your tests

Check warning on line 71 in docs/visual-testing/integrations/espresso.md

View workflow job for this annotation

GitHub Actions / vale

[vale] docs/visual-testing/integrations/espresso.md#L71

[sauce.Headings] 'Step 3: Add visual tests in your tests' should use title case capitalization.
Raw output
{"message": "[sauce.Headings] 'Step 3: Add visual tests in your tests' should use title case capitalization.", "location": {"path": "docs/visual-testing/integrations/espresso.md", "range": {"start": {"line": 71, "column": 5}}}, "severity": "WARNING"}

Add a check to one of your tests:


```java
import org.junit.Test;

@Test
void checkAppCatalog() {

Check warning on line 81 in docs/visual-testing/integrations/espresso.md

View workflow job for this annotation

GitHub Actions / vale

[vale] docs/visual-testing/integrations/espresso.md#L81

[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/visual-testing/integrations/espresso.md", "range": {"start": {"line": 81, "column": 1}}}, "severity": "WARNING"}
visual.sauceVisualCheck("Before Login");
kb-kerem marked this conversation as resolved.
Show resolved Hide resolved
}
```

### Step 4: Configure your Sauce Labs credentials

Check warning on line 86 in docs/visual-testing/integrations/espresso.md

View workflow job for this annotation

GitHub Actions / vale

[vale] docs/visual-testing/integrations/espresso.md#L86

[sauce.Headings] 'Step 4: Configure your Sauce Labs credentials' should use title case capitalization.
Raw output
{"message": "[sauce.Headings] 'Step 4: Configure your Sauce Labs credentials' should use title case capitalization.", "location": {"path": "docs/visual-testing/integrations/espresso.md", "range": {"start": {"line": 86, "column": 5}}}, "severity": "WARNING"}

Sauce Visual Espresso expects Sauce Labs username and access key to be passed when initiating the client.

Check warning on line 88 in docs/visual-testing/integrations/espresso.md

View workflow job for this annotation

GitHub Actions / vale

[vale] docs/visual-testing/integrations/espresso.md#L88

[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/visual-testing/integrations/espresso.md", "range": {"start": {"line": 88, "column": 106}}}, "severity": "WARNING"}
It's recommended to define and pass your Sauce Labs credentials to `VisualClient` as custom `BuildConfig` fields.

Check warning on line 89 in docs/visual-testing/integrations/espresso.md

View workflow job for this annotation

GitHub Actions / vale

[vale] docs/visual-testing/integrations/espresso.md#L89

[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/visual-testing/integrations/espresso.md", "range": {"start": {"line": 89, "column": 114}}}, "severity": "WARNING"}

```groovy
android {
buildConfigField "String", "SAUCE_USERNAME", "YOUR_SAUCE_USERNAME"
buildConfigField "String", "SAUCE_ACCESS_KEY", "YOUR_SAUCE_ACCESS_KEY"
}
```

```java
import com.saucelabs.visual.VisualClient;

static VisualClient visualClient = VisualClient.builder(
BuildConfig.SAUCE_USERNAME,
BuildConfig.SAUCE_ACCESS_KEY)
.buildName("Espresso Basic Sample")
.build();
```

Username and Access Key can be retrieved from https://app.saucelabs.com/user-settings.

Check warning on line 108 in docs/visual-testing/integrations/espresso.md

View workflow job for this annotation

GitHub Actions / vale

[vale] docs/visual-testing/integrations/espresso.md#L108

[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/visual-testing/integrations/espresso.md", "range": {"start": {"line": 108, "column": 87}}}, "severity": "WARNING"}

### Step 5: Run the test

Upon executing your tests for the first time under this step, a visual baseline is automatically created in our system. This baseline serves as the standard for all subsequent WebDriver tests. As new tests are run, they are compared to this original baseline, with any deviations highlighted to signal visual changes. These comparisons are integral for detecting any unintended visual modifications early in your development cycle. All test builds, including the initial baseline and subsequent runs, can be monitored and managed through the Sauce Labs platform at [Sauce Visual Builds](https://app.saucelabs.com/visual/builds).
kb-kerem marked this conversation as resolved.
Show resolved Hide resolved

Remember, the baseline is established during the initial run, and any subsequent visual differences detected will be marked for review.

## Advanced usage

Check warning on line 116 in docs/visual-testing/integrations/espresso.md

View workflow job for this annotation

GitHub Actions / vale

[vale] docs/visual-testing/integrations/espresso.md#L116

[sauce.Headings] 'Advanced usage' should use title case capitalization.
Raw output
{"message": "[sauce.Headings] 'Advanced usage' should use title case capitalization.", "location": {"path": "docs/visual-testing/integrations/espresso.md", "range": {"start": {"line": 116, "column": 4}}}, "severity": "WARNING"}

### Customizing Your Build Lifecycle

Following builder methods are available for `VisualClient` if you'd like to manage your build lifecyle externally.

- `buildId(String buildId)`: For advanced users, a user-supplied Sauce Labs Visual build ID. Can be used to create builds in advance using the GraphQL API or CLI tool. This can be used to parallelize tests with multiple browsers, shard, or more. By default, this is not set and we create / finish a build during setup / teardown.
- `customId(String customId)`: For advanced users, a user-supplied custom ID to identify this build. Can be used in CI to identify / check / re-check the status of a single build. Usage suggestions: CI pipeline ID.

### Build attributes

Check warning on line 125 in docs/visual-testing/integrations/espresso.md

View workflow job for this annotation

GitHub Actions / vale

[vale] docs/visual-testing/integrations/espresso.md#L125

[sauce.Headings] 'Build attributes' should use title case capitalization.
Raw output
{"message": "[sauce.Headings] 'Build attributes' should use title case capitalization.", "location": {"path": "docs/visual-testing/integrations/espresso.md", "range": {"start": {"line": 125, "column": 5}}}, "severity": "WARNING"}

When creating the service in `VisualClient`, extra fields can be set to define the context, thus acting on which baselines new snapshots will be compared to. ([More info on baseline matching](../../visual-testing.md#baseline-matching))

It needs to be defined through the `VisualApi.Builder` object.

Methods available:

- `buildName(String buildName)`: Sets the name of the build
- `projectName(String project)`: Sets the name of the project
- `branchName(String branch)`: Sets the name of the branch
- `defaultBranchName(String defaultBranch)`: Sets the name of the default branch

Example:

```java
import com.saucelabs.visual.VisualClient;

visual = VisualClient.builder(username, accessKey)
.buildName("Sauce Demo Test")
.branchName("main")
.projectName("Java examples")
.build();
```

### Ignored regions

Check warning on line 150 in docs/visual-testing/integrations/espresso.md

View workflow job for this annotation

GitHub Actions / vale

[vale] docs/visual-testing/integrations/espresso.md#L150

[sauce.Headings] 'Ignored regions' should use title case capitalization.
Raw output
{"message": "[sauce.Headings] 'Ignored regions' should use title case capitalization.", "location": {"path": "docs/visual-testing/integrations/espresso.md", "range": {"start": {"line": 150, "column": 5}}}, "severity": "WARNING"}

#### Component-based ignored region

Check warning on line 152 in docs/visual-testing/integrations/espresso.md

View workflow job for this annotation

GitHub Actions / vale

[vale] docs/visual-testing/integrations/espresso.md#L152

[sauce.Headings] 'Component-based ignored region' should use title case capitalization.
Raw output
{"message": "[sauce.Headings] 'Component-based ignored region' should use title case capitalization.", "location": {"path": "docs/visual-testing/integrations/espresso.md", "range": {"start": {"line": 152, "column": 6}}}, "severity": "WARNING"}

Sauce Visual provides a way to ignore a list of components.

An ignored component can be a specific element from the page.

Those ignored components are specified when requesting a new snapshot.

Example:

```java
import com.saucelabs.visual.VisualCheckOptions;;

visualClient.sauceVisualCheck("Inventory Page",
VisualCheckOptions.builder()
.ignore(withId(R.id.changeTextBt))
.build());
```

#### User-specified ignored region

Check warning on line 171 in docs/visual-testing/integrations/espresso.md

View workflow job for this annotation

GitHub Actions / vale

[vale] docs/visual-testing/integrations/espresso.md#L171

[sauce.Headings] 'User-specified ignored region' should use title case capitalization.
Raw output
{"message": "[sauce.Headings] 'User-specified ignored region' should use title case capitalization.", "location": {"path": "docs/visual-testing/integrations/espresso.md", "range": {"start": {"line": 171, "column": 6}}}, "severity": "WARNING"}

Alternatively, ignored regions can be user-specified areas. A region is defined by four elements.

- `x`, `y`: The location of the top-left corner of the ignored region
- `width`: The width of the region to ignore
- `height`: The height of the region to ignore

_Note: all values are pixels_

You can also give a name to a region that will be visible in Sauce Visual UI using `name`

Example:

```java

import com.saucelabs.visual.VisualCheckOptions;
import com.saucelabs.visual.model.Region;

visualClient.sauceVisualCheck("Inventory Page",
VisualCheckOptions.builder()
.ignore(Region.builder()
.name("Demo region")
.x(100)
.y(100)
.width(200)
.height(200)
.build())
.build());
```

### Capturing the DOM snapshot

Check warning on line 202 in docs/visual-testing/integrations/espresso.md

View workflow job for this annotation

GitHub Actions / vale

[vale] docs/visual-testing/integrations/espresso.md#L202

[sauce.Headings] 'Capturing the DOM snapshot' should use title case capitalization.
Raw output
{"message": "[sauce.Headings] 'Capturing the DOM snapshot' should use title case capitalization.", "location": {"path": "docs/visual-testing/integrations/espresso.md", "range": {"start": {"line": 202, "column": 5}}}, "severity": "WARNING"}

Sauce Visual does not capture DOM snapshots by default. This setting can be changed globally via the build options.

Example:
```java
import com.saucelabs.visual.VisualCheckOptions;

static VisualClient visualClient = VisualClient.builder(
BuildConfig.SAUCE_USERNAME,
BuildConfig.SAUCE_ACCESS_KEY)
.buildName("Espresso Basic Sample")
.captureDom(true)
.build();
```

You can alternatively enable DOM capturing when initating a visual check.

```java
import com.saucelabs.visual.VisualCheckOptions;

visualClient.sauceVisualCheck("Inventory Page",
VisualCheckOptions.builder()
.captureDom(true)
.build());
```

### Clip to an Element

Check warning on line 229 in docs/visual-testing/integrations/espresso.md

View workflow job for this annotation

GitHub Actions / vale

[vale] docs/visual-testing/integrations/espresso.md#L229

[sauce.Headings] 'Clip to an Element' should use title case capitalization.
Raw output
{"message": "[sauce.Headings] 'Clip to an Element' should use title case capitalization.", "location": {"path": "docs/visual-testing/integrations/espresso.md", "range": {"start": {"line": 229, "column": 5}}}, "severity": "WARNING"}

<ClippingDescription />

Example:

```java
import com.saucelabs.visual.VisualCheckOptions;
kb-kerem marked this conversation as resolved.
Show resolved Hide resolved

visualClient.sauceVisualCheck("Visible Sale Banner",
VisualCheckOptions.builder()
.clipElement(withId(R.id.changeTextBt))
.build());
```

## Examples

Click [here](https://github.com/saucelabs/visual-examples/tree/main/espresso) to see the example project.

Check warning on line 246 in docs/visual-testing/integrations/espresso.md

View workflow job for this annotation

GitHub Actions / vale

[vale] docs/visual-testing/integrations/espresso.md#L246

[sauce.MeaningfulLinkWords] Improve SEO and accessibility by rewriting 'here' in the link text.
Raw output
{"message": "[sauce.MeaningfulLinkWords] Improve SEO and accessibility by rewriting 'here' in the link text.", "location": {"path": "docs/visual-testing/integrations/espresso.md", "range": {"start": {"line": 246, "column": 8}}}, "severity": "WARNING"}
1 change: 1 addition & 0 deletions sidebars.js
Original file line number Diff line number Diff line change
Expand Up @@ -1725,6 +1725,7 @@ module.exports = {
'visual-testing/integrations/python',
'visual-testing/integrations/python-robot-framework',
'visual-testing/integrations/playwright',
'visual-testing/integrations/espresso'
],
},
'visual-testing/cli',
Expand Down