美文网首页
selenium 分布式执行补充--填坑1

selenium 分布式执行补充--填坑1

作者: 足__迹 | 来源:发表于2019-06-22 18:18 被阅读0次

启动主节点hub 和子节点node,编辑脚本执行,
脚本如下:

from selenium import webdriver
from selenium.webdriver.common.keys import Keys
import time

driver = webdriver.Remote(
    command_executor="http://192.168.0.102:5555/wd/hub",
    desired_capabilities= {
        "browserName" : "chrome",
        "version" : '75.0.3770.100',
        "video": "true",
        "platform": "MAC",
        'javascriptEnable':True
    }

)
driver.get('http://www.baidu.com')
time.sleep(5)
assert '百度' in driver.title
driver.quit()


报错如下

selenium.common.exceptions.WebDriverException: Message: First match w3c capabilities is zero length
Stacktrace:
    at org.openqa.selenium.remote.NewSessionPayload.validate (NewSessionPayload.java:172)
    at org.openqa.selenium.remote.NewSessionPayload.<init> (NewSessionPayload.java:154)
    at org.openqa.selenium.remote.NewSessionPayload.create (NewSessionPayload.java:105)
    at org.openqa.selenium.remote.server.commandhandler.BeginSession.execute (BeginSession.java:64)
    at org.openqa.selenium.remote.server.WebDriverServlet.lambda$handle$0 (WebDriverServlet.java:235)
    at java.util.concurrent.Executors$RunnableAdapter.call (Executors.java:511)
    at java.util.concurrent.FutureTask.run (FutureTask.java:266)
    at java.util.concurrent.ThreadPoolExecutor.runWorker (ThreadPoolExecutor.java:1149)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run (ThreadPoolExecutor.java:624)
    at java.lang.Thread.run (Thread.java:748)

发现问题是建立会话是报错了打断点看下

image.png
image.png

问题出现了,发现参数并没有放在字典中,不符合格式要求
修改如下:

#分布式执行(放在开头,python调用函数从上往下)
添加一个判断是否符合desired_capabilities格式的函数
_W3C_CAPABILITY_NAMES = frozenset([
    'acceptInsecureCerts',
    'browserName',
    'browserVersion',
    'platformName',
    'pageLoadStrategy',
    'proxy',
    'setWindowRect',
    'timeouts',
    'unhandledPromptBehavior',
])

_OSS_W3C_CONVERSION = {
    'acceptSslCerts': 'acceptInsecureCerts',
    'version': 'browserVersion',
    'platform': 'platformName'
}


def _make_w3c_caps(caps):
    """Makes a W3C alwaysMatch capabilities object.

    Filters out capability names that are not in the W3C spec. Spec-compliant
    drivers will reject requests containing unknown capability names.

    Moves the Firefox profile, if present, from the old location to the new Firefox
    options object.

    :Args:
     - caps - A dictionary of capabilities requested by the caller.
    """
    caps = copy.deepcopy(caps)
    profile = caps.get('firefox_profile')
    always_match = {}
    if caps.get('proxy') and caps['proxy'].get('proxyType'):
        caps['proxy']['proxyType'] = caps['proxy']['proxyType'].lower()
    for k, v in caps.items():
        if v and k in _OSS_W3C_CONVERSION:
            always_match[_OSS_W3C_CONVERSION[k]] = v.lower() if k == 'platform' else v
        if k in _W3C_CAPABILITY_NAMES or ':' in k:
            always_match[k] = v
    if profile:
        moz_opts = always_match.get('moz:firefoxOptions', {})
        # If it's already present, assume the caller did that intentionally.
        if 'profile' not in moz_opts:
            # Don't mutate the original capabilities.
            new_opts = copy.deepcopy(moz_opts)
            new_opts['profile'] = profile
            always_match['moz:firefoxOptions'] = new_opts
    return {"firstMatch": [{}], "alwaysMatch": always_match}

将一下模块修改

image.png

修改后

            if "moz:firefoxOptions" in capabilities:
                capabilities["moz:firefoxOptions"]["profile"] = browser_profile.encoded
            else:
                capabilities.update({'firefox_profile': browser_profile.encoded})
        w3c_caps = _make_w3c_caps(capabilities)
        parameters = {"capabilities": w3c_caps,
                      "desiredCapabilities": capabilities}

收获;对于selenium 的执行流程有了更加深刻的了解,遇见问题不要慌,一步一步打断点慢慢找总能清除掉

相关文章

  • selenium 分布式执行补充--填坑1

    启动主节点hub 和子节点node,编辑脚本执行,脚本如下: 报错如下 发现问题是建立会话是报错了打断点看下 问题...

  • Selenium分布式

    Selenium Grid Selenium Grid是用于分布式执行测试用例的工具。通过Selenium Gri...

  • iOS10适配问题收集

    先占坑位,再填坑,欢迎大家补充。 1、TencentOpenAPI的坑 表现:启动就crash原因:由于很久没有更...

  • iOS10适配问题收集《转载》

    先占坑位,再填坑,欢迎大家补充。 1、TencentOpenAPI的坑表现:启动就crash原因:由于很久没有更新...

  • Numpy小技巧学习历险记~~持续更新中....

    Numpy学习之旅,填坑之旅。欢迎留言补充*_<>_*。 1、numpy.random.shuffle()与num...

  • ConstraintLayout入坑指南

    本文章只为填坑,不做使用教程(后续遇到会陆续补充,也欢迎广大网友补充)。1.match_parent会使约束失效,...

  • selenium 分布式执行

    1.启动管理节点 java -jar selenium-server-standalone-3.141.59...

  • Selenium grid介绍和使用

    Selenium Grid是Selenium的三大组件之一,它的作用就是分布式执行测试,在不同机器上测试不同浏览器...

  • Python多线程

    1.背景:上一篇文章介绍的selenium grid2 虽然可以分布式执行,但不支持并行,为了节省时间,分布式+并...

  • Selenium+python各种填坑

    版本 Python3.5.2 \ Selenium3.4.0 \ FireFox51.0 安装setuptool...

网友评论

      本文标题:selenium 分布式执行补充--填坑1

      本文链接:https://www.haomeiwen.com/subject/ivuvqctx.html