Sauce Labs con XCUITest

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
Not for use with personal data

Con Axe DevTools Mobile, puoi individuare problematiche di accessibilità nei tuoi test delle UI. Integra il tuo test con Sauce Labs e ottieni informazioni sull'esperienza degli utenti della tua app - prima ancora che la vedano! Sauce Labs è la più grande piattaforma di test basata su cloud, ospitando varie configurazioni di dispositivi e simulatori per rafforzare la tua sicurezza digitale. Configura i tuoi test per eseguirli su Sauce nel tuo attuale processo di automazione della build, per individuare i problemi prima che raggiungano la produzione.

Di seguito troverai una guida per eseguire i tuoi test di UI integrati con Axe DevTools Mobile e Sauce Labs.

Prerequisiti

  1. Prepara la tua app per la distribuzione. Poiché i test su Sauce Labs vengono eseguiti su dispositivi reali, avere l'app e i target di UITest predisposti prima di inviarli al loro servizio per la firma renderà il processo più fluido.
  2. Installa l'interfaccia a riga di comando, e configura le tue credenziali di Sauce Labs. Segui le saucectl istruzioni di Sauce Labs .Cerchi un esempio? Il nostro Progetto iOS di esempio ha un'integrazione pronta per il test.
tip

Verifica di avere i prerequisiti.

  1. progetto di esempio da Github
  2. Download the sample project from Github
  3. Nella stessa finestra, digita cd O axe-devtools-ios-sample-app. Premi ritorno/invio.
  4. In the same window, type sh prepareForSauceRealDevice.sh OR sh prepareForSauceVirtualDevice.sh. Hit return/enter.

Aggiungi configurazione Sauce Labs

Add Sauce Labs Configuration

Sauce Labs uses a yaml file, located at at the project root, .sauce/config.yml. See the sample config below for testing on real devices.

apiVersion: v1alpha
kind: xcuitest
sauce:
  region: us-west-1
  concurrency: 1

xcuitest: 
  # file names for real devices have the `.ipa` extension
  app: "<app_name>.ipa"
  testApp: "<app_name>UITests-Runner.ipa"


suites:
  - name: "<app_name>UITests"
    devices:
      - name: "iPhone.*"
        platformVersion: "17.2"

Dalla cartella radice del tuo progetto nel Terminale, esegui il seguente comando per creare build del dispositivo senza dover collegare un dispositivo al tuo computer:

From your project's root folder in the Terminal, call the following command to create device builds without needing to have a device plugged into your computer:

xcodebuild build-for-testing -configuration Debug \
                             -scheme "$APP_SCHEME" \
                             -target "$APP_UITEST_TARGET" \
                             -sdk iphoneos \
                             -derivedDataPath "./DerivedData"

This command will generate two app files located at ./DerivedData/Build/Products/Debug-iphoneos/: Your iOS application and your UI tests (ending in UITests-Runner).

file. Segui le .ipa istruzioni di Sauce Labs su come creare file .ipa .**app**

Once the .ipa files are created, create an apps folder in the project's directory and add both .ipa files to it.

Run the following command to push the .ipa files to Sauce Labs and begin testing:

saucectl run
note

integrazione con la tua pipeline CI e Sauce Labs .Automazione

Automation

Once you've confirmed your configurations are set up correctly, you're ready to automate this process! We've included a script below to automatically build .ipa files for devices, upload them to Sauce Labs, and run your XCUITests. Your team can also use this script to invoke a test run on Sauce Labs manually.

APP_LOCATION="DerivedData/Build/Products/Debug-iphoneos"
APP_NAME="<app_name>"

rm -rf *.ipa

xcodebuild build-for-testing -configuration Debug \
       -scheme "<scheme_name>" \
       -target "<UITests target>" \
       -sdk iphoneos \
       -derivedDataPath "./DerivedData" \
       -quiet

mkdir Payload

mv $APP_LOCATION/$APP_NAME.app Payload
zip -r -qq "$APP_NAME.ipa" Payload
rm -rf Payload/*

mv $APP_LOCATION/${APP_NAME}UITests-Runner.app Payload
zip -r -qq "${APP_NAME}UITests-Runner.ipa" Payload

saucectl run

rm -rf Payload
rm -rf DerivedData

Puoi eseguire test XCUITest automatizzati con dispositivi virtuali su Sauce Labs! Segui i passaggi seguenti per iniziare.

Aggiungi configurazione Sauce Labs

Add Sauce Labs Configuration

When testing with simulators, your configuration will be located at the project root, .sauce/config.yml. If you have done testing with real devices before, you should note that the configuration for simulators is different from the config you use for real devices. The .zip extension is used in the file names for app and testApp, and suites lists 'simulators' rather than 'devices'.

apiVersion: v1alpha
kind: xcuitest
sauce:
  region: us-west-1
  concurrency: 1

xcuitest:
  # file names for simulators use the `.zip` extension
  app: "<app_name>.zip"
  testApp: "<app_name>UITests-Runner.zip"

suites:
  - name: "<app_name>UITests"
    simulators:
      - name: "iPhone 12 Simulator"
        platformVersions:
          - "16.2"
note

configurazioni separate e suites fornire app configurazione per testApp . each suiteImpostazione della build

Build Setup

You will build the app and the test runner for simulators specifically, using the snippet below as your guide. If you have done testing with Real Devices before, you may note a few differences here - -sdk iphonesimulator, EXCLUDED_ARCHS="", and CODE_SIGN_IDENTITY...

xcodebuild build-for-testing -configuration Debug \
  -scheme "$APP_SCHEME" \
  -target "$APP_UITEST_TARGET" \
  -sdk iphonesimulator \ 
  -derivedDataPath "./DerivedData" \
  EXCLUDED_ARCHS="" \
  CODE_SIGN_IDENTITY="" CODE_SIGNING_REQUIRED=NO CODE_SIGNING_ALLOWED=NO

Infine, esegui il seguente comando per caricare i tuoi file .app e iniziare i test.

  zip -r testApp.zip testApp.app
  zip -r testRunner.zip testRunner.app

Finally, run the following command to upload your .zip files and begin testing.

  saucectl run

Automation

Once you've set up the configuration for testing on simulators, you'll be able to automate this process! Use the script below to automatically build .app files for simulators, zip them up, upload them to Sauce Labs, and run your XCUITests.

APP_LOCATION="DerivedData/Build/Products/Debug-iphonesimulator"
APP_NAME="<app_name>"
RUNNER_NAME="<testApp_name>"

rm -rf $APP_NAME.zip $RUNNER_NAME.zip

xcodebuild build-for-testing -configuration Debug \
  -scheme "<scheme_name>" \
  -target "<UITests target>" \
  -sdk iphonesimulator \
  -derivedDataPath "./DerivedData" \
  -quiet \
  EXCLUDED_ARCHS="" \
  CODE_SIGN_IDENTITY="" CODE_SIGNING_REQUIRED=NO CODE_SIGNING_ALLOWED=NO

zip -r -qq $APP_NAME.zip $APP_LOCATION/$APP_NAME.app
zip -r -qq $RUNNER_NAME.zip $APP_LOCATION/$RUNNER_NAME.app

saucectl run

rm -rf DerivedData