본문 바로가기

Server

Ubuntu 22.0.4 + Robot + SeleniumLibrary 환경 만들기

728x90

우분투는 도커를 사용했다 (UI 가 없다)
우분투 업데이트를 진행한 적 없다면 하자

# apt-get update

 

내 우분투가 python 3.9 를 설치할 수 있는지 확인한다

# apt-cache search python3.9
python3-llfuse - Python 3 bindings for the low-level FUSE API

 

없다면 다음을 입력하라

# apt install software-properties-common
# add-apt-repository ppa:deadsnakes/ppa

 

이 상태에서 python 이 있는지 확인하면 있다

# python3 -V
Python 3.10.4
# pip -V
bash: pip: command not found

 

내가 원하는 Python 버전은 3.9 이며, pip 도 필요하다
따라서 softwoare-properties-common 을 설치하면서 함께 설치된 python 3.10 버전은 사용하지 않을 계획이다

이번엔 내 우분투가 python 3.9 를 설치할 수 있는지 확인하자

# apt-cache search python3.9
python3-llfuse - Python 3 bindings for the low-level FUSE API
idle-python3.9 - IDE for Python (v3.9) using Tkinter
libpython3.9 - Shared Python runtime library (version 3.9)
libpython3.9-dbg - Debug Build of the Python Interpreter (version 3.9)
libpython3.9-dev - Header files and a static library for Python (v3.9)
libpython3.9-minimal - Minimal subset of the Python language (version 3.9)
libpython3.9-stdlib - Interactive high-level object-oriented language (standard library, version 3.9)
libpython3.9-testsuite - Testsuite for the Python standard library (v3.9)
python3.9 - Interactive high-level object-oriented language (version 3.9)
python3.9-dbg - Debug Build of the Python Interpreter (version 3.9)
python3.9-dev - Header files and a static library for Python (v3.9)
python3.9-distutils - distutils package for Python (version 3.9)
python3.9-examples - Examples for the Python language (v3.9)
python3.9-full - Python Interpreter with complete class library (version 3.9)
python3.9-gdbm - GNU dbm database support for Python (version 3.9)
python3.9-gdbm-dbg - GNU dbm database support for Python (version 3.9 debug extension)
python3.9-lib2to3 - lib2to3 package for Python (version 3.9)
python3.9-minimal - Minimal subset of the Python language (version 3.9)
python3.9-tk - Tkinter - Writing Tk applications with Python (version 3.9)
python3.9-tk-dbg - Tkinter - Writing Tk applications with Python (version 3.9 debug extension)
python3.9-venv - Interactive high-level object-oriented language (pyvenv binary, version 3.9)

 

이번엔 중간에 python3.9 가 보인다
설치를 진행한다

# apt-get install python3.9 -y

...
...

Please select the geographic area in which you live. Subsequent configuration questions will narrow this down by presenting a list of cities, representing the time
zones in which they are located.

  1. Africa  2. America  3. Antarctica  4. Australia  5. Arctic  6. Asia  7. Atlantic  8. Europe  9. Indian  10. Pacific  11. US  12. Etc
Geographic area: 6

Please select the city or region corresponding to your time zone.

  1. Aden      11. Baku        21. Damascus     31. Hong_Kong  41. Kashgar       51. Makassar      61. Pyongyang  71. Singapore      81. Ujung_Pandang
  2. Almaty    12. Bangkok     22. Dhaka        32. Hovd       42. Kathmandu     52. Manila        62. Qatar      72. Srednekolymsk  82. Ulaanbaatar
  3. Amman     13. Barnaul     23. Dili         33. Irkutsk    43. Khandyga      53. Muscat        63. Qostanay   73. Taipei         83. Urumqi
  4. Anadyr    14. Beirut      24. Dubai        34. Istanbul   44. Kolkata       54. Nicosia       64. Qyzylorda  74. Tashkent       84. Ust-Nera
  5. Aqtau     15. Bishkek     25. Dushanbe     35. Jakarta    45. Krasnoyarsk   55. Novokuznetsk  65. Rangoon    75. Tbilisi        85. Vientiane
  6. Aqtobe    16. Brunei      26. Famagusta    36. Jayapura   46. Kuala_Lumpur  56. Novosibirsk   66. Riyadh     76. Tehran         86. Vladivostok
  7. Ashgabat  17. Chita       27. Gaza         37. Jerusalem  47. Kuching       57. Omsk          67. Sakhalin   77. Tel_Aviv       87. Yakutsk
  8. Atyrau    18. Choibalsan  28. Harbin       38. Kabul      48. Kuwait        58. Oral          68. Samarkand  78. Thimphu        88. Yangon
  9. Baghdad   19. Chongqing   29. Hebron       39. Kamchatka  49. Macau         59. Phnom_Penh    69. Seoul      79. Tokyo          89. Yekaterinburg
  10. Bahrain  20. Colombo     30. Ho_Chi_Minh  40. Karachi    50. Magadan       60. Pontianak     70. Shanghai   80. Tomsk          90. Yerevan
