[๋ชจ๋ฐ”์ผ ๋งคํฌ๋กœ] ๋‰ด์Šค URL ํด๋ฆญ ๋ฐ ๋ชจ๋ฐ”์ผ ํ™”๋ฉด ์บก์ณ ์ž๋™ํ™”, ๋ชจ๋ฐ”์ผ ์Šคํฌ๋ฆฐ ์บก์ณ, selenium + appium + screen capture ์ €์žฅํ•˜๊ธฐ
๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ
๋””์ง€ํ„ธ ๊ฟ€ํŒ

[๋ชจ๋ฐ”์ผ ๋งคํฌ๋กœ] ๋‰ด์Šค URL ํด๋ฆญ ๋ฐ ๋ชจ๋ฐ”์ผ ํ™”๋ฉด ์บก์ณ ์ž๋™ํ™”, ๋ชจ๋ฐ”์ผ ์Šคํฌ๋ฆฐ ์บก์ณ, selenium + appium + screen capture ์ €์žฅํ•˜๊ธฐ

by ์ผ์ƒ์„ ๊ณต์œ ํ•ฉ๋‹ˆ๋‹ค 2022. 9. 19.

appium์„ ์•Œ๊ณ  ๋ถ€ํ„ฐ๋Š” ๋ชจ๋ฐ”์ผ์—์„œ ํ•  ์ˆ˜ ์žˆ๋Š” ๊ฒƒ๋“ค์ด ๋งŽ์•„์กŒ์–ด์š”. ์ฒ˜์Œ ๋ฐฐ์šธ ๋• ๋ชฐ๋ž๋Š”๋ฐ ํ•˜๋‹ค๋ณด๋‹ˆ, ๋ชจ๋ฐ”์ผ ๋งคํฌ๋กœ๋Š” ๋‹ค๋“ค ์ด๊ฑธ๋กœ ๊ตฌํ˜„ํ•˜๊ฒ ๊ตฌ๋‚˜ ๋ผ๋Š” ์ƒ๊ฐ์„ ํ•˜๊ฒŒ ๋˜์—ˆ๋‹ต๋‹ˆ๋‹ค. ๋ผ๋–ผ๋Š” ์ด๋Ÿฐ๊ฒŒ ์žˆ์—ˆ๋‚˜ ์‹ถ์ง€๋งŒ selenium์ด ์ด๋ ‡๊ฒŒ ๋งŽ์€ ๋ณ€ํ™”๋ฅผ ๊ฐ€์ ธ๋‹ค ์ฃผ๋Š” ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ์˜€๋„ค์š”.

์˜ค๋Š˜์˜ ์ฃผ์ œ๋Š” ๋งํฌ ํด๋ฆญ ๋ฐ ๋ชจ๋ฐ”์ผ ํ™”๋ฉด ์Šคํฌ๋ฆฐ ์บก์ณ ๋œจ๋Š” ๋ฐฉ๋ฒ•์ž…๋‹ˆ๋‹ค. ์ œ์ผ ์ข‹์•˜๋˜ ๊ฒƒ์€ ์Šคํฌ๋ฆฐ์บก์ณ ๋œฌ ํ™”๋ฉด์ด PC ํŠน์ • ํด๋”์— ๋ฐ”๋กœ ์ €์žฅ๋˜๊ฒŒ๋” ํ•  ์ˆ˜ ์žˆ์—ˆ๋˜ ๊ฒƒ์ด์—์š”. ์ •๋ง ์ข‹์€ ์žฅ์ ์ธ ๊ฑด, ๋Œ€ํฐ ์šฉ๋Ÿ‰๋„ ๊ด€๋ฆฌ ํ•  ์ˆ˜ ์žˆ๊ณ , ๋˜ ์ œ๊ฐ€ ์›ํ•˜๋Š” ์ด๋ฏธ์ง€๋ฅผ ํด๋”๋ณ„๋กœ ์ •๋ฆฌ๋„ ํ•  ์ˆ˜ ์žˆ๋‹ค๋Š” ๊ฒ๋‹ˆ๋‹ค. ์˜ค๋Š˜์€ ์ด๋ฏธ์ง€ ์ €์žฅ์ด์ง€๋งŒ, ํ™”๋ฉด ๋…นํ™”๋„ ๊ฐ€๋Šฅํ•˜์—ฌ, ๋‹ค์Œ ๋ฒˆ์—” ํ™”๋ฉด ๋…นํ™” ๋ฐฉ๋ฒ•๋„ ๊ฐ€์ ธ์™€ ๋ณผ ์˜ˆ์ •์ž…๋‹ˆ๋‹ค.

