如何让 Cypress 在页面上执行 API 脚本?
How to make Cypress execute an API script on a page?
我目前正在尝试将 Protractor 代码转换为 Cypress 代码。我的一些 Protractor 代码涉及让网页执行 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
我目前正在尝试将 Protractor 代码转换为 Cypress 代码。我的一些 Protractor 代码涉及让网页执行 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