AWS Device Farm에서 사용자 지정 테스트 환경으로 작업 - AWS Device Farm

기계 번역으로 제공되는 번역입니다. 제공된 번역과 원본 영어의 내용이 상충하는 경우에는 영어 버전이 우선합니다.

AWS Device Farm에서 사용자 지정 테스트 환경으로 작업

AWS Device Farm을 사용하면 모든 Device Farm 사용자에게 권장되는 접근 방식인 자동 테스트(사용자 지정 모드)를 위한 사용자 지정 환경을 구성할 수 있습니다. Device Farm의 환경에 대해 자세히 알아보려면 테스트 환경을 참조하세요.

표준 모드와 달리 사용자 지정 모드의 이점은 다음과 같습니다.

  • 더 빠른 end-to-end 테스트 실행: 테스트 패키지가 테스트 도구 모음의 모든 테스트를 탐지하도록 파싱되지 않으므로 사전 처리/사후 처리 오버헤드를 피할 수 있습니다.

  • 라이브 로그 및 비디오 스트리밍: 사용자 지정 모드를 사용하면 클라이언트 측 테스트 로그와 비디오가 실시간 스트리밍됩니다. 이 기능은 표준 모드의 경우 사용할 수 없습니다.

  • 모든 아티팩트 캡처: 호스트 및 장치에서 사용자 지정 모드를 사용하면 모든 테스트 아티팩트를 캡처할 수 있습니다. 표준 모드에서는 불가능할 수 있습니다.

  • 보다 일관되고 복제 가능한 로컬 환경: 표준 모드에서는 개별 테스트마다 아티팩트가 별도로 제공되므로 특정 상황에서 유용할 수 있습니다. 하지만 Device Farm이 실행된 각 테스트를 다르게 처리하므로 로컬 테스트 환경이 원래 구성과 다를 수 있습니다.

    반면 사용자 지정 모드를 사용하면 Device Farm 테스트 실행 환경을 로컬 테스트 환경에 맞게 일관되게 만들 수 있습니다.

사용자 지정 환경은 YAML 형식의 테스트 사양(테스트 사양) 파일을 사용하여 구성됩니다. Device Farm은 지원되는 각 테스트 유형에 대해 있는 그대로 사용하거나 사용자 지정할 수 있는 기본 테스트 사양 파일을 제공합니다. 테스트 필터 또는 구성 파일과 같은 사용자 지정을 테스트 사양에 추가할 수 있습니다. 편집된 테스트 사양은 향후 테스트 실행을 위해 저장할 수 있습니다.

자세한 정보는 AWS CLI를 사용하여 사용자 지정 테스트 사양 업로드Device Farm에서 테스트 실행 생성 단원을 참조하세요.

테스트 사양 구문

YAML 테스트 사양 파일 구조

version: 0.1 phases: install: commands: - command - command pre_test: commands: - command - command test: commands: - command - command post_test: commands: - command - command artifacts: - location - location

테스트 사양에는 다음이 포함되어 있습니다.

version

Device Farm에서 지원하는 테스트 사양 버전을 반영합니다. 현재 버전 번호는 0.1입니다.

phases

이 섹션에는 테스트 실행 중에 실행되는 명령 그룹이 포함되어 있습니다.

허용되는 테스트 단계 이름은 다음과 같습니다.

install

선택 사항

Device Farm에서 지원되는 프레임워크를 테스트하기 위한 기본 종속 항목이 이미 설치되어 있습니다. 이 단계에는 Device Farm이 설치 중에 실행하는 추가 명령(있는 경우)이 포함되어 있습니다.

pre_test

선택 사항

자동 테스트 실행 전에 실행되는 명령이 있는 경우입니다.

test

선택 사항

자동 테스트 실행 중에 실행되는 명령입니다. 테스트 단계에서 명령이 실패할 경우 테스트가 실패로 표시됩니다.

post_test

선택 사항

자동 테스트 실행 후에 실행되는 명령이 있는 경우입니다.

artifacts

선택 사항

Device Farm은 여기에 지정된 위치에서 사용자 지정 보고서, 로그 파일 및 이미지 등의 아티팩트를 수집합니다. 와일드카드 문자는 아티팩트 위치의 일부로 지원되지 않으므로 각 위치의 올바른 경로를 지정해야 합니다.

이러한 테스트 아티팩트는 테스트 실행에서 각 디바이스에 사용할 수 있습니다. 테스트 아티팩트 검색에 대한 자세한 내용은 사용자 지정 테스트 환경에서 아티팩트 사용 단원을 참조하세요.

중요

테스트 사양은 올바른 YAML 파일 형식으로 지정해야 합니다. 테스트 사양에서 들여쓰기 또는 공백이 잘못된 경우 테스트 실행이 실패할 수 있습니다. YAML 파일에서 탭은 허용되지 않습니다. YAML 검사기를 사용하여 테스트 사양이 올바른 YAML 파일인지 여부를 테스트할 수 있습니다. 자세한 내용은 YAML 웹 사이트를 참조하세요.

