Comments (5)
Yes. You can do it using a ClientFunction feature.
I've created an example
import { Selector, ClientFunction } from 'testcafe';
fixture `Vue properties`
.page('http://localhost:8080/test/data/');
test('get Vue specific properties', async t => {
const node = Selector('#app');
const getVueProperties = ClientFunction(() => {
function getData (instance, prop) {
const result = {};
Object.keys(prop).forEach(key => {
result[key] = instance[key];
});
return result;
}
function getProps (instance) {
return getData(instance, instance.$options.props || {});
}
function getState (instance) {
const props = instance._props || instance.$options.props;
const getters = instance.$options.vuex && instance.$options.vuex.getters;
const result = {};
Object.keys(instance._data)
.filter(key => !(props && key in props) && !(getters && key in getters))
.forEach(key => {
result[key] = instance._data[key];
});
return result;
}
function getComputed (instance) {
return getData(instance, instance.$options.computed || {});
}
var nodeVue = node().__vue__;
if (!nodeVue)
return null;
var props = getProps(nodeVue);
var state = getState(nodeVue);
var computed = getComputed(nodeVue);
return {
props: props,
state: state,
computed: computed
};
}, { dependencies: { node } });
const vueProperties = await getVueProperties();
console.log(vueProperties);
});
from testcafe-vue-selectors.
Hi @jkirkby91-2
The code
const welcome = VueSelector('welcome')
const welcomeVue = await welcome.getVue()
should work.
It looks like you specified a wrong component tag name.
Could you please provide code with the Welcome
component definition?
Something like this:
Vue.component('welcome', {
props: ['id'],
template: '...'
});
from testcafe-vue-selectors.
The welcome component is served from vue-router so I will give an excerpt of my router/index.js
import Vue from 'vue'
import VueRouter from 'vue-router'
Vue.use(VueRouter)
/**
* @param component
* @returns {function()}
*/
function load (component) {
return () => import(`@/${component}.vue`)
}
/**
* @type {VueRouter}
*/
const router = new VueRouter({
base: '/',
hashbang: false,
routes: [
{
path: '/',
component: load('Welcome'),
meta: {
requiresAuth: false
}
}
}
An excerpt of my App.vue html template looks like this
<template>
<q-layout ref="layout" @scroll="scrollHandler">
<div id="q-app" :class="this.$router.currentRoute.name">
<div class="container scroll" style="height: 80vh; overflow: scroll">
<div class="row justify-center">
<transition name="slide-fade">
<router-view></router-view>
</transition>
</div>
<q-scroll-observable @scroll="scrollHandler" />
</div>
</div>
</q-layout>
</template>
vue-router I guess "injects" the welcome component into the <router-view></router-view>
Here is an example test trying to grab the welcome component
import VueSelector from 'testcafe-vue-selectors'
import { Selector, ClientFunction } from 'testcafe'
const setFakeVue = ClientFunction(() => {
window.Vue = { version: "2.2.6" }
})
fixture(`test welcome component`)
.beforeEach(async t => {
await setFakeVue()
})
.page('http://localhost:8080')
test('can we select the Welcome component', async testController => {
const welcome1 = VueSelector('Welcome')
const welcomeVue1 = await welcome1.getVue()
console.log(welcomeVue1)
})
test('can we select the welcome component', async testController => {
const welcome = VueSelector('welcome')
const welcomeVue = await welcome.getVue()
console.log(welcomeVue)
})
Which throws this error
-
An error occurred in getVue code:
TypeError: undefined is not an object (evaluating 'node.vue')
Always on the variation of this line
const welcomeVue = await welcome.getVue()
As said in my last message the welcome component does contain other custom vue elements such as a login component and buttons which it can grab and test no problem
from testcafe-vue-selectors.
Unfortunately, at present testcafe-vue-selectors
does not support components loaded via vue-router
.
I've create the issue on this.
As a workaround, try to use the build-in TestCafe selectors.
from testcafe-vue-selectors.
is there a way to access vue computed properties with the default selectors?
from testcafe-vue-selectors.
Related Issues (20)
- Support component loaded via vue-router HOT 6
- [FR] Typings HOT 2
- Can't install vue-selectors HOT 1
- Vue cmp state doens't seem to update HOT 1
- `vue-loader`: migrate to `15.x`
- Return ref along with data, props, computed and state on getVue() HOT 2
- Can't get access to global Vue (Nuxt) object, fails with error. HOT 3
- Basic usage- Vue render content not available HOT 5
- Unable to find a Vue componant within a named slot HOT 4
- Select VueComponent by props values HOT 3
- How to get to deeply nested component? HOT 1
- How to get the text of the component q-toolbar-title? HOT 1
- "babel-core" should be included in package HOT 2
- Error "_keys2 is not defined" when calling .getVue() HOT 1
- Selector() failed to access "Row" of v-data-table of Vuetify HOT 3
- .getVue() seems not working HOT 2
- .getVue() causes error HOT 5
- Select VueComponent by key HOT 3
- Searching for nested components HOT 3
- Vue3 compatibility HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from testcafe-vue-selectors.