我正在测试的网页在 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/