테스트 사양 예

Appium Java TestNG 테스트 실행으로 구성하는 Device Farm YAML 테스트 사양의 예입니다.

version: 0.1 # This flag enables your test to run using Device Farm's Amazon Linux 2 test host when scheduled on # Android devices. By default, iOS device tests will always run on Device Farm's macOS test hosts. # For Android, you can explicitly select your test host to use our Amazon Linux 2 infrastructure. # For more information, please see: # https://docs.aws.amazon.com/devicefarm/latest/developerguide/amazon-linux-2.html android_test_host: amazon_linux_2 # Phases represent collections of commands that are executed during your test run on the test host. phases: # The install phase contains commands for installing dependencies to run your tests. # For your convenience, certain dependencies are preinstalled on the test host. # For Android tests running on the Amazon Linux 2 test host, many software libraries are available # from the test host using the devicefarm-cli tool. To learn more, please see: # https://docs.aws.amazon.com/devicefarm/latest/developerguide/amazon-linux-2-devicefarm-cli.html # For iOS tests, you can use the Node.JS tools nvm, npm, and avm to setup your environment. By # default, Node.js versions 16.20.2 and 14.19.3 are available on the test host. install: commands: # The Appium server is written using Node.js. In order to run your desired version of Appium, # you first need to set up a Node.js environment that is compatible with your version of Appium. - |- if [ $DEVICEFARM_DEVICE_PLATFORM_NAME = "Android" ]; then devicefarm-cli use node 16; else # For iOS, use "nvm use" to switch between the two preinstalled NodeJS versions 14 and 16, # and use "nvm install" to download a new version of your choice. nvm use 16; fi; - node --version # Use the devicefarm-cli to select a preinstalled major version of Appium on Android. # Use avm or npm to select Appium for iOS. - |- if [ $DEVICEFARM_DEVICE_PLATFORM_NAME = "Android" ]; then # For Android, the Device Farm service automatically updates the preinstalled Appium versions # over time to incorporate the latest minor and patch versions for each major version. If you # wish to select a specific version of Appium, you can instead use NPM to install it: # npm install -g appium@2.1.3; devicefarm-cli use appium 2; else # For iOS, Appium versions 1.22.2 and 2.2.1 are preinstalled and selectable through avm. # For all other versions, please use npm to install them. For example: # npm install -g appium@2.1.3; # Note that, for iOS devices, Appium 2 is only supported on iOS version 14 and above using # NodeJS version 16 and above. avm 2.2.1; fi; - appium --version # For Appium version 2, for Android tests, Device Farm automatically updates the preinstalled # UIAutomator2 driver over time to incorporate the latest minor and patch versions for its major # version 2. If you want to install a specific version of the driver, you can use the Appium # extension CLI to uninstall the existing UIAutomator2 driver and install your desired version: # - |- # if [ $DEVICEFARM_DEVICE_PLATFORM_NAME = "Android" ]; # then # appium driver uninstall uiautomator2; # appium driver install uiautomator2@2.34.0; # fi; # For Appium version 2, for iOS tests, the XCUITest driver is preinstalled using version 5.7.0 # If you want to install a different version of the driver, you can use the Appium extension CLI # to uninstall the existing XCUITest driver and install your desired version: # - |- # if [ $DEVICEFARM_DEVICE_PLATFORM_NAME = "iOS" ]; # then # appium driver uninstall xcuitest; # appium driver install xcuitest@5.8.1; # fi; # We recommend setting the Appium server's base path explicitly for accepting commands. - export APPIUM_BASE_PATH=/wd/hub # Install the NodeJS dependencies. - cd $DEVICEFARM_TEST_PACKAGE_PATH # First, install dependencies which were packaged with the test package using npm-bundle. - npm install *.tgz # Then, optionally, install any additional dependencies using npm install. # If you do run these commands, we strongly recommend that you include your package-lock.json # file with your test package so that the dependencies installed on Device Farm match # the dependencies you've installed locally. # - cd node_modules/* # - npm install # The pre-test phase contains commands for setting up your test environment. pre_test: commands: # Device farm provides different pre-built versions of WebDriverAgent, an essential Appium # dependency for iOS devices, and each version is suggested for different versions of Appium: # DEVICEFARM_WDA_DERIVED_DATA_PATH_V8: this version is suggested for Appium 2 # DEVICEFARM_WDA_DERIVED_DATA_PATH_V7: this version is suggested for Appium 1 # Additionally, for iOS versions 16 and below, the device unique identifier (UDID) needs # to be slightly modified for Appium tests. - |- if [ $DEVICEFARM_DEVICE_PLATFORM_NAME = "iOS" ]; then if [ $(appium --version | cut -d "." -f1) -ge 2 ]; then DEVICEFARM_WDA_DERIVED_DATA_PATH=$DEVICEFARM_WDA_DERIVED_DATA_PATH_V8; else DEVICEFARM_WDA_DERIVED_DATA_PATH=$DEVICEFARM_WDA_DERIVED_DATA_PATH_V7; fi; if [ $(echo $DEVICEFARM_DEVICE_OS_VERSION | cut -d "." -f 1) -le 16 ]; then DEVICEFARM_DEVICE_UDID_FOR_APPIUM=$(echo $DEVICEFARM_DEVICE_UDID | tr -d "-"); else DEVICEFARM_DEVICE_UDID_FOR_APPIUM=$DEVICEFARM_DEVICE_UDID; fi; fi; # Appium downloads Chromedriver using a feature that is considered insecure for multitenant # environments. This is not a problem for Device Farm because each test host is allocated # exclusively for one customer, then terminated entirely. For more information, please see # https://github.com/appium/appium/blob/master/packages/appium/docs/en/guides/security.md # We recommend starting the Appium server process in the background using the command below. # The Appium server log will be written to the $DEVICEFARM_LOG_DIR directory. # The environment variables passed as capabilities to the server will be automatically assigned # during your test run based on your test's specific device. # For more information about which environment variables are set and how they're set, please see # https://docs.aws.amazon.com/devicefarm/latest/developerguide/custom-test-environment-variables.html - |- if [ $DEVICEFARM_DEVICE_PLATFORM_NAME = "Android" ]; then appium --base-path=$APPIUM_BASE_PATH --log-timestamp \ --log-no-colors --relaxed-security --default-capabilities \ "{\"appium:deviceName\": \"$DEVICEFARM_DEVICE_NAME\", \ \"platformName\": \"$DEVICEFARM_DEVICE_PLATFORM_NAME\", \ \"appium:app\": \"$DEVICEFARM_APP_PATH\", \ \"appium:udid\":\"$DEVICEFARM_DEVICE_UDID\", \ \"appium:platformVersion\": \"$DEVICEFARM_DEVICE_OS_VERSION\", \ \"appium:chromedriverExecutableDir\": \"$DEVICEFARM_CHROMEDRIVER_EXECUTABLE_DIR\", \ \"appium:automationName\": \"UiAutomator2\"}" \ >> $DEVICEFARM_LOG_DIR/appium.log 2>&1 & else appium --base-path=$APPIUM_BASE_PATH --log-timestamp \ --log-no-colors --relaxed-security --default-capabilities \ "{\"appium:deviceName\": \"$DEVICEFARM_DEVICE_NAME\", \ \"platformName\": \"$DEVICEFARM_DEVICE_PLATFORM_NAME\", \ \"appium:app\": \"$DEVICEFARM_APP_PATH\", \ \"appium:udid\":\"$DEVICEFARM_DEVICE_UDID_FOR_APPIUM\", \ \"appium:platformVersion\": \"$DEVICEFARM_DEVICE_OS_VERSION\", \ \"appium:derivedDataPath\": \"$DEVICEFARM_WDA_DERIVED_DATA_PATH\", \ \"appium:usePrebuiltWDA\": true, \ \"appium:automationName\": \"XCUITest\"}" \ >> $DEVICEFARM_LOG_DIR/appium.log 2>&1 & fi; # This code will wait until the Appium server starts. - |- appium_initialization_time=0; until curl --silent --fail "http://0.0.0.0:4723${APPIUM_BASE_PATH}/status"; do if [[ $appium_initialization_time -gt 30 ]]; then echo "Appium did not start within 30 seconds. Exiting..."; exit 1; fi; appium_initialization_time=$((appium_initialization_time + 1)); echo "Waiting for Appium to start on port 4723..."; sleep 1; done; # The test phase contains commands for running your tests. test: commands: # Your test package is downloaded and unpackaged into the $DEVICEFARM_TEST_PACKAGE_PATH directory. # When compiling with npm-bundle, the test folder can be found in the node_modules/*/ subdirectory. - cd $DEVICEFARM_TEST_PACKAGE_PATH/node_modules/* - echo "Starting the Appium NodeJS test" # Enter your command below to start the tests. The command should be the same command as the one # you use to run your tests locally from the command line. An example, "npm test", is given below: - npm test # The post-test phase contains commands that are run after your tests have completed. # If you need to run any commands to generating logs and reports on how your test performed, # we recommend adding them to this section. post_test: commands: # Artifacts are a list of paths on the filesystem where you can store test output and reports. # All files in these paths will be collected by Device Farm. # These files will be available through the ListArtifacts API as your "Customer Artifacts". artifacts: # By default, Device Farm will collect your artifacts from the $DEVICEFARM_LOG_DIR directory. - $DEVICEFARM_LOG_DIR