์†Œ์Šค์ฝ”๋“œ

from selenium.webdriver.common.by import By
from appium import webdriver
from time import sleep
import os

# ํŒŒ์ผ ์ €์žฅํ•  ๊ฒฝ๋กœ ์„ค์ •ํ•˜๊ธฐ
SCREEN_PATH = '%s/' % os.getcwd() + "screenshot/"


# SLEEP TIME
PAUSE_TIME = 0.1
LOADING_WAIT_TIME = 1
LOADING_SCROLL_WAIT_TIME = 3
LOADING_TAB_WAIT_TIME = 5

#์•ˆ๋“œ๋กœ์ด๋“œ ์ •๋ณด ์ž…๋ ฅํ•˜๊ธฐ
caps = {}
caps["platformName"] = "Android"
caps["appium:platformVersion"] = "6.0.1"
caps["appium:deviceName"] = "S916N"
caps["appium:app"] = "์‹คํ–‰ํ•  ์•ฑ ์„ค์น˜ ํŒŒ์ผ ๊ฒฝ๋กœ(.apk)"
caps["appium:automationName"] = "Appium"
caps["appium:newCommandTImeout"] = 300
caps["appium:appPackage"] = "com.kakao.talk"
caps["appium:appActivity"] = "์‹คํ–‰ํ•  ์•ฑ ๋ฉ”์ธ Activity"
caps["appium:udid"] = "ํœด๋Œ€ํฐ udid"
caps["appium:noReset"] = "true"
caps["appium:fullReset"] = "false"
caps["appium:ensureWebviewsHavePages"] = True
caps["appium:nativeWebScreenshot"] = True
caps["appium:newCommandTimeout"] = 3600
caps["appium:connectHardwareKeyboard"] = True


#๋ณผ ์ฝ˜ํ…์ธ  ๋งํฌ ์ •๋ณด
with open('/Users/program/info_screenshot.json') as json_file:
    info = json.load(json_file)

#appium ์„œ๋ฒ„ ์—ฐ๋™
driver = webdriver.Remote("http://0.0.0.0:4723/wd/hub", caps)


#์นด์นด์˜คํ†ก ์‹คํ–‰ ํ›„ ์นœ๊ตฌ ํƒญ ์„ ํƒ 
ele = driver.find_element(By.XPATH, value ='//android.widget.RelativeLayout[@content-desc="์นœ๊ตฌ ํƒญ"]')
ele.click()

sleep(LOADING_TAB_WAIT_TIME)

#๊ฒ€์ƒ‰ ๋ฒ„ํŠผ ํด๋ฆญ
ele = driver.find_element(By.XPATH, value='//android.widget.TextView[@content-desc="๊ฒ€์ƒ‰ ๋ฒ„ํŠผ"]')
ele.click()

sleep(LOADING_WAIT_TIME)

#๋‚ด์ด๋ฆ„ ๊ฒ€์ƒ‰(๋ณธ์ธํ•œํ…Œ ๋งํฌ ๋ณด๋‚ด๊ธฐ)
ele = driver.find_element(By.XPATH, value='/hierarchy/android.widget.FrameLayout/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.LinearLayout/android.view.ViewGroup/android.widget.LinearLayout/android.widget.LinearLayout/android.widget.EditText')
ele.send_keys("๋ณธ์ธ ์นด์นด์˜คํ†ก ์ด๋ฆ„")

sleep(LOADING_WAIT_TIME)

