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} 启动成功')
相关推荐
niuniu_6661 天前
简单的自动化场景(以 Chrome 浏览器 为例)
运维·chrome·python·selenium·测试工具·自动化·安全性测试
suimeng62 天前
ChromeDriver的常用方法
java·selenium
niuniu_6662 天前
Selenium 性能测试指南
selenium·测试工具·单元测试·测试·安全性测试
莓事哒2 天前
selenium和pytessarct提取古诗文网的验证码(python爬虫)
爬虫·python·selenium·测试工具·pycharm
suimeng62 天前
基本元素定位(findElement方法)
java·selenium
mywpython2 天前
mac 最新的chrome版本配置selenium的方式
chrome·python·selenium·macos
软件测试曦曦2 天前
如何使用Python自动化测试工具Selenium进行网页自动化?
自动化测试·软件测试·python·功能测试·测试工具·程序人生·自动化
freejackman2 天前
Selenium框架——Web自动化测试
python·selenium·测试
互联网杂货铺2 天前
黑盒测试、白盒测试、集成测试和系统测试的区别与联系
自动化测试·软件测试·python·功能测试·测试工具·单元测试·集成测试
Feng.Lee3 天前
聊一聊缓存如何进行测试
功能测试·测试工具·缓存