javascript - Property of window is undefined in cypress - Stack Overflow

admin2025-04-26  7

I am using Cypress with Meteor.

I need the Meteor object on the window to call Meteor.loginWithPassword.

I want to use this to skip using the UI for login each time. I have tried the following but Meteor is not on the window when it runs.

cy.window()
  .then((window) => {
      console.log(window.Meteor);
   });

I am using Cypress with Meteor.

I need the Meteor object on the window to call Meteor.loginWithPassword.

I want to use this to skip using the UI for login each time. I have tried the following but Meteor is not on the window when it runs.

cy.window()
  .then((window) => {
      console.log(window.Meteor);
   });
Share Improve this question asked Jul 24, 2018 at 10:31 Ozzy WalshOzzy Walsh 8879 silver badges17 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 5

Try this:

cy.window().its('Meteor');

This will wait until the Meteor property exists on the window object.


Or, if you want to do something with the Meteor property once it exists, use .then():

cy.window().its('Meteor').then(meteor => {
    console.log(meteor);
    // do things
});

.its() will attempt to get a property from the object wrapped by Cypress, in this case the window object, and will retry until the property exists or the mand times out.

转载请注明原文地址:http://conceptsofalgorithm.com/Algorithm/1745674000a313481.html

最新回复(0)