赛普拉斯从窗口获取全局变量

时间:2019-08-08 17:56:06

标签: javascript user-interface testing global cypress

为什么我不能使用Cypress获取全局变量(附加到window对象上)的内容?
我已经尝试了许多不同的方法并最终得到了结果,但这仍然行不通:

it('blabla', () => {...
var arr = [];
cy.window()
        .then((win) => {
            cy.log(win);
            arr = win.teasers;
        })
        .then(() => {
            arr.forEach(function (el, i) {
                cy.get('h1').should('be.visible');
                cy.get('h1').should('have.text', win.teasers[i]);
                cy.tick(11800);
            });
        });
...});

即使在上面记录了ReferenceError: win is not defined的情况下,window也会出错,并且该记录的对象还包含teasers数组作为属性。当它确实在第一行.then()中记录第二行时,为什么它不起作用?
谢谢您的帮助。

编辑:注释掉上面的代码片段并执行以下断言:

cy.window().should('have.property', 'teasers');

工作正常。这意味着该属性必须存在,并留下一个问题,为什么我不能在那个数组上进行迭代?

1 个答案:

答案 0 :(得分:1)

private RetryPolicy<Object> MY_RETRY_POLICY = new RetryPolicy<>() .handle(RuntimeException.class) .onRetry(fail -> otherFunction1()) .withMaxRetries(3); 不在第二private RetryPolicy<Object> MY_RETRY_POLICY = new RetryPolicy<>() .handle(RuntimeException.class) .onFailure(fail -> otherFunction1()) .withMaxRetries(3); 的范围内,因此错误TextFormField( ... decoration: InputDecoration( contentPadding: EdgeInsets.all(10.0), ... ) 。在第一个win中只能使用一次。

由于在执行第二个then()ReferenceError: win is not defined的值已经设置为then(),请更改此值:

arr

对此:

win.teasers
相关问题