zoukankan      html  css  js  c++  java
  • selenium-grid 分布式 实现同一脚本在不同pc上运行

    1、使用版本:
    selenium 3.11.0
    chrome 65
    phantomjs 2.1.1
    selenium-server selenium-server-standalone-2.46.0.jar 下载地址:http://selenium-release.storage.googleapis.com/index.html
    2、grid配置文件
    def grid():
    d = {'http://127.0.0.1:4444/wd/hub': 'chrome',
    'http://127.0.0.1:5555/wd/hub': 'phantomjs',
    'http://10.6.60.176:4452/wd/hub': 'chrome',
    }
    return d
    该文件定义了一个方法,该方法存放了一个字典,分别给本机分配了2个不同的端口并指定了不同的浏览器
    3、测试脚本
    # encoding:utf-8

    from selenium import webdriver
    from selenium.webdriver.common.desired_capabilities import DesiredCapabilities
    import time, os.path
    from tmp import grid_module

    for host, browser in grid_module.grid().items():
    driver = webdriver.Remote(
    command_executor=host,
    desired_capabilities={
    'platform': 'ANY',
    'browserName': browser,
    'version': '',
    'javascriptEnabled': True
    }
    )
    driver.get("http://www.baidu.com")
    driver.find_element_by_id("kw").send_keys(u"中国")
    driver.find_element_by_id("su").click()
    time.sleep(3)
    if driver.title == u"中国_百度搜索":
    print("title匹配!")
    else:
    print("title不匹配!")
    driver.close()

    dosc中运行: java -jar selenium-server-standalone-2.46.0.jar -role hub
    java -jar selenium-server-standalone-2.46.0.jar -role node -port 5555
    启动后在 http://127.0.0.1:4444/grid/console 打开grid控制台

     启动其他电脑节点:
    java -jar selenium-server-standalone-2.46.0.jar -port 4452 -role node -hub 

    运行脚本即可

  • 相关阅读:
    Pyechart——学习
    matplotlib——散点图、条形图、直方图
    matplotlib——折线图
    寻找n以内的亲密数对
    Golang判断时间点处于今天
    寒假作业3
    寒假作业2
    面向对象程序设计寒假作业1
    自我介绍
    关于cve2019_0708的反弹shell
  • 原文地址:https://www.cnblogs.com/changqing8023/p/9057328.html
Copyright © 2011-2022 走看看