javascript - (已解决)使用 TestCafe - 如何阻止移动网络智能应用横幅出现?

标签 javascript ios testing testcafe smartbanner

我正在测试的网页在 iOS 设备上显示 Apple 智能应用横幅,并在 HTML 中使用以下属性:

name="apple-itunes-app"
content="app-id=foobar"
rel="manifest"
href="/CompanyName/mobile/include/manifest.json"

但是,我不希望显示此内容。通常,如果涉及到请求,我会使用 TestCafe Request Mocker,但是这个横幅似乎没有使用请求,它只是出现了! “网络”选项卡中没有 list 请求。

如何使用 TestCafe native 功能或任何合适的 Node 包来阻止智能应用横幅?

解决方案(感谢@Alex Kamaev 帮助):

import { ClientFunction } from 'testcafe';

fixture `fixture`
    .page `http://localhost:8080`;

test.clientScripts({ content: `
    document.querySelector('meta[name="apple-itunes-app"]').remove();
` })(`test`, async t => {
    await t.wait(5000);
});

最佳答案

您可以尝试使用 ClientScripts 机制从页面中删除横幅元标记。详情请引用以下文章:https://devexpress.github.io/testcafe/documentation/using-testcafe/common-concepts/inject-scripts-into-tested-pages.html

我准备了一个例子:

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title>Math Ninja iPhone/iPod Touch Game | Making Addition, Subtraction, Multiplication, and Division Fun!</title>
    <meta name="apple-itunes-app" content="app-id=370144476"/>
    <link rel="stylesheet" type="text/css" href="reset.css"/>
    <link rel="stylesheet" type="text/css" href="style.css"/>
</head>
<body>
</body>
</html>

测试代码:

import { ClientFunction } from 'testcafe';

fixture `fixture`
    .page `http://localhost:8080`;


const removeBanner = ClientFunction(() => {
    var banner = document.querySelector('meta');

    banner.parentNode.removeChild(banner);
});

test.clientScripts({ content: `
    var banner = document.querySelector('meta');

    banner.parentNode.removeChild(banner);
` })(`test`, async t => {
    await t.wait(5000);
});

关于javascript - (已解决)使用 TestCafe - 如何阻止移动网络智能应用横幅出现?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60566333/

相关文章:

JavaScript:instanceof 运算符出现意外结果

ios - 自定义委托(delegate)和数据源 NSObject 最佳实践

ruby-on-rails - 是否有日志可以查看 rspec 在运行测试时实际在做什么?

javascript - Node.js - 语法错误 : Unexpected token import

javascript - ExtJS:Ext.Window Prototypal继承的对象无法被销毁

ios - 什么是armv7s?

ios - 视口(viewport)属性如何正确使用

ios - 有什么方法可以配置针对一个特定模拟器启动的测试吗?

android - headless 安卓模拟器 : GPS Location does not work even with setting Geo Fix

javascript - 在 forEach 循环中获取特定元素