오늘은 appium을 해보려다가 발생했던 트러블 슈팅을 기록하려고 한다. 아래 명령어를 수행하였으나 아마도 Node 버전이 문제일 것이라면서 설치를 거부당했다.
sudo npm i -g appium
npm WARN notsup Unsupported engine for consola@3.2.3: wanted: {"node":"^14.18.0 || >=16.10.0"} (current: {"node":"14.17.4","npm":"6.14.14"})
npm WARN notsup Not compatible with your version of node/npm: consola@3.2.3
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! appium@2.5.2 postinstall: `node ./scripts/autoinstall-extensions.js`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the appium@2.5.2 postinstall script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
그래서 node 를 업그레이드해주도록 한다. 일단 현재 설치되어 있는 버전을 확인하자. 나는 설치된 버전이 (화면에도 보이지만) 14.17.4였기에 최신 버전으로 업그레이드를 하기로 했다.
node -v
sudo npm install n
sudo npm install 14 // 14 의 최신버전 설치
####
installing : node-v14.21.3
mkdir : /usr/local/n/versions/node/14.21.3
fetch : https://nodejs.org/dist/v14.21.3/node-v14.21.3-darwin-x64.tar.xz
copying : node/14.21.3
installed : v14.21.3 (with npm 6.14.18)
자, 이제 다시 appium 설치를 시도해보자.
sudo npm i -g appium
###############
###blah blah###
###############
+ appium@2.5.2
added 454 packages from 501 contributors in 46.833s
자, 설치가 완료되면 실행도 해봅시다.
$ appium
[Appium] Welcome to Appium v2.5.2
[Appium] The autodetected Appium home path: /Users/1004676/.appium
[Appium] Appium REST http interface listener started on http://0.0.0.0:4723
[Appium] You can provide the following URLs in your client code to connect to this server:
[Appium] http://127.0.0.1:4723/ (only accessible from the same host)
[Appium] http://10.202.201.87:4723/
[Appium] No drivers have been installed in /Users/1004676/.appium. Use the "appium driver" command to install the one(s) you want to use.
[Appium] No plugins have been installed. Use the "appium plugin" command to install the one(s) you want to use.
실행도 잘 된 것 같은데 뭔가 허전하긴 하지만 이제 추가로 설치해야 하는 플러그인들을 설치해 봅시다. 일단은 안드로이드로 시작을 해봅시다. 저는 갤럭시를 써서 그렇게 수행하였습니다. 간단하게 터미널 하나 더 열어서 설치 명령어 수행해 봅니다.
$ appium driver install uiautomator2
✔ Checking if 'appium-uiautomator2-driver' is compatible
✔ Installing 'uiautomator2' using NPM install spec 'appium-uiautomator2-driver'
ℹ Driver uiautomator2@3.1.0 successfully installed
- automationName: UiAutomator2
- platformNames: ["Android"]
Install the UiAutomator2 Driver - Appium Documentation
Install the UiAutomator2 Driver You can't do much with Appium unless you have a driver, which is an interface that allows Appium to automate a particular platform. Info For this quickstart guide, we're going to be automating an app on the Android platform,
appium.io
스크립트 작성을 위해서는 xpath라는 걸 알아내야 하는데 appium-inspector를 이용해 봅시다. 아래 링크를 참조하여 os버전 맞춰서 다운로드하고 설치하시면 됩니다.
Releases · appium/appium-inspector
A GUI inspector for mobile apps and more, powered by a (separately installed) Appium server - appium/appium-inspector
github.com
세션 정보는 json을 수정하고 나면 연결이 되는데, 혹시 디폴트 앱이 설치하다가 타임아웃이 나면 터미널에서 명령어 보고 따라 치시면 됩니다. 앱이 커서 그런가 수십 분씩 걸리는 작업들이 있어요.
{
"platformName": "Android",
"appium:automationName": "uiautomator2",
"appium:deviceName": "device name"
}
세션이 연결되었다면 이제 xpath를 알아내고 준비해 두었던 언어로 스크립트를 작성해 봅시다. 저는 python으로 작성하려고 VS Code를 준비했습니다. 일단 python 스크립트를 작성하기 위해서 아래 명령어로 환경 구성을 해줍니다.
pip install Appium-Python-Client
아래 링크에 있는 테스트 코드를 참고하여 잘 작성하고 실행을 준비해 봅시다.
Write a Test (Python) - Appium Documentation
Write a Test (Python) The Appium Python Client is an official Appium client in Python, which is available via pypi under the Appium-Python-Client package name. It inherits from the Selenium Python Binding, so installing the Appium Python Client includes th
appium.io
테스트 스크립트 예제를 어디선가 복사해서 잘 실행되나 보려고 하였으나 아래와 같은 오류가 발생하면 아래를 참고하여 진행하시면 됩니다.
ModuleNotFoundError: No module named 'appium'
$ git clone https://github.com/appium/python-client.git
cd cd python-client
python setup.py install
자, 이제 홈화면에 배치되어 있는 네이버 앱을 한 번 구동해 보도록 하는 코드를 작성해 보겠습니다. appium server를 구동하여 그 config (ip:port 등)를 맞춰주시고 진행하시면 됩니다.
import unittest
from appium import webdriver
from appium.options.android import UiAutomator2Options
from appium.webdriver.common.appiumby import AppiumBy
capabilities = dict(
platformName='Android',
automationName='uiautomator2',
deviceName='Android'
)
appium_server_url = 'http://localhost:4723'
class TestAppium(unittest.TestCase):
def setUp(self) -> None:
self.driver = webdriver.Remote(appium_server_url, options=UiAutomator2Options().load_capabilities(capabilities))
def tearDown(self) -> None:
if self.driver:
self.driver.quit()
def test_run_naver_app(self) -> None:
el = self.driver.find_element(by=AppiumBy.XPATH, value='//*[@text="NAVER"]')
el.click()
if __name__ == '__main__':
unittest.main()
읽어주셔서 감사합니다. 혹시 궁금하시거나 틀린 내용이 있거나 수정할 점이 있으면 댓글 남겨주세요.
댓글