Skip to content

Commit

Permalink
Merge branch 'IRIS-420-docs-structure' of https://github.com/saucelab…
Browse files Browse the repository at this point in the history
…s/sauce-docs into IRIS-420-docs-structure
  • Loading branch information
wswebcreation committed Nov 9, 2023
2 parents 61541d1 + 2061314 commit 6a6e8f8
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 16 deletions.
4 changes: 2 additions & 2 deletions docs/visual-testing/integrations/cypress.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ context('Sauce Demo', () => {
### Step 4: Configure your Sauce Labs credentials

Sauce Visual relies on environment variables for authentications.<br />
Both `SAUCE_USERNAME` and `SAUCE_ACCESS_KEY` need to be set prior starting your WebdriverIO job.
Both `SAUCE_USERNAME` and `SAUCE_ACCESS_KEY` need to be set prior starting your Cypress job.

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

Expand All @@ -88,7 +88,7 @@ Builds will appear on Sauce Labs platform as soon as they have been created by t

### Build name

Sauce Visual for Cypress plugin extends Cypress configuration, allowing to define the context, thus acting on which baselines new snapshots will be compared to. ([More info on baseline matching](../sauce-visual.md#baseline-matching))
Sauce Visual for Cypress plugin extends Cypress configuration, allowing to define the context, thus acting on which baselines new snapshots will be compared to. ([More info on baseline matching](/visual-testing/#baseline-matching))

Options:
- `region`: Sauce Labs Region where the new build will be created (default: `us-west-1`)
Expand Down
66 changes: 52 additions & 14 deletions docs/visual-testing/integrations/java.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,14 @@ Add [Sauce Visual](https://central.sonatype.com/artifact/com.saucelabs.visual/ja

Declare a RemoteWebDriver and a VisualApi instance as class variables
```java
import org.openqa.selenium.remote.RemoteWebDriver;
import com.saucelabs.visual.VisualApi;

private static VisualApi visual;
private static RemoteWebDriver driver;
```

Initialize `RemoteWebDriver` and `VisualApi` in `@BeforeAll` section, or `@BeforeSuite` if you're using TestNG
Initialize `RemoteWebDriver` and `VisualApi`

<Tabs
defaultValue="JUnit"
Expand All @@ -55,27 +58,31 @@ Initialize `RemoteWebDriver` and `VisualApi` in `@BeforeAll` section, or `@Befor
<TabItem value="JUnit">

```java
import org.junit.jupiter.api.BeforeAll;

@BeforeAll
public static void init() {
driver = new RemoteWebDriver(webDriverUrl, capabilities);
visual = new Builder(driver, sauceUsername, sauceAccessKey, DataCenter.US_WEST_1).build();
visual = new VisualApi.Builder(driver, sauceUsername, sauceAccessKey, DataCenter.US_WEST_1).build();
}
```
</TabItem>
<TabItem value="TestNG">

```java
import org.testng.annotations.BeforeSuite;

@BeforeSuite
public static void init() {
driver = new RemoteWebDriver(webDriverUrl, capabilities);
visual = new Builder(driver, sauceUsername, sauceAccessKey, DataCenter.US_WEST_1).build();
visual = new VisualApi.Builder(driver, sauceUsername, sauceAccessKey, DataCenter.US_WEST_1).build();
}
```
</TabItem>
</Tabs>


Don't forget to quit the WebDriver in `@AfterAll` section, or `@AfterSuite` if you're using TestNG
Don't forget to quit the WebDriver
<Tabs
defaultValue="JUnit"
  values={[
Expand All @@ -85,6 +92,8 @@ Don't forget to quit the WebDriver in `@AfterAll` section, or `@AfterSuite` if y
<TabItem value="JUnit">

```java
import org.junit.jupiter.api.AfterAll;

@AfterAll
public static void tearDown() {
if (driver != null) {
Expand All @@ -96,6 +105,8 @@ Don't forget to quit the WebDriver in `@AfterAll` section, or `@AfterSuite` if y
<TabItem value="TestNG">

```java
import org.testng.annotations.AfterSuite;

@AfterSuite
public static void tearDown() {
if (driver != null) {
Expand All @@ -110,20 +121,47 @@ Don't forget to quit the WebDriver in `@AfterAll` section, or `@AfterSuite` if y
### Step 3: Add visual tests in your tests

Add a check to one of your tests:
```java
@Test
void checkLoginLooksTheSame() {
var loginPage = new LoginPage(driver);
loginPage.open();

visual.sauceVisualCheck("Before Login");
}
```
<Tabs
defaultValue="JUnit"
  values={[
    {label: 'JUnit', value: 'JUnit'},
    {label: 'TestNG', value: 'TestNG'},
  ]}>
<TabItem value="JUnit">

```java
import org.junit.jupiter.api.Test;

@Test
void checkLoginLooksTheSame() {
var loginPage = new LoginPage(driver);
loginPage.open();

visual.sauceVisualCheck("Before Login");
}
```
</TabItem>
<TabItem value="TestNG">

```java
import org.testng.annotations.Test;

@Test
void checkLoginLooksTheSame() {
var loginPage = new LoginPage(driver);
loginPage.open();

visual.sauceVisualCheck("Before Login");
}
```
</TabItem>
</Tabs>

### Step 4: Configure your Sauce Labs credentials

Sauce Labs Visual relies on environment variables for authentications.<br />
Both `SAUCE_USERNAME` and `SAUCE_ACCESS_KEY` need to be set prior starting your WebdriverIO job.
Both `SAUCE_USERNAME` and `SAUCE_ACCESS_KEY` need to be set prior starting your Java job.

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

Expand Down Expand Up @@ -200,7 +238,7 @@ Alternatively, ignored regions can be user-specified areas. A region is defined

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

*Note: all values are pixels*

Expand Down

0 comments on commit 6a6e8f8

Please sign in to comment.