Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/337.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Cypress 访问get-in-then块的输出_Cypress - Fatal编程技术网

Cypress 访问get-in-then块的输出

Cypress 访问get-in-then块的输出,cypress,Cypress,如何访问从.then()函数中的.get().contains()生成的元素 我的代码没有进入Then块。我哪里做错了 cy.get(".c-header-listItem").contains("My Account").should(($link) => { expect(localStorage.read("CD-SessionId")).to.be.not.null;`enter code here` }).then(($link) => {

如何访问从.then()函数中的.get().contains()生成的元素

我的代码没有进入Then块。我哪里做错了

cy.get(".c-header-listItem").contains("My Account").should(($link) => {
        expect(localStorage.read("CD-SessionId")).to.be.not.null;`enter code here`
    }).then(($link) => {
        $link.click();
    });

我从Cypress文档中获得了登录名。应该(elem=>{})的行为与
完全相同。然后(elem=>{})
,除了传递给
应该
的函数将重试,直到它不抛出任何异常。考虑到这一点,以下代码应该可以工作:

cy.get(“.c-header-listItem”)。包含(“我的帐户”)。应该(($link)=>{
expect(localStorage.read(“CD SessionId”).to.be.not.null;
//请注意,我必须将其包装以执行Cypress
//单击它。$link是一个本机DOM对象。
cy.wrap($link)。单击();
});

这也会起作用,但不需要分离

cy.get(“.c-header-listItem”)。包含(“我的帐户”)。应该(($link)=>{
expect(localStorage.read(“CD SessionId”).to.be.not.null;
});
cy.get(“.c-header-listItem”)。包含(“我的帐户”)。单击();
.should(elem=>{})
的行为与
完全相同。然后(elem=>{})
,除了传递给
should
的函数将重试,直到它不抛出任何异常为止。考虑到这一点,以下代码应该可以工作:

cy.get(“.c-header-listItem”)。包含(“我的帐户”)。应该(($link)=>{
expect(localStorage.read(“CD SessionId”).to.be.not.null;
//请注意,我必须将其包装以执行Cypress
//单击它。$link是一个本机DOM对象。
cy.wrap($link)。单击();
});

这也会起作用,但不需要分离

cy.get(“.c-header-listItem”)。包含(“我的帐户”)。应该(($link)=>{
expect(localStorage.read(“CD SessionId”).to.be.not.null;
});
cy.get(“.c-header-listItem”)。包含(“我的帐户”)。单击();

没问题,很乐意帮忙:)没问题,很乐意帮忙:)