Utilizzare Chrome per Testing o Chromium con Axe Watcher

This page is not available in the language you requested. You have been redirected to the English version of the page.
Link to this page copied to clipboard

Come installare e configurare Chrome per Testing o Chromium per piattaforme che si connettono a un browser installato sul sistema

Not for use with personal data

Axe Watcher supporta solo Google Chrome per Testing o Chromium. Le versioni regolari di Chrome dalla 139 in poi non sono supportate.

Le piattaforme di test che gestiscono la propria installazione del browser (Playwright e Puppeteer) non sono interessate; scaricano automaticamente un Chromium compatibile. Le piattaforme che si connettono a un browser già installato sulla macchina (WebdriverIO, WebDriverJS e Java Selenium) richiedono di installare Chrome per Testing o Chromium e configurare esplicitamente il percorso.

Installare Chrome per Testing o Chromium

Scegli uno dei seguenti metodi di installazione:

  • Usando npm: @puppeteer/browsers è uno strumento di download del browser autonomo; non richiede l'installazione di Puppeteer nel progetto. Per installare Chrome per Testing, esegui:

    npx @puppeteer/browsers install chrome@stable

    Per installare invece Chromium, esegui:

    npx @puppeteer/browsers install chromium@latest

    Il comando stampa il percorso del binario installato alla fine del suo output, per esempio:

    chrome@stable /home/user/.cache/puppeteer/chrome/linux-136.0.7103.92/chrome-linux64/chrome

    Imposta la variabile d'ambiente CHROME_PATH su quel percorso prima di eseguire i tuoi test.

    important

    @puppeteer/browsers install scarica il browser in una sottodirectory della directory di lavoro corrente. Esegui il comando da una posizione in cui un grande download sia appropriato e considera di aggiungere la directory risultante al tuo .gitignore.

  • Usando GitHub Actions: Aggiungi il seguente passo al tuo file di workflow. Per installare Chrome per Testing:

    - name: Setup Chrome for Testing
      uses: browser-actions/setup-chrome@latest
      id: setup-chrome
      with:
        chrome-version: stable
        install-chromedriver: true

    Per installare invece Chromium, usa latest per chrome-version:

    - name: Setup Chromium
      uses: browser-actions/setup-chrome@latest
      id: setup-chrome
      with:
        chrome-version: latest
        install-chromedriver: true

    In entrambi i casi, il percorso del binario è disponibile dall'output del passo:

    ${{ steps.setup-chrome.outputs.chrome-path }}

Configura la tua piattaforma

Una volta impostato CHROME_PATH , configura il tuo setup di test come segue.

WebdriverIO

Passa il percorso del binario all'interno di goog:chromeOptions nelle tue capacità di WebdriverIO.

Per il pacchetto standalone (wdioConfig()):

const browser = await remote(
  wdioConfig({
    axe: {
      apiKey: ACCESSIBILITY_API_KEY,
      projectId: PROJECT_ID
    },
    capabilities: {
      browserName: 'chrome',
      'goog:chromeOptions': {
        binary: process.env.CHROME_PATH
      }
    }
  })
)

Per WDIO Testrunner (wdioTestRunner()):

export const config = wdioTestRunner({
  axe: {
    apiKey: ACCESSIBILITY_API_KEY,
    projectId: PROJECT_ID
  }
}, {
  capabilities: [{
    browserName: 'chrome',
    'goog:chromeOptions': {
      binary: process.env.CHROME_PATH
    }
  }]
})

WebDriverJS

Chiama webdriverConfig() prima per ottenere l'oggetto delle opzioni di Chrome, quindi imposta il percorso del binario prima di costruire il browser:

const chromeOptions = webdriverConfig({
  axe: {
    apiKey: ACCESSIBILITY_API_KEY,
    projectId: PROJECT_ID
  }
})
chromeOptions.setBinaryPath(process.env.CHROME_PATH)

const browser = await new Builder()
  .forBrowser('chrome')
  .setChromeOptions(chromeOptions)
  .build()

Java Selenium

Imposta il percorso del binario su ChromeOptions prima di chiamare watcher.configure():

AxeWatcherOptions options =
    new AxeWatcherOptions()
        .setApiKey(System.getenv("ACCESSIBILITY_API_KEY"))
        .setProjectId(System.getenv("PROJECT_ID"));
AxeWatcher watcher = new AxeWatcher(options);
ChromeOptions chromeOptions = new ChromeOptions();
chromeOptions.setBinary(System.getenv("CHROME_PATH"));
chromeOptions = watcher.configure(chromeOptions);
WebDriver wrappedDriver = watcher.wrapDriver(new ChromeDriver(chromeOptions));