#์นด์นด์˜คํ†ก ํ”„๋กœํ•„ ํด๋ฆญํ•˜๊ธฐ
ele = driver.find_element(By.ID, value='com.kakao.talk:id/profile')
ele.click()    

sleep(LOADING_WAIT_TIME)
sleep(LOADING_WAIT_TIME)

#1:1 ์ฑ„ํŒ… ๊ฑธ๊ธฐ
ele = driver.find_element(By.XPATH, value='//android.widget.RelativeLayout[@content-desc="1:1์ฑ„ํŒ… ๋ฒ„ํŠผ"]/android.widget.ImageView')
ele.click()  

#์ฑ„ํŒ…์–‘์— ๋”ฐ๋ผ ์กฐ๊ธˆ ๋กœ๋”ฉ์ด ๊ธธ์–ด์ง€๋”๋ผ๊ตฌ์š”
sleep(LOADING_TAB_WAIT_TIME)
sleep(LOADING_TAB_WAIT_TIME)

#์นด์นด์˜คํ†ก ๋ฉ”์‹œ์ง€์— ๋‰ด์Šค๋งํฌ ๋ณด๋‚ด๊ธฐ
ele = driver.find_element(By.ID, value='com.kakao.talk:id/message_edit_text')
ele.send_keys("๋‰ด์Šค๋งํฌ")
sleep(LOADING_SCROLL_WAIT_TIME)

#๋ฉ”์‹œ์ง€ ์ „์†ก
ele = driver.find_element(By.ID, value='com.kakao.talk:id/send')
ele.click()

sleep(LOADING_WAIT_TIME)
sleep(LOADING_WAIT_TIME)

#๋ฉ”์‹œ์ง€ ๋งํฌ ํด๋ฆญํ•˜๊ธฐ, ๋ฐฉ๊ธˆ ๋ฉ”์‹œ์ง€ ๋ณด๋ƒˆ๊ธฐ ๋•Œ๋ฌธ์— ๋งˆ์ง€๋ง‰ message ํด๋ฆญํ•˜๋Š” ๋ฐฉ๋ฒ•
ele_arry= driver.find_elements(By.ID, value='com.kakao.talk:id/message')

index = len(ele_arry)
ele_arry[index-1].click()

#ํ˜„์žฌ ํ™”๋ฉด ์บก์ณ
isSave_content = driver.save_screenshot(SCREEN_PATH + "ํŒŒ์ผ๋ช….png")
sleep(LOADING_WAIT_TIME)

#๋‹ซ๊ธฐ ๋ฒ„ํŠผ ์žˆ์„ ๊ฒฝ์šฐ ๋‰ด์Šค๋งํฌ ๋‹ซ๊ธฐ
ele_close = driver.find_element(By.ID, "com.kakao.talk:id/close")
ele_close.click()

 

์ € ๊ฐ™์€ ๊ฒฝ์šฐ ๊ด€์‹ฌ ์žˆ๋Š” ๊ธฐ์‚ฌ ๋งํฌ๋ฅผ ๋‹ค ์Šคํฌ๋žฉํ•˜์—ฌ, ๊ตฌ๊ธ€ ๋ฌธ์„œ์— ์ €์žฅํ•˜๊ณ  ์žˆ๋‹ค๊ฐ€, ๊ตฌ๊ธ€๋ฌธ์„œ์—์„œ ํ•ด๋‹น ๋งํฌ ๋ฆฌ์ŠคํŠธ๋ฅผ ๊ฐ€์ง€๊ณ  ์™€์„œ ํ™”๋ฉด ์บก์ณ๋ฅผ ํ•˜๋„๋ก ํ•˜์˜€์Šต๋‹ˆ๋‹ค. ์˜ˆ์ „์— ์‹ ๋ฌธ๋ณด๋‹ค๊ฐ€ ๊ด€์‹ฌ ์žˆ๋Š” ๊ธฐ์‚ฌ๋Š” ๋ชจ์•„์„œ ๋ณด๊ด€ํ•˜์˜€๋Š”๋ฐ ์ถ”์–ต์ด ์ƒˆ๋ก์ƒˆ๋กํ•˜๋„ค์š”. ์•„๋‚ ๋กœ๊ทธ์—์„œ ๋””์ง€ํ„ธ๋กœ ๋ณ€ํ™˜๋งŒ ํ–ˆ์„ ๋ฟ์ด๋„ค์š”.

