*******사전 작업 필요함*******
✅ [터미널]
adb -s <핸드폰 모델명> shell dumpsys window | findstr "mCurrentFocus"
명령어를 작성하면 실행 중인 package와 Activity 를 확인할 수 있음

✅ [Appium inspector]
package와 Activity 를 확인해서 작성해주고 Start Session

-. 앱이 실행되고 인스펙터를 통해서 요소를 확인 할 수 있음(id/xpath 등)
-. 투어비스 실행앱 화면 마다 요소를 읽어오고 코드를 작성하면서 아래와 같이 로직을 완성 시킴
✅ [모바일 자동화 테스트 로직 완성]
1.투어비스 여행 어플 앱실행
2. 허용 버튼 클릭
3. 창닫기 버튼 클릭
4. 내여행 버튼 클릭
from appium import webdriver
from appium.options.android import UiAutomator2Options
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
import time
# Desired capabilities 설정
options = UiAutomator2Options()
options.device_name = "R3CMA00MR4T"
options.platform_name = "Android"
options.app_package = "com.tourvis.app"
options.app_activity = "com.tourvis.app.activity.MainActivity"
# WebDriver 초기화
driver = webdriver.Remote("http://localhost:4723/wd/hub", options=options)
# 앱이 로드될 때까지 대기
time.sleep(3)
# WebDriverWait을 사용하여 요소가 나타날 때까지 대기
try:
# '허용' 버튼 클릭
allow_button = WebDriverWait(driver, 10).until(
EC.presence_of_element_located((By.ID, 'com.android.permissioncontroller:id/permission_allow_button'))
)
allow_button.click()
print("허용 버튼 클릭")
time.sleep(3) # 클릭 후 3초 대기
# '창닫기' 버튼 클릭
reject_button = WebDriverWait(driver, 10).until(
EC.presence_of_element_located((By.ID, 'com.tourvis.app:id/benefitRejectButton'))
)
reject_button.click()
print("창닫기 버튼 클릭")
time.sleep(3) # 클릭 후 3초 대기
# '내 여행' 텍스트를 가진 요소 클릭
button = WebDriverWait(driver, 10).until(
EC.presence_of_element_located((By.XPATH, '//android.widget.TextView[@text="내 여행"]'))
)
button.click()
print("내 여행 클릭 성공")
time.sleep(3) # 클릭 후 3초 대기
except Exception as e:
print("Error interacting with the app:", e)
# 드라이버 종료
driver.quit()
'5.자동화 > [개인 과제] 자동화프로그램구현하기' 카테고리의 다른 글
Appium 과 Python을 이용하여 모바일 자동화 테스트 [1] (0) | 2024.08.02 |
---|---|
챗GPT 연동해서 주제에 적합한 블로그 포스팅 생성(GPT API , Streamlit) (9) | 2024.05.15 |
[SRT]기차표 자동화 예매하기 (결제화면 출력까지 개발) (0) | 2024.04.16 |
[롯데온] 자동 로그인 구현하기 - 우회 방법 (0) | 2024.02.07 |
[네이버 로그인] 자동화 코드 - 우회 하는 방법 (0) | 2024.02.06 |