> Markdown version of [Introduzione](https://vaadin.com/docs/latest/it/flow/testing/browserless/getting-started). Section index: [llms.txt](https://vaadin.com/docs/latest/it/flow/llms.txt)

# Introduzione ai test browserless

Questa pagina elenca le dipendenze di test per ciascun framework applicativo supportato, e una classe di test minimale su cui si basano gli snippet nelle pagine seguenti.

## <a id="dipendenze"></a>Dipendenze

Con il Vaadin Bill-of-Materials (BOM) importato in un progetto Maven, aggiungere le dipendenze per il proprio framework con scope `test`. Il BOM definisce le versioni degli artifact Vaadin.

**Plain Java**

```xml
<dependency>
    <groupId>com.vaadin</groupId>
    <artifactId>browserless-test-junit6</artifactId>
    <scope>test</scope>
</dependency>
```

**Spring Boot**

```xml
<dependency>
    <groupId>com.vaadin</groupId>
    <artifactId>browserless-test-spring</artifactId>
    <scope>test</scope>
</dependency>
<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-test</artifactId>
    <scope>test</scope>
</dependency>

<!-- Optional: Spring Security test annotations, such as @WithMockUser -->
<dependency>
    <groupId>org.springframework.security</groupId>
    <artifactId>spring-security-test</artifactId>
    <scope>test</scope>
</dependency>
```

**Quarkus**

```xml
<dependency>
    <groupId>com.vaadin</groupId>
    <artifactId>browserless-test-junit6</artifactId>
    <scope>test</scope>
</dependency>
<dependency>
    <groupId>com.vaadin</groupId>
    <artifactId>browserless-test-quarkus</artifactId>
    <scope>test</scope>
</dependency>
<dependency>
    <groupId>io.quarkus</groupId>
    <artifactId>quarkus-junit</artifactId>
    <scope>test</scope>
</dependency>

<!-- Optional: Quarkus Security test annotation @TestSecurity -->
<dependency>
    <groupId>io.quarkus</groupId>
    <artifactId>quarkus-test-security</artifactId>
    <scope>test</scope>
</dependency>
```

**Java EE/CDI**

```xml
<dependency>
    <groupId>com.vaadin</groupId>
    <artifactId>browserless-test-junit6</artifactId>
    <scope>test</scope>
</dependency>
<dependency>
    <groupId>org.jboss.weld</groupId>
    <artifactId>weld-junit5</artifactId>
    <version>5.0.3.Final</version>
    <scope>test</scope>
</dependency>
<dependency>
    <groupId>org.junit.jupiter</groupId>
    <artifactId>junit-jupiter</artifactId>
    <scope>test</scope>
</dependency>

<!-- In <dependencyManagement>, unless your parent POM already manages JUnit -->
<dependency>
    <groupId>org.junit</groupId>
    <artifactId>junit-bom</artifactId>
    <version>6.0.3</version>
    <type>pom</type>
    <scope>import</scope>
</dependency>
```

Un progetto Java EE/CDI necessita anche di [Vaadin CDI](https://vaadin.com/docs/latest/it/flow/integrations/cdi.md#add-dependencies) e delle API Jakarta EE fornite, che l’applicazione ha già.

Le dipendenze di sicurezza opzionali forniscono le annotazioni di test che impostano l’utente delle classi base di [Spring](https://vaadin.com/docs/latest/it/flow/testing/browserless/spring-security.md) e [Quarkus](https://vaadin.com/docs/latest/it/flow/testing/browserless/quarkus.md#security-integration). Un application context protetto necessita solo della propria Spring Security o Quarkus Security dell’applicazione.

## <a id="classe-di-test-minimale"></a>Classe di test minimale

Una classe di test estende la classe base del proprio framework. Prima di ciascun metodo di test, le classi base Plain Java, Spring Boot e Quarkus creano l’ambiente Vaadin con un utente e una window, e aprono la root view; dopo il metodo di test, ripuliscono l’ambiente. Il test chiama su sé stesso i metodi di testing, come `navigate()`.

**Plain Java**

```java
import org.junit.jupiter.api.Test;
import com.vaadin.browserless.BrowserlessTest;

class MyViewTest extends BrowserlessTest {

    @Test
    void myTest() {
        MyView view = navigate(MyView.class);
        // Find components and simulate user actions
    }
}
```

**Spring Boot**

```java
import org.junit.jupiter.api.Test;
import org.springframework.boot.test.context.SpringBootTest;
import com.vaadin.browserless.SpringBrowserlessTest;

@SpringBootTest
class MyViewTest extends SpringBrowserlessTest {

    @Test
    void myTest() {
        MyView view = navigate(MyView.class);
        // Find components and simulate user actions
    }
}
```

**Quarkus**

```java
import org.junit.jupiter.api.Test;
import com.vaadin.browserless.quarkus.QuarkusBrowserlessTest;
import io.quarkus.test.junit.QuarkusTest;

@QuarkusTest
class MyViewTest extends QuarkusBrowserlessTest {

    @Test
    void myTest() {
        MyView view = navigate(MyView.class);
        // Find components and simulate user actions
    }
}
```

**Java EE/CDI**

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

class MyViewTest extends AbstractCdiViewTest {

    @Test
    void myTest() {
        MyView view = navigate(MyView.class);
        // Find components and simulate user actions
    }
}
```

Queste classi base eseguono la scansione dell’intero classpath per le route, a meno che la classe di test non abbia un’annotazione [`@ViewPackages`](https://vaadin.com/docs/latest/it/flow/testing/browserless/test-environment.md#route-scanning).

Un test Java EE/CDI estende `AbstractCdiViewTest`, una sottoclasse di `BrowserlessTest` posseduta dall’applicazione che avvia l’ambiente Vaadin con Weld e `CdiVaadinServlet`, e registra le route che i test utilizzano invece di eseguire la scansione. Vedere [CDI Test Integration](https://vaadin.com/docs/latest/it/flow/testing/browserless/cdi.md#test-base-class) per quella classe.

### <a id="locators"></a>Locators

L’interfaccia opzionale `Locators` fornisce ulteriori metodi di utilità: punti di ingresso tipizzati per i [locator](https://vaadin.com/docs/latest/it/flow/testing/browserless/locators.md), come `findButton()` e `findTextField()`. Per usarli in un test che estende una classe base, implementare l’interfaccia nella classe di test, come descritto in [Opting in for `BrowserlessTest`](https://vaadin.com/docs/latest/it/flow/testing/browserless/locators.md#opting-in).

## <a id="uso-degli-snippet-nelle-pagine-seguenti"></a>Uso degli snippet nelle pagine seguenti

La maggior parte degli snippet nelle pagine seguenti chiama i metodi di testing su `window`, una window di un [application context](https://vaadin.com/docs/latest/it/flow/testing/browserless/multi-user.md). In un test che estende una classe base, chiamare gli stessi metodi sulla classe di test stessa: `window.navigate()` diventa `navigate()`, e `window.findButton()` diventa `findButton()` quando la classe di test implementa `Locators`.

Gli snippet che creano utenti e window da `app` necessitano di un application context, che un test configura quando ha bisogno di più utenti o window, o di maggiore controllo sull’ambiente Vaadin; vedere [Setting Up an Application Context](https://vaadin.com/docs/latest/it/flow/testing/browserless/multi-user.md#setting-up-an-application-context).

`4D59DA39-8F41-49F4-B25D-09074A06FA3A`
