
자동화 테스트의 핵심은 "어떤 요소를 클릭할 것인가"입니다. Appium Inspector를 사용해서 앱의 UI 요소를 찾는 방법을 알아봅니다.
Appium Inspector는 앱 화면의 UI 요소를 탐색하고 Locator를 확인할 수 있는 GUI 도구입니다.
GitHub Releases에서 최신 버전을 다운로드합니다.
| OS | 파일 형식 | 설치 방법 |
|---|---|---|
| Windows | .exe | 다운로드 후 실행하여 설치 |
| Mac (Intel) | .dmg | 다운로드 후 Applications 폴더로 드래그 |
| Mac (Apple Silicon) | .dmg (arm64) | 다운로드 후 Applications 폴더로 드래그 |
Mac 사용자 참고: 첫 실행 시 "확인되지 않은 개발자" 경고가 나타나면,
시스템 설정 > 개인정보 보호 및 보안에서 "확인 없이 열기"를 클릭합니다.
Inspector를 사용하기 전에 Appium 서버를 먼저 시작해야 합니다.
appium --address 127.0.0.1 --port 4723 --base-path /
정상 시작 시:
[Appium] Welcome to Appium v2.x.x
[Appium] Appium REST http interface listener started on http://127.0.0.1:4723
설치한 Appium Inspector를 실행합니다.
| 항목 | 값 |
|---|---|
| Remote Host | 127.0.0.1 |
| Remote Port | 4723 |
| Remote Path | / |
JSON 형식으로 입력합니다:
{
"platformName": "Android",
"appium:automationName": "UiAutomator2",
"appium:deviceName": "YOUR_DEVICE_UDID",
"appium:udid": "YOUR_DEVICE_UDID",
"appium:appPackage": "com.example.myapp",
"appium:appActivity": ".MainActivity",
"appium:noReset": true
}
# 디바이스 UDID 확인
adb devices
# 앱 패키지명 확인 (앱 실행 상태에서)
# Windows
adb shell dumpsys window | findstr mCurrentFocus
# Mac / Linux
adb shell dumpsys window | grep mCurrentFocus
# 출력 예: mCurrentFocus=Window{... com.example.myapp/.MainActivity}
# 패키지명: com.example.myapp
# 액티비티: .MainActivity
모든 설정이 완료되면 Start Session 버튼을 클릭합니다.
Inspector가 연결되면 3개 영역이 표시됩니다:
| 영역 | 설명 |
|---|---|
| 왼쪽 | 앱 화면 스크린샷 |
| 중앙 | UI 계층 구조 (XML 트리) |
| 오른쪽 | 선택한 요소의 속성 |
| 속성 | 설명 | 예시 |
|---|---|---|
resource-id | 고유 ID | com.example:id/btn_login |
text | 표시 텍스트 | 로그인 |
content-desc | 접근성 설명 | 로그인 버튼 |
class | 요소 타입 | android.widget.Button |
bounds | 위치 좌표 | [0,100][200,150] |
| 순위 | Locator | 장점 | 단점 |
|---|---|---|---|
| 1 | resource-id | 안정적, 빠름 | 없는 경우 있음 |
| 2 | accessibility id | 의미 명확 | 설정 안 된 경우 많음 |
| 3 | text | 직관적 | 다국어 시 변경됨 |
| 4 | XPath | 모든 요소 접근 가능 | 느림, 불안정 |
from appium.webdriver.common.appiumby import AppiumBy
# resource-id로 찾기
element = driver.find_element(AppiumBy.ID, "com.example.myapp:id/btn_login")
# 텍스트로 찾기
element = driver.find_element(AppiumBy.XPATH, "//*[@text='로그인']")
# accessibility id로 찾기
element = driver.find_element(AppiumBy.ACCESSIBILITY_ID, "로그인 버튼")
# XPath로 찾기 (복잡한 조건)
element = driver.find_element(
AppiumBy.XPATH,
"//android.widget.Button[@text='확인' and @enabled='true']"
)
# 나쁜 예 - UI 변경 시 깨짐
element = driver.find_element(AppiumBy.XPATH, "//android.widget.Button[3]")
# 나쁜 예 - 계층 변경 시 깨짐
element = driver.find_element(
AppiumBy.XPATH,
"/hierarchy/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.Button"
)
# 나쁜 예 - 해상도마다 다름
driver.tap([(100, 200)])
화면이 변경되면 상단의 Refresh 버튼으로 새로고침합니다.
선택한 요소에 대해 직접 동작을 테스트할 수 있습니다:
오른쪽 패널에서 생성된 Locator를 바로 복사할 수 있습니다.
동작을 녹화해서 코드로 변환하는 기능도 있습니다 (참고용으로만 사용 권장).
| 요소 | Locator 전략 | 값 |
|---|---|---|
| 이메일 입력창 | ID | com.example:id/et_email |
| 비밀번호 입력창 | ID | com.example:id/et_password |
| 로그인 버튼 | ID | com.example:id/btn_login |
| 회원가입 링크 | text | //*[@text='회원가입'] |
from appium.webdriver.common.appiumby import AppiumBy
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
def login(driver, email, password):
# 이메일 입력
email_field = WebDriverWait(driver, 10).until(
EC.presence_of_element_located((AppiumBy.ID, "com.example:id/et_email"))
)
email_field.send_keys(email)
# 비밀번호 입력
password_field = driver.find_element(AppiumBy.ID, "com.example:id/et_password")
password_field.send_keys(password)
# 로그인 버튼 클릭
login_btn = driver.find_element(AppiumBy.ID, "com.example:id/btn_login")
login_btn.click()
| 문제 | 원인 | 해결 방법 |
|---|---|---|
| Session 연결 실패 | Appium 서버 미실행 | 서버 먼저 시작 |
| 요소를 찾을 수 없음 | 화면 로딩 중 | Refresh 후 재시도 |
| resource-id가 없음 | 개발 시 미설정 | text 또는 XPath 사용 |
| 동일 text 여러 개 | 중복 요소 | 부모 요소와 조합하여 XPath 작성 |
| 문제 | 원인 | 해결 방법 |
|---|---|---|
| "손상된 앱" 경고 | Gatekeeper 차단 | 터미널에서 xattr -cr /Applications/Appium\ Inspector.app 실행 |
| Inspector가 열리지 않음 | 보안 설정 | 시스템 설정 > 개인정보 보호 및 보안 > "확인 없이 열기" 클릭 |
| adb 명령어 미인식 | PATH 미설정 | ~/.zshrc에 export PATH=$PATH:~/Library/Android/sdk/platform-tools 추가 |
이번 글에서는 Appium Inspector를 사용해서 UI 요소를 찾는 방법을 알아봤습니다.
핵심 정리:
resource-id > accessibility id > text > XPath 순으로 사용다음 글에서는 찾은 Locator를 활용해서 실제 테스트 코드를 작성하는 방법을 알아보겠습니다.