cypress: unable to access app from window object

不羁的心 提交于 2019-12-11 16:19:15

问题


I need to access my vuex store in cypress tests, so i added the app to the window object in my main.js:

const app = new Vue({
  router,
  store,
  render: h => h(App)
}).$mount("#app");

window.vueApp = app;

And then i try to access it in my login command (commands.js):

cy
    .request({
      method: "POST",
      url: "http://localhost:8081/api/v1/login",
      body: {},
      headers: {
        Authorization: "Basic " + btoa("administrator:12345678")
      }
    })
    .then(resp => {
      console.log("app:", window.vueApp);
      ...
      window.localStorage.setItem("aq-username", "administrator");
    });

but it's always undefined, what am i doing wrong?


回答1:


window that you're using refers to the cypress runner window. If you want to access the window of your AUT (application under test), use cy.window() command.

Or you can use cy.state('window') which returns the window object synchronously, but this is undocumented and may change in the future.

Related: if you want to access your AUT in the dev console, you'll need to switch the context to Your app...:



来源:https://stackoverflow.com/questions/51122236/cypress-unable-to-access-app-from-window-object

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!