[英]Robot Framework using Python 3.6.8 on Ubuntu 18.04.2 LTS docker container
我一直無法找到在 Ubuntu v18.x 上使用 Python v3.x 運行 Robot Framework 的良好公共映像。 一位同事構建了一個圖像,我將其用作基礎,但我的機器人腳本無法連接到該站點,而且我一直在旋轉輪子太久了。 是時候向社區伸出援手了!
我有一個簡單的機器人框架腳本(見下文),它連接到一個站點(chrome headless)並驗證標題。 它可以在我的 Ubuntu 工作站上找到,但是當我在該工作站上運行 docker 容器時 - 它只是無法連接。 起初,我以為是管道問題,但事實並非如此。 以下是我與適用於我的工作站但不適用於容器的機器人代碼一起采取的步驟:
確認連接從容器工作:
curl -o /dev/null -s -w %{http_code} https://www.google.com
(返回 200)
確保我的工作站和容器上的 python3、pip3 和 ubuntu 版本相同
確保 pip3 庫是相同的(除了一些我知道我不需要的庫,是的,我知道我安裝的庫比我需要的要多) - 這是pip3 freeze
命令的列表:
asn1crypto==0.24.0
certifi==2020.4.5.1
chardet==3.0.4
coverage==5.2
cryptography==2.1.4
decorator==4.4.2
idna==2.6
importlib-metadata==1.7.0
jsonpath-rw==1.4.0
jsonpath-rw-ext==1.2.2
keyring==10.6.0
keyrings.alt==3.0
pbr==5.4.5
pluggy==0.13.1
ply==3.11
py==1.9.0
pycrypto==2.6.1
pygobject==3.26.1
pyxdg==0.25
requests==2.23.0
robotframework==3.1.1
robotframework-jsonlibrary==0.3.1
robotframework-requests==0.7.0
robotframework-seleniumlibrary==4.1.0
SecretStorage==2.3.1
selenium==3.141.0
six==1.11.0
tox==3.0.0
urllib3==1.22
virtualenv==16.7.10
zipp==3.1.0
現在機器人腳本(再次在我的工作站上工作,而不是在容器上)
*** Settings ***
Documentation
... Basic Test for Google.com in headless mode
Library Collections
Library DateTime
Library Dialogs
Library OperatingSystem
Library SeleniumLibrary
Library String
Library RequestsLibrary
Library JSONLibrary
Suite Setup Setup Environment and Open Browser
Suite Teardown Close All Browsers
*** Variables ***
${BROWSER} HeadlessChrome
${SITE_URL} https://www.google.com
*** Test Cases ***
Title Test
Title Should Be Google
*** Keywords ***
Open Chrome Browser To URL
[Documentation] Open Chrome browser and navigate to URL with browser options set
[Tags] open_chrome_browser
${browserOptions} Run Keyword If 'Headless' in '${BROWSER}' Set Headless Chrome Options
Create Webdriver Chrome chrome_options=${browserOptions}
Go To ${SITE_URL}
Maximize Browser Window
Browser timeout and speed
[Documentation]
... Set browser timeout and speed
Set Selenium Timeout 30s
Set Selenium Speed 0s
Set Headless Chrome Options
[Documentation]
... Set the Chrome options for running in headless mode. Restrictions do not apply to headless mode.
[Tags] headless_chrome_options
${chromeOptions} Evaluate sys.modules['selenium.webdriver'].ChromeOptions() sys
Call Method ${chromeOptions} add_argument test-type
Call Method ${chromeOptions} add_argument --headless
Call Method ${chromeOptions} add_argument --disable-extensions
Call Method ${chromeOptions} add_argument --disable-gpu
Call Method ${chromeOptions} add_argument --disable-dev-shm-usage
Call Method ${chromeOptions} add_argument --no-sandbox
[Return] ${chromeOptions}
Setup Environment and Open Browser
[Documentation]
... This keyword will establish the environment variables and open a browser
[Tags] simple_test
Open Chrome Browser To URL
Browser timeout and speed
robot -b debug.log testgoogle.robot
,調試日志顯示了這個有趣的部分:20200820 11:40:53.410 - DEBUG - Traceback (most recent call last):
File "/usr/local/lib/python3.6/dist-packages/SeleniumLibrary/__init__.py", line 467, in run_keyword
return DynamicCore.run_keyword(self, name, args, kwargs)
File "/usr/local/lib/python3.6/dist-packages/SeleniumLibrary/base/robotlibcore.py", line 102, in run_keyword
return self.keywords[name](*args, **kwargs)
File "/usr/local/lib/python3.6/dist-packages/SeleniumLibrary/keywords/element.py", line 569, in click_link
self.find_element(locator, tag='link').click()
File "/usr/local/lib/python3.6/dist-packages/SeleniumLibrary/base/context.py", line 74, in find_element
return self.element_finder.find(locator, tag, True, required, parent)
File "/usr/local/lib/python3.6/dist-packages/SeleniumLibrary/locators/elementfinder.py", line 76, in find
% (element_type, locator))
20200820 11:40:53.410 - INFO - +--- END KW: SeleniumLibrary.Click Link (74)
20200820 11:40:53.410 - INFO - +-- END KW: LoginHandler.User Logout (75)
關於故障排除步驟的任何想法或建議?
非常感謝!
我仍然無法讓它直接與 ChromeDriver 一起使用,但是,我能夠使用 selenium grid 讓它工作:
https://selenium-release.storage.googleapis.com/3.141/selenium-server-standalone-3.141.59.jar
我啟動了一個集線器(在容器中),然后直接在運行測試的容器上啟動了一個節點,它工作正常。 我仍在構建運行節點的容器(雖然它不能作為單獨的容器工作......我必須添加一些配置)。 以下是使用遠程 chrome 驅動程序的機器人框架測試套件:
*** Settings ***
Documentation
... This is a simple robot test to open a browser and check the title of a given website.
Library Collections
Library DateTime
Library Dialogs
Library OperatingSystem
Library SeleniumLibrary
Library String
Library RequestsLibrary
Suite Setup Setup Environment and Open Browser
Suite Teardown Close All Browsers
*** Variables ***
${BROWSER} HeadlessChrome
${SITE_URL} https://www.google.com
*** Test Cases ***
Title Test
Title Should Be Google
*** Keywords ***
Open Chrome Browser To URL
[Documentation] Open Chrome browser and navigate to URL with browser options set
[Tags] open_chrome_browser
${chromeOptions} Evaluate sys.modules['selenium.webdriver'].ChromeOptions() sys, selenium.webdriver
Call Method ${chromeOptions} add_argument --headless
${ws}= Set Variable window-size=1920, 1080
Call Method ${chromeOptions} add_argument ${ws}
Call Method ${chromeOptions} add_argument --disable-extensions
Call Method ${chromeOptions} add_argument --disable-gpu
Call Method ${chromeOptions} add_argument --disable-dev-shm-usage
Call Method ${chromeOptions} add_argument --ignore-certificate-errors
${remoteOptions}= Call Method ${chromeOptions} to_capabilities
Create Webdriver Remote command_executor=http://<IP ADDR OF HUB>:4444/wd/hub desired_capabilities=${remoteOptions}
Go To ${SITE_URL}
Maximize Browser Window
Browser timeout and speed
[Documentation]
... Set browser timeout and speed
Set Selenium Timeout 30s
Set Selenium Speed 0s
Setup Environment and Open Browser
[Documentation]
... This keyword will establish the environment variables and open a browser
[Tags] simple_test
Open Chrome Browser To URL
Browser timeout and speed
現在要弄清楚如何在容器中運行節點...
經過更多研究,我只是使用公共 Selenium Grid 3 集線器和節點來解決我的問題。
https://github.com/SeleniumHQ/docker-selenium/tree/selenium-3/Hub
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.