更新铬版本后的量角器问题 [英] protractor issue after update chromium version

查看:75
本文介绍了更新铬版本后的量角器问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚刚更新了我的 Chrome 版本和getAttribute"总是返回null,有人知道为什么吗?(在此更新工作正常之前)

I just updated my chromium version and the "getAttribute" always returns null, does anybody knows why? (before this update was working fine)

CHROMIUM_REVISION=884014

element(by.id(elementId)).getAttribute('value').then((value) => {
                console.log(value); // <-- null
            });

推荐答案

这是 ChromeDriver 91 的一个问题,首先在 Chromium 错误跟踪器 2021 年 5 月 3 日.

This is an issue with ChromeDriver 91, first reported in the Chromium bug tracker on May 3rd 2021.

我在 这篇文章.

简而言之,Chromium 团队认为 最近的变化GetElementAttribute 命令的行为产生了负面影响,现在导致 WebElement.getAttribute 方法返回 null 而不是属性的实际值.

In short, the Chromium team believes that a recent change to the ChromeDriver attribute endpoint has negatively impacted the behaviour of the GetElementAttribute command, which now leads to WebElement.getAttribute method returning null instead of the actual value of the attribute.

该问题影响使用 JsonWireProtocol 的工具,例如 Selenium WebDriver3,Protractor 使用 幕后.

The issue affects tools using the JsonWireProtocol, such as Selenium WebDriver 3, which Protractor uses under the hood.

Chromium 团队推荐的解决方案是改用 Selenium WebDriver 4,并且有一个 正在进行努力让 Protractor 也使用它(如果你在 GitHub 上,请考虑为这张票投票).需要注意的是,Selenium WebDriver 4 弃用了许多 API,因此需要更新测试以避免使用那些(即 browser.actions()).

The solution recommended by the Chromium team is to use Selenium WebDriver 4 instead, and there's an ongoing effort to make Protractor use that too (if you're on GitHub, please consider upvoting this ticket). A thing to note is that Selenium WebDriver 4 deprecates a number of APIs, so tests will need to be updated to avoid using those (i.e. browser.actions()).

Selenium WebDriver 3 兼容修复也已提出,但在撰写本文时(2021 年 6 月 8 日)不可用.

A Selenium WebDriver 3-compatible fix has been proposed too, but isn't available at the time of writing (June 8th 2021).

如果您想在官方修复程序可用之前将 Chromium/ChromeDriver 91 与 Protractor 一起使用,您有以下三种选择:

If you'd like to use Chromium/ChromeDriver 91 with Protractor before the official fixes are available you have three options:

您可以在 protractor.conf.js 中显式启用对 W3C 协议(而不是受影响的 JsonWireProtocol)的支持:

You can explicitly enable support for W3C protocol (instead of the affected JsonWireProtocol) in protractor.conf.js:

capabilities: {
    'browserName': 'chrome',
    'goog:chromeOptions': {
        w3c: true,
        args: [
            '--headless',
        ]
    },
}

警告:某些 API,例如 browser.actions() 与 W3C 模式不兼容,并且在启用此模式时会中断.

Warning: Some APIs, like browser.actions() are not compatible with the W3C mode and will break when this mode is enabled.

getAttribute() 返回 null 时,您可以更改测试以回退到通过 JavaScript 检索属性值.

You can change your tests to fall back to retrieving the attribute value via JavaScript when getAttribute() returns null.

const attribute = await element.getAttribute(name).then(value => {
    if (value !== null) {
        return value;
    }
    
    return browser.executeScript(`
        function getAttribute(webElement, attributeName) {
            return webElement.getAttribute(attributeName);        
        })
    `, element, name);
})

这类似于 Serenity/JS 验收测试框架的做法幕后.

我已经在 Serenity/JS 中实现了上述回退策略(查看 GitHub),因此如果您将 Protractor 与 Serenity/JS 一起使用,则需要更新任何 @serenity-js/* 模块到版本 2.29.0,它只适用于 Chromium 91.

I've already implemented the above fallback strategy in Serenity/JS (view on GitHub), so if you're using Protractor with Serenity/JS, you need to updated any @serenity-js/* modules to version 2.29.0 and it will just work with Chromium 91.

例如,如果您有这样的小部件:

For example, if you have a widget like this:

<input type="checkbox" id="confirm" />

使用 Serenity/JS 和量角器,您可以按如下方式检索小部件的任何属性:

With Serenity/JS and Protractor, you'd retrieve any of the widget's attributes as follows:

import { actorCalled } from '@serenity-js/core';
import { Ensure, equals } from '@serenity-js/assertions';
import { Target } from '@serenity-js/protractor';
import { by } from 'protractor';

const confirmation = Target.the('confirmation checkbox')
    .located(by.id('confirm'));

// in the test:

actorCalled('Alice').attemptsTo(
    Ensure.that(
        Attribute.of(confirmation).called('checked'),
        equals('true')
    ),
);

开始使用 Serenity/JS 和量角器:

To get started with Serenity/JS and Protractor:

完全公开,我是 Serenity/JS 的作者

Full disclosure, I'm the author of Serenity/JS

这篇关于更新铬版本后的量角器问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