问题描述
我目前正在尝试将我的量角器代码转换为 Cypress 代码。我的一些量角器代码涉及使网页执行 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
这些代码行是否有 Cypress 等效项?
解决方法
一些灵感:
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