selenium grid分布式

selenium grid环境在很多实体电脑上可以实现,如果我们没有那么多电脑,就需要利用docker来完成selenium grid环境搭建

一、环境搭建

  1. 创建一个docker网络

    复制代码
    docker network create grid
  2. 完成中心的搭建

  • 拉取镜像

    复制代码
    docker pull selenium/hub:4.10
  • 启动镜像

    复制代码
    docker run -d -p 4442-4444:4442-4444 --network grid --name shub -v
    /etc/localtime:/etc/localtime:ro --privileged=true selenium/hub:4.10
  • 启动成功后,浏览器访问(http://ip:4444/ui)

3.完成chrome节点搭建

  • 拉取镜像

    复制代码
    docker pull selenium/node-chrome:4.10
  • 启动镜像

    复制代码
    docker run -d -p 7900:7900 --network grid -e SE_EVENT_BUS_HOST=shub --
    shm-size="2g" -e SE_EVENT_BUS_PUBLISH_PORT=4442 -e
    SE_EVENT_BUS_SUBSCRIBE_PORT=4443 --name chrome -v
    /etc/localtime:/etc/localtime:ro --privileged=true selenium/nodechrome:4.10
  • 可以通过下面的链接打开docker容器浏览器可视化界面

    复制代码
    http://ip:7900/?autoconnect=1&resize=scale&password=secret

4.完成selenium gird的框架修改

python 复制代码
class DriverOperate:
    # 利用类属性定一个全局核心操作对象,他的赋值未来必须在conftest里完成
    globalDriverOperate=None
    # 这个类将会封装我们所有的核心操作
    # 在之后我们的这个框架,将会调用该类提供的各种动作来实现操作
    def __init__(self,browser='chrome',remote_url=None):
        self.logger = GetLogger.get_logger()
        self.browser = browser.lower()
        if remote_url:
            # 要用selenium grid方式运行
            if self.browser == 'chrome':
                options = webdriver.ChromeOptions()

            elif self.browser == 'firefox':
                options = webdriver.FirefoxOptions()

            elif self.browser == 'ie':
                options = webdriver.IeOptions()

            elif self.browser == 'edge':
                options = webdriver.EdgeOptions()

            elif self.browser == 'safari':
                options = webdriver.safari.options.Options()

            else:
                self.logger.error(f'{self.browser} 不支持')
                raise BaseException(f'{self.browser} 不支持')
            options.page_load_strategy='eager' # 表示页面加载较快
            self.driver = webdriver.Remote(remote_url,options=options)
        else:
            # 执行本地浏览器
            if self.browser == 'chrome':
                options = webdriver.ChromeOptions()
                self.driver = webdriver.Chrome(options=options)
            elif self.browser == 'firefox':
                options = webdriver.FirefoxOptions()
                self.driver = webdriver.Firefox(options=options)
            elif self.browser == 'ie':
                options = webdriver.IeOptions()
                self.driver = webdriver.Ie(options=options)
            elif self.browser == 'edge':
                options = webdriver.EdgeOptions()
                self.driver = webdriver.Edge(options=options)
            elif self.browser == 'safari':
                options = webdriver.safari.options.Options()
                self.driver = webdriver.Safari(options=options)
            else:
                self.logger.error(f'{self.browser} 不支持')
                raise BaseException(f'{self.browser} 不支持')
        self.driver.maximize_window()
        self.driver.implicitly_wait(10)
        self.logger.info(f'{self.browser} 启动成功')
相关推荐
Run Freely9377 小时前
接口测试-postman-全局变量与环境变量
测试工具·postman
我的xiaodoujiao10 小时前
从 0 到 1 搭建 Python 语言 Web UI自动化测试学习系列 8--基础知识 4--常用函数 2
前端·python·测试工具·ui
程序员小远13 小时前
常用的测试用例
自动化测试·软件测试·python·功能测试·测试工具·职场和发展·测试用例
(时光煮雨)14 小时前
【Python进阶】Python爬虫-Selenium
爬虫·python·selenium
依旧很淡定3 天前
Selenium(Python)创建Chrome浏览器实例
chrome·python·selenium
小熊出擊3 天前
【pytest】finalizer 执行顺序:FILO 原则
python·测试工具·单元测试·pytest
云闲不收3 天前
接口请求工具对比 apifox apipost swagger postman等
测试工具·postman
sitellla3 天前
Testify Go测试工具包入门教程
git·测试工具·其他·golang
我的xiaodoujiao3 天前
从 0 到 1 搭建 Python 语言 Web UI自动化测试学习系列 9--基础知识 5--常用函数 3
前端·python·测试工具·ui
可可南木4 天前
ICT 数字测试原理 8 - -VCL 的测试参数
开发语言·功能测试·测试工具·pcb工艺