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?
window
that you're using refers to the cypress runnerwindow
. If you want to access thewindow
of your AUT (application under test), usecy.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...
: