Cypress学习文档

沉淀cypress对常用html组件定位的文档


mock接口

<h1>mock接口返回</h1> <p>举例:针对Method为PUT,API请求路径包含/comments/的接口,进行mock,返回数据</p> <p>intercept参数中,第一个{}为请求数据定义,第二个{}为mock返回数据定义 当第二个{}不定义时,等待实际返回的请求。</p> <p>使用wait('@putComment')等待接口返回;</p> <pre><code class="language-javascript">// Stub a response to PUT comments/ **** cy.intercept({ method: 'PUT', url: '**/comments/*', }, { statusCode: 404, body: { error: message }, headers: { 'access-control-allow-origin': '*' }, delayMs: 500, }).as('putComment') cy.get('xxx').click(); cy.wait('@putComment');</code></pre>

页面列表

ITEM_HTML