Skip to main content
Cypress应用

getAllSessionStorage

获取测试交互过的所有源的 sessionStorage 数据。

语法

cy.getAllSessionStorage()
cy.getAllSessionStorage(options)

用法

正确用法

cy.getAllSessionStorage()

参数

options (Object)

传入一个选项对象来改变cy.getAllSessionStorage()的默认行为。

选项默认值描述
logtrue命令日志中显示该命令

生成结果 了解主题管理

cy.getAllSessionStorage()返回一个对象,其键是源,值是sessionStorage数据的键值对。

例如,如果在https://example.cypress.io上设置了key1value1,在https://www.cypress-dx.com上设置了key2value2cy.getAllSessionStorage()将返回:

{
'https://example.cypress.io': {
key1: 'value1',
},
'https://www.cypress-dx.com': {
key2: 'value2',
},
}

示例

获取所有sessionStorage

cy.visit('/users', {
onBeforeLoad(win) {
win.sessionStorage.setItem('key', 'value')
},
})

cy.getAllSessionStorage().then((result) => {
expect(result).to.deep.equal({
'http://localhost:8080': {
key: 'value',
},
})
})

规则

要求 了解命令链

  • cy.getAllSessionStorage()需要链式调用cy

断言 了解断言

  • cy.getAllSessionStorage()只会运行你链式调用的断言一次,并且不会重试

超时设置 了解超时机制

  • cy.getAllSessionStorage()不会超时。

另请参阅