Time zone: 69

 

설치하다보면 지역과 시간대를 물어본다
나는 아시아와 서울에 있으므로, 6, 69 를 순서대로 입력하고 설치를 완료한다

파이썬이 잘 설치 되었는지 확인하자

# python -V
bash: python: command not found
# python3 -V
Python 3.10.4
# python3.9 -V
Python 3.9.13

 

python3.9 는 잘 설치된 것 같지만 python 명령어를 입력했을 때 python3.9 가 동작하도록 하고싶다

python3.9 디렉터리 위치로 이동 후 링크 파일을 생성해준다

# which python3.9
/usr/bin/python3.9
# cd /usr/bin/
# ll python*
lrwxrwxrwx 1 root root      10 Mar 25 21:41 python3 -> python3.10*
-rwxr-xr-x 1 root root 5901416 Apr  2 18:04 python3.10*
-rwxr-xr-x 1 root root 5302896 May 24 06:57 python3.9*
# rm python3
# ln -s python3.9 python
# ln -s python3.9 python3
# ll python*
lrwxrwxrwx 1 root root       9 Jun 30 10:07 python -> python3.9*
lrwxrwxrwx 1 root root      10 Mar 25 21:41 python3 -> python3.9*
-rwxr-xr-x 1 root root 5901416 Apr  2 18:04 python3.10*
-rwxr-xr-x 1 root root 5302896 May 24 06:57 python3.9*

 

이제 pip 를 설치해줘야 한다.
단순하게 apt-get install python3-pip 를 하게 되면 python3.10 의 pip 가 설치된다.

따라서 아래를 입력한다

# apt-get install curl
# apt-get install python3.9-distutils
# curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py
# python3 get-pip.py
# pip -V
pip 22.1.2 from /usr/local/lib/python3.9/dist-packages/pip (python 3.9)
# pip3 -V
pip 22.1.2 from /usr/local/lib/python3.9/dist-packages/pip (python 3.9)

 

이제 Robot Framework 를 설치한다

# pip install robotframework
# pip install robotframework-seleniumlibrary

 

Selenium 브라우저로는 Chrome 을 사용할 예정이다
Chrome 을 다운로드하고 설치한다

# apt-get install wget
# wget https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb 
# apt install ./google-chrome-stable_current_amd64.deb -y
# google-chrome --version

 

크롬 드라이버는 크롬 버전과 같은 것을 다운로드 받아 사용한다
https://chromedriver.chromium.org/downloads

위 주소에서 같은 크롬 버전을 찾아 링크를 복사한다

# wget https://chromedriver.storage.googleapis.com/103.0.5060.53/chromedriver_linux64.zip
# unzip chromedriver_linux64.zip

 

크롬 드라이버를 설치했으면 chromedriver 와 같은 경로에 다음과 같이 간단한 robot 파일을 만들고 실행해보자

*** Settings ***
Library           SeleniumLibrary

*** Test Cases ***
Test Naver Open
    Open Browser    url=https://www.naver.com/    browser=headlesschrome    options=add_argument("--no-sandbox");add_argument("--disable-dev-shm-usage")    executable_path=./chromedriver
    Set Window Size    width=1351    height=780
    Sleep    3
    Close Browser

 

robot 파일 실행

# robot ./
==============================================================================
Robot
==============================================================================
Test Naver Open                                                       | PASS |
------------------------------------------------------------------------------
Robot                                                                 | PASS |
1 test, 1 passed, 0 failed
==============================================================================
Output:  /root/robot/output.xml
Log:     /root/robot/log.html
Report:  /root/robot/report.html

 

완료

 

 

 

728x90