赛普拉斯:无法从窗口对象访问应用 [英] cypress: unable to access app from window object

查看:77
本文介绍了赛普拉斯:无法从窗口对象访问应用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要在赛普拉斯测试中访问我的vuex存储,因此我将应用程序添加到了main.js中的window对象中。

  const app = new Vue({
路由器,
商店,
渲染:h => h(App)
})。$ mount(#app );

window.vueApp =应用;

然后我尝试在登录命令(commands.js)中访问它:

  cy 
.request({
method: POST,
url: http:// localhost:8081 / api / v1 / login,
正文:{},
标头:{
授权:基本 + btoa(管理员:12345678)
}
}}
.then(resp => {
console.log( app:,window.vueApp);
...
window.localStorage .setItem( aq-username, administrator);
});

但是它始终是不确定的,我在做什么错?

解决方案

窗口指的是柏树赛跑者窗口。如果要访问AUT的窗口(被测试的应用程序),请使用


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 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...:

这篇关于赛普拉斯:无法从窗口对象访问应用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