目前,我正在使用赛普拉斯测试自动化。我index.html
里面有一个文件cypress/downloads/sample/index.html
。该index.html
文件具有以下结构。
<html>
<head>
<style type="text/css">
</style>
</head>
<body>
<script src="https://test"></script>
<script src="https://test2"></script>
<!-- sample Config -->
<script>
const authConfig = {
clientID: "sample value",
signInRedirectURL: "sample value",
serverOrigin: "sample value"
};
</script>
</body>
</html>
我将复制脚本标记内的内容,该标记将显示在应用程序 UI 中,使用按钮单击进行复制操作,因此复制的内容如下所示
<script>
const authConfig = {
clientID: "abcd1234",
signInRedirectURL: "https://localhost:8000",
serverOrigin: "https://localhost:8000"
};
</script>
为复制和粘贴操作编写的方法如下:
static CopyConfigs() {
cy.get(COPY_ICON).click();
cy.wait(7000);
}
static pasteoperation(Location){
cy.task("getClipboard").then((value) => {
cy.writeFile(Location + "/sample/index.html", value);
});
}
writeFile 将替换整个index.html
文件内容
需要帮助
我想index.html
通过仅替换文件中的脚本标记(与 authConfig 相关)内容index.html
而不替换整个index.html
文件内容来替换(粘贴)复制到文件的内容。因此,clientID、signInRedirectURL 和fileserverOrigin
的 script 标签内的index.html
值将具有新值。是否可以使用赛普拉斯自动化读取index.html
文件并捕获脚本标签并替换标签内容?<script>
感谢您对如何实现这一目标的支持。