部署分布式 UI 自动化测试环境
docker run --name hub -d -p 5442-5444:4442-4444 selenium/hub:4.0.0-rc-2-prerelease-20210923
docker run --name node -p 5902:5900 -d -e SE_EVENT_BUS_HOST=ke.hogwarts.ceshiren.com -e SE_NODE_MAX_SESSIONS=20 -e SE_NODE_OVERRIDE_MAX_SESSIONS=true -e SE_EVENT_BUS_PUBLISH_PORT=5442 -e SE_EVENT_BUS_SUBSCRIBE_PORT=5443 -v /dev/shm:/dev/shm selenium/node-chrome:4.0.0-rc-2-prerelease-20210923
- vnc 密码:secret
连接 grid 的代码
from selene.support.shared import browser, config
from selenium.webdriver import Chrome
import selenium.webdriver
if __name__ == '__main__':
config.browser_name = 'chrome'
config.base_url = "http://ke.hogwarts.ceshiren.com:5444"
config.timeout = 10
config.save_screenshot_on_failure = False
option = selenium.webdriver.ChromeOptions()
option.add_argument("--disable-infobars")
option.add_argument("--disable-dev-shm-usage")
option.add_argument("--no-sandbox")
option.add_argument("--disable-extensions")
option.add_argument("--ignore-ssl-errors")
option.add_argument("--ignore-certificate-errors")
option.add_argument('--disable-gpu')
prefs = {'download.default_directory': '/home/seluser/Downloads/'}
option.add_experimental_option('prefs', prefs)
option.add_experimental_option('w3c', False)
option.add_experimental_option('perfLoggingPrefs', {
'enableNetwork': True,
'enablePage': False,
})
caps = option.to_capabilities()
caps['goog:loggingPrefs'] = {'performance': 'ALL'}
config.driver = selenium.webdriver.Remote(
command_executor="http://47.93.32.161:5444",
desired_capabilities=caps,
keep_alive=True,
options=option)
config.driver.set_page_load_timeout(10)
browser.open('/')
browser.driver.maximize_window()