微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

如何使用 cypress 自动化测试替换 index.html 文件中特定标记内的某些值

如何解决如何使用 cypress 自动化测试替换 index.html 文件中特定标记内的某些值

目前,我正在使用 Cypress 测试自动化。我在 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 文件内容。这样 serverOrigin 文件的脚本标记内的 clientID、signInRedirectURL 和 index.html 的值将具有新值。是否可以使用赛普拉斯自动化读取 index.html 文件并捕获脚本标记并替换 <script> 标记内容?感谢您对如何实现这一目标的支持

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。