728x90
삼성 순정 알람 앱 자동화 스크립트 짜보기(엑셀 연동)

import openpyxl
def getRowCount(file, sheetName):
workbook = openpyxl.load_workbook(file)
sheet = workbook[sheetName]
return sheet.amx_row
def getColumnCount(file, sheetName):
workbook = openpyxl.load_workbook(file)
sheet = workbook[sheetName]
return sheet.max_column
def readData(file, sheetName, rowNum, columnNum):
workbook = openpyxl.load_workbook(file)
sheet = workbook[sheetName]
return sheet.cell(row=rowNum, column=columnNum).value
def writeData(file, sheetName, rowNum, columnNum, data):
workbook = openpyxl.load_workbook(file)
sheet = workbook[sheetName]
sheet.cell(row=rowNum, column=columnNum).value=data
workbook.save(file)
openpyxl 쓸 때 필요한 __init__.py
from appium import webdriver
desired_cap = {
"appium:deviceName": "DeviceID",
"platformName": "Android",
"appPackage": "com.sec.android.app.clockpackage",
"appActivity": "com.sec.android.app.clockpackage.ClockPackage"
}
def clockk():
wd = webdriver.Remote("http://localhost:4723/wd/hub", desired_cap)
wd.implicitly_wait(5)
return wd
알람 앱 실행시키는 스크립트
import time
from openpyxl import load_workbook
from appium.webdriver.common.touch_action import TouchAction
from selenium.common.exceptions import NoSuchElementException
from selenium.webdriver.common.by import By
from openfile import openfile1
wd = openfile1.clockk()
time.sleep(2)
action = TouchAction(wd)
wb = load_workbook('clocktestcase.xlsx')
ws = wb['Sheet1']
try:
element = wd.find_element(By.XPATH, '/hierarchy/android.widget.FrameLayout/android.widget.LinearLayout')
ws['D3'] = "PASS"
except NoSuchElementException:
ws['D3'] = "FAIL"
time.sleep(1)
wd.find_element(By.XPATH, '//android.widget.Button[@content-desc="알람 추가"]').click()
time.sleep(1)
try:
element = wd.find_element(By.XPATH, '/hierarchy/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout')
ws['D4'] = "PASS"
except NoSuchElementException:
ws['D4'] = "FAIL"
time.sleep(1)
wd.find_element(By.XPATH, '//android.widget.Button[@content-desc="취소"]/android.view.ViewGroup/android.widget.TextView').click()
time.sleep(1)
wd.find_element(By.XPATH, '//android.widget.ImageView[@content-desc="옵션 더보기"]').click()
time.sleep(1)
try:
element = wd.find_element(By.XPATH, '/hierarchy/android.widget.FrameLayout/android.widget.FrameLayout/android.widget.ListView/android.widget.LinearLayout[1]/android.widget.LinearLayout')
element = wd.find_element(By.XPATH, '/hierarchy/android.widget.FrameLayout/android.widget.FrameLayout/android.widget.ListView/android.widget.LinearLayout[2]/android.widget.LinearLayout')
element = wd.find_element(By.XPATH, '/hierarchy/android.widget.FrameLayout/android.widget.FrameLayout/android.widget.ListView/android.widget.LinearLayout[3]/android.widget.LinearLayout')
ws['D5'] = "PASS"
except NoSuchElementException:
ws['D5'] = "FAIL"
time.sleep(1)
action.tap(x=445, y=1375).perform()
time.sleep(1)
wd.find_element(By.XPATH, '//android.widget.LinearLayout[@content-desc="세계시각"]/android.widget.RelativeLayout/android.widget.TextView').click()
time.sleep(1)
try:
element = wd.find_element(By.XPATH, '/hierarchy/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.FrameLayout/android.widget.FrameLayout/android.widget.LinearLayout')
ws['D6'] = "PASS"
except NoSuchElementException:
ws['D6'] = "FAIL"
time.sleep(1)
wd.find_element(By.XPATH, '/hierarchy/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.FrameLayout/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.ScrollView/android.widget.LinearLayout/android.widget.Button[1]').click()
time.sleep(1)
wd.find_element(By.XPATH, '//android.widget.LinearLayout[@content-desc="스톱워치"]/android.widget.RelativeLayout/android.widget.TextView').click()
time.sleep(1)
try:
element = wd.find_element(By.XPATH, '/hierarchy/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.LinearLayout/android.widget.RelativeLayout/android.widget.ScrollView/android.widget.RelativeLayout/android.widget.RelativeLayout')
ws['D7'] = "PASS"
except NoSuchElementException:
ws['D7'] = "FAIL"
time.sleep(1)
wd.find_element(By.XPATH, '//android.widget.LinearLayout[@content-desc="타이머"]/android.widget.RelativeLayout/android.widget.TextView').click()
time.sleep(1)
try:
# element = wd.find_element(By.XPATH, '/hierarchy/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.LinearLayout/android.widget.RelativeLayout/android.widget.ScrollView/android.widget.RelativeLayout/android.widget.RelativeLayout')
element = wd.find_element(By.XPATH, '/hierarchy/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.LinearLayout/android.widget.RelativeLayout/android.widget.ScrollView/android.view.ViewGroup')
ws['D8'] = "PASS"
except NoSuchElementException:
ws['D8'] = "FAIL"
time.sleep(1)
wb.save('clocktestcase0917.xlsx')
* 마지막 try문의 주석 부분을 활성화하고 바로 아랫줄을 주석 처리하면 결과가 FAIL로 나온다.


728x90
'Appium' 카테고리의 다른 글
[Appium] 시나리오 (0) | 2023.11.10 |
---|---|
[Appium] 뮤직 플레이어 제어 (0) | 2023.09.12 |