【问题标题】:Customize TestCafe Selector in TypeScript for Shadow root Element在 TypeScript 中为影子根元素自定义 TestCafe 选择器
【发布时间】:2019-09-18 01:46:27
【问题描述】:

请帮我在 TypeScript 中定义Selector 部分

import { Selector, t } from 'testcafe'

fixture `Scenario Name : Validation`
    .page `https://chrisbateman.github.io/guide-to-web-components/demos/shadow-dom.htm`;


const demoPage  = Selector('#demo1');
const paragraph = Selector(() => {
    return demoPageSelector().shadowRoot.querySelectorAll('p');
}, { dependencies: { demoPageSelector: demoPage } });


test('Test ShadowDom', async t => {
    await t
        .expect(paragraph.value).eql('Some text');
});

【问题讨论】:

标签: typescript automated-tests e2e-testing shadow-dom testcafe


【解决方案1】:

Debashish Samanta

依赖项在运行时添加到函数的作用域中,因此 TypeScript 在编译期间无法找到它们。您可以使用 // @ts-ignore 注释禁止此验证。

至于“'{ dependencies: { demoPageSelector: Selector; }; }' 类型的参数不能分配给'SelectorOptions' 类型的参数。”错误,似乎dependencies 属性在SelectorOptions 类型声明中以某种方式丢失。您可以使用<SelctorOptions> 类型断言来解决此问题。

import { Selector, t } from 'testcafe'

fixture `Scenario Name : Validation`
    .page `https://chrisbateman.github.io/guide-to-web-components/demos/shadow-dom.htm`;


const demoPage  = Selector('#demo1');
const paragraph = Selector(() => {
    // @ts-ignore: Cannot find name 'demoPageSelector'.
    return demoPageSelector().shadowRoot.querySelectorAll('p');
}, <SelectorOptions> { dependencies: { demoPageSelector: demoPage } });


test('Test ShadowDom', async t => {
    await t
        .expect(paragraph.innerText).eql('These paragraphs are in a shadow root.');
});

【讨论】:

    猜你喜欢
    • 2019-07-16
    • 2015-10-07
    • 2018-10-22
    • 2021-06-15
    • 2022-08-12
    • 1970-01-01
    • 1970-01-01
    • 2021-05-28
    • 1970-01-01
    相关资源
    最近更新 更多