Giter Club home page Giter Club logo

Comments (5)

miherlosev avatar miherlosev commented on July 29, 2024 1

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.

miherlosev avatar miherlosev commented on July 29, 2024

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.

nshCore avatar nshCore commented on July 29, 2024

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

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

miherlosev avatar miherlosev commented on July 29, 2024

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.

nshCore avatar nshCore commented on July 29, 2024

is there a way to access vue computed properties with the default selectors?

from testcafe-vue-selectors.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.