环境部署
部署方式
version: "3"
x-restart-policy: &restart_policy
restart: unless-stopped
services:
chrome:
<<: *restart_policy
image: selenium/node-chrome:4.0.0-20211025
shm_size: 2gb
depends_on:
- selenium-hub
environment:
- SE_EVENT_BUS_HOST=selenium-hub
- SE_EVENT_BUS_PUBLISH_PORT=4442
- SE_EVENT_BUS_SUBSCRIBE_PORT=4443
- SE_NODE_GRID_URL=http://localhost:4444
ports:
- "5900-5999:5900"
volumes:
- /dev/shm:/dev/shm
edge:
<<: *restart_policy
image: selenium/node-edge:4.0.0-20211025
shm_size: 2gb
depends_on:
- selenium-hub
environment:
- SE_EVENT_BUS_HOST=selenium-hub
- SE_EVENT_BUS_PUBLISH_PORT=4442
- SE_EVENT_BUS_SUBSCRIBE_PORT=4443
- SE_NODE_GRID_URL=http://localhost:4444
ports:
- "5900-5999:5900"
volumes:
- /dev/shm:/dev/shm
firefox:
<<: *restart_policy
image: selenium/node-firefox:4.0.0-20211025
shm_size: 2gb
depends_on:
- selenium-hub
environment:
- SE_EVENT_BUS_HOST=selenium-hub
- SE_EVENT_BUS_PUBLISH_PORT=4442
- SE_EVENT_BUS_SUBSCRIBE_PORT=4443
- SE_NODE_GRID_URL=http://localhost:4444
ports:
- "5900-5999:5900"
volumes:
- /dev/shm:/dev/shm
selenium-hub:
image: selenium/hub:4.0.0-20211025
container_name: selenium-hub
ports:
- "4444:4444"
简单脚本
from selenium import webdriver
from selenium.webdriver import DesiredCapabilities
driver = webdriver.Remote('http://x.x.x.x:4444/wd/hub', desired_capabilities=DesiredCapabilities.FIREFOX)
driver.get("https://www.baidu.com")
driver.find_element_by_id("kw").send_keys("测试")
driver.find_element_by_id("su").click()
建立连接
- 1、在 docker 中启动 hub 服务
- 2、通过 Remote 方法,进行远程连接到 hub 服务中,由 hub 进行分配调用对应的浏览器进行测试
- 3、简化本地还要下载对应的 driver,还有对应版本的浏览器,确保一点,就是 docker 镜像与hub一致就可以了
appium服务启动
启动appium服务
adb forward tcp:8888 tcp:6790
adb shell am instrument -w -e disableAnalytics true io.appium.uiautomator2.server.test/androidx.test.runner.AndroidJUnitRunner
adb shell am start -W -n io.appium.android.apis/.ApiDemos -S -a android.intent.action.MAIN -c android.intent.category.LAUNCHER -f 0x10200000