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} 启动成功')
相关推荐
慌糖6 小时前
✨ Apifox:这玩意儿是接口界的“瑞士军刀”吧![特殊字符][特殊字符]
测试工具
试着9 小时前
【新技术】微软 Azure Test Impact Analyzer (TIA) 全面解析
测试工具·microsoft·azure·测试覆盖率
心灵宝贝11 小时前
Postman-win64-7.2.2 安装教程(Windows 64位详细步骤)
windows·测试工具·postman
程序员小远12 小时前
接口测试和单元测试详解
自动化测试·软件测试·python·测试工具·单元测试·测试用例·接口测试
Ctrl С15 小时前
[三分钟]入门web自动化测试(一):1.使用驱动管理下载web驱动(WebDriver);2.初步认识和使用Selenium
selenium·测试工具·自动化·web
HtwHUAT16 小时前
二、UI自动化测试02--元素定位方法
笔记·python·selenium·ui
??? Meggie20 小时前
【Python】保持Selenium稳定爬取的方法(防检测策略)
开发语言·python·selenium
半路_出家ren2 天前
流量抓取工具(wireshark)
网络·网络协议·测试工具·网络安全·wireshark·流量抓取工具
猿周LV2 天前
JMeter 安装及使用 [软件测试工具]
java·测试工具·jmeter·单元测试·压力测试
西柚小萌新2 天前
【Python爬虫基础篇】--4.Selenium入门详细教程
爬虫·python·selenium