最新消息:Welcome to the puzzle paradise for programmers! Here, a well-designed puzzle awaits you. From code logic puzzles to algorithmic challenges, each level is closely centered on the programmer's expertise and skills. Whether you're a novice programmer or an experienced tech guru, you'll find your own challenges on this site. In the process of solving puzzles, you can not only exercise your thinking skills, but also deepen your understanding and application of programming knowledge. Come to start this puzzle journey full of wisdom and challenges, with many programmers to compete with each other and show your programming wisdom! Translated with DeepL.com (free version)

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

matteradmin5PV0评论

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.

Post a comment

comment list (0)

  1. No comments so far