首页 > 解决方案 > 如何让赛普拉斯在页面上执行 API 脚本?

问题描述

我目前正在尝试将我的量角器代码转换为赛普拉斯代码。我的一些量角器代码涉及使网页执行 API 脚本,例如:

import { browser } from “protractor”; // this is the import I used

browser.executeScript(‘arguments[0].click()’;, this.closeButton); // this is for button clicking

browser.executeScript(‘localStorage.setItem(“example-boolean”, “false”)’); // this is for setting a value to false

这些代码行是否有赛普拉斯等价物?

标签: typescriptautomated-testscypressend-to-end

解决方案


一些灵感:

import "cypress-localstorage-commands";

cy.get('#yourCloseBtnId').click();  // Clicking on the element with an ID #yourCloseBtnId

cy.setLocalStorage("example-boolean", false);  // Setting an item in the local storage

推荐阅读