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} 启动成功')
相关推荐
我的xiaodoujiao38 分钟前
API 接口自动化测试详细图文教程学习系列9--Requests模块
python·学习·测试工具·pytest
oi..40 分钟前
《Web 安全入门|XSS 漏洞原理、CSP 策略与 HttpOnly 防护实践》
前端·网络·测试工具·安全·web安全·xss
代码的乐趣2 小时前
支持selenium的chrome driver更新到147.0.7727.56
chrome·python·selenium
我的xiaodoujiao2 小时前
API 接口自动化测试详细图文教程学习系列10--Requests模块2--举例说明
python·学习·测试工具·pytest
橘子编程3 小时前
软件测试全流程实战指南
java·功能测试·测试工具·junit·tomcat·压力测试·可用性测试
RunningBComeOn3 小时前
如何通过wireshark抓取802.11无线网络的数据包
网络·测试工具·wireshark
llilian_161 天前
选择北斗导航卫星信号模拟器注意事项总结 北斗导航卫星模拟器 北斗导航信号模拟器
功能测试·单片机·嵌入式硬件·测试工具·51单片机·硬件工程
小白学大数据1 天前
Selenium+Python 爬虫:动态加载头条问答爬取
爬虫·python·selenium
周杰伦的稻香1 天前
tcpdump
网络·测试工具·tcpdump
金玉满堂@bj1 天前
什么是静态测试?
测试工具