ํ…Œ์ŠคํŠธ ์˜ˆ์ œ๋กœ๋Š” ์ œ๊ฐ€ ์‚ฌ์šฉํ•˜๋Š” ์นด์นด์˜ค๋ทฐ ์ฑ„๋„์„ ์ด์šฉํ•˜์˜€๋‹ต๋‹ˆ๋‹ค. ๋ชจ๋ฐ”์ผ์—์„œ ๋งคํฌ๋กœ๋ฅผ ํ•˜๋‹ค๋ณด๋‹ˆ, ์•ˆ๋“œ๋กœ์ด๋“œ ํฐ ์‚ฌ์–‘ ์ข‹์€ ๊ฑธ ๊ตฌ์ž…ํ•˜๊ณ  ์‹ถ์–ด์กŒ์–ด์š”. ๋ฐฐ๋ณด๋‹ค ๋ฐฐ๊ผฝ์ด ๋” ํฐ ์ผ€์ด์Šค๊ฐ€ ๋˜๋Š”๊ตฐ์š”.

IT ์ผ์ƒ ์ƒํ™œ, ๋ชจ๋“  ๋ฐ˜๋ณต ์ ์ธ ์—…๋ฌด๋ฅผ ํŽธ๋ฆฌํ•˜๊ฒŒ ์ž๋™ํ™”ํ•˜๋Š” ๊ทธ๋‚ ๊นŒ์ง€ ์—ด์‹ฌํžˆ ์ •๋ณด ๊ณต์œ ๋“œ๋ ค์š”. APPIUM์€ ๋™์˜์ƒ์œผ๋กœ๋„ ์ œ๊ณตํ•ด๋“œ๋ฆด ์˜ˆ์ •์ž…๋‹ˆ๋‹ค.

๊ฒฐ๊ณผ๋ฌผ

 

* ๊ธฐ์‚ฌ ๋‚ด์šฉ ๊ณต์œ ๊ฐ€ ํ˜น์‹œ๋‚˜ ๋ฌธ์ œ ์ƒ๊ธธ๊นŒ ํ•˜์—ฌ ํŽ˜์ด์ง€ ์ œ์ผ ์•„๋ž˜๋กœ ๋‚ด๋ ค ํ™”๋ฉด ์บก์ณํ•œ ์˜ˆ์ œ์ž…๋‹ˆ๋‹ค

 

 

[์นด์นด์˜ค๋ทฐ ์ž๋™ํ™”] ์นด๋ทฐ ๊ด€๋ฆฌ ์ž๋™ํ™”๋ฅผ ์œ„ํ•œ appium ์‚ฌ์šฉ ๋ง›๋ณด๊ธฐ 1๋‹จ๊ณ„

์˜ˆ๋ž‘์ด๊ฐ€ ์ด๋Ÿฐ ํ…Œ์ŠคํŠธ ์ž๋™ํ™” ํ”„๋กœ๊ทธ๋žจ์ด ์žˆ๋‹ค๋Š” ๊ฑธ ์•Œ๋ ค์ค˜์„œ ์ ‘ํ•˜๊ฒŒ ๋˜์—ˆ์Šต๋‹ˆ๋‹ค. ์ฒ˜์Œ ํ•ด๋ณด๋Š” ๊ฒƒ์ด๋ผ์„œ ๋‚ฏ์„ค์—ˆ์ง€๋งŒ, ๋‹ค๋ฅธ ์–ธ์–ด๋“ค์ฒ˜๋Ÿผ ์ฒซ ์…‹ํŒ…๋งŒ ์ž˜ํ•ด๋ณด๋ฉด ๋‹ค ๋น„์Šทํ•˜๊ณ  ๊ฒฐ๊ตญ์—” python์œผ๋กœ ์ฝ”๋”ฉ

odaily.tistory.com

 

๋Œ“๊ธ€