Vue.js
Vue.js என்பது வலை பயனர் இடைமுகங்களை உருவாக்குவதற்கான அணுகக்கூடிய, செயல்திறன் மிக்க மற்றும் பல்துறை கட்டமைப்பாகும். WebdriverIO மற்றும் அதன் உலாவி இயக்கி பயன்படுத்தி Vue.js கூறுகளை நேரடியாக உண்மையான உலாவியில் சோதிக்கலாம்.
அமைவு
உங்கள் Vue.js திட்டத்தில் WebdriverIO ஐ அமைக்க, எங்கள் கூறு சோதனை ஆவணங்களில் வழிமுறைகளை பின்பற்றவும். உங்கள் இயக்கி விருப்பங்களில் vue
ஐ முன்னமைப்பாக தேர்ந்தெடுக்க உறுதிசெய்யவும், எ.கா:
// wdio.conf.js
export const config = {
// ...
runner: ['browser', {
preset: 'vue'
}],
// ...
}
நீங்கள் ஏற்கனவே Vite ஐ உருவாக்க சேவையகமாக பயன்படுத்துகிறீர்கள் என்றால், உங்கள் WebdriverIO கட்டமைப்பில் vite.config.ts
இல் உள்ள உங்கள் கட்டமைப்பை மீண்டும் பயன்படுத்தலாம். மேலும் தகவலுக்கு, இயக்கி விருப்பங்களில் viteConfig
ஐப் பார்க்கவும்.
Vue முன்னமைப்புக்கு @vitejs/plugin-vue
நிறுவப்பட வேண்டும். மேலும், கூறுகளை சோதனை பக்கத்தில் காட்சிப்படுத்த Testing Library பயன்படுத்த பரிந்துரைக்கிறோம். அதற்காக பின்வரும் கூடுதல் ச ார்புகளை நிறுவ வேண்டியிருக்கும்:
- npm
- Yarn
- pnpm
- Bun
npm install --save-dev @testing-library/vue @vitejs/plugin-vue
yarn add --dev @testing-library/vue @vitejs/plugin-vue
pnpm add --save-dev @testing-library/vue @vitejs/plugin-vue
bun add --dev @testing-library/vue @vitejs/plugin-vue
பின்னர் பின்வருமாறு இயக்குவதன் மூலம் சோதனைகளைத் தொடங்கலாம்:
npx wdio run ./wdio.conf.js
சோதனைகளை எழுதுதல்
பின்வரும் Vue.js கூறு இருப்பதாக வைத்துக் கொள்ளுங்கள்:
<template>
<div>
<p>Times clicked: {{ count }}</p>
<button @click="increment">increment</button>
</div>
</template>
<script>
export default {
data: () => ({
count: 0,
}),
methods: {
increment() {
this.count++
},
},
}
</script>
உங்கள் சோதனையில் கூறுகளை DOM-இல் காட்சிப்படுத்தி அதன் மீது உறுதிப்படுத்தல்களை இயக்கவும். கூறுகளை சோதனை பக்கத்துடன் இணைக்க @vue/test-utils
அல்லது @testing-library/vue
பயன்படுத்த பரிந்துரைக்கிறோம். கூறுகளுடன் தொடர்புகொள்ள WebdriverIO கட்டளைகளைப் பயன்படுத்தவும், ஏனெனில் அவை உண்மையான பயனர் தொடர்புகளுக்கு நெருக்கமாக செயல்படுகின்றன, எ.கா:
- @vue/test-utils
- @testing-library/vue
import { $, expect } from '@wdio/globals'
import { mount } from '@vue/test-utils'
import Component from './components/Component.vue'
describe('Vue Component Testing', () => {
it('increments value on click', async () => {
// The render method returns a collection of utilities to query your component.
const wrapper = mount(Component, { attachTo: document.body })
expect(wrapper.text()).toContain('Times clicked: 0')
const button = await $('aria/increment')
// Dispatch a native click event to our button element.
await button.click()
await button.click()
expect(wrapper.text()).toContain('Times clicked: 2')
await expect($('p=Times clicked: 2')).toExist() // same assertion with WebdriverIO
})
})
import { $, expect } from '@wdio/globals'
import { render } from '@testing-library/vue'
import Component from './components/Component.vue'
describe('Vue Component Testing', () => {
it('increments value on click', async () => {
// The render method returns a collection of utilities to query your component.
const { getByText } = render(Component)
// getByText returns the first matching node for the provided text, and
// throws an error if no elements match or if more than one match is found.
getByText('Times clicked: 0')
const button = await $(getByText('increment'))
// Dispatch a native click event to our button element.
await button.click()
await button.click()
getByText('Times clicked: 2') // assert with Testing Library
await expect($('p=Times clicked: 2')).toExist() // assert with WebdriverIO
})
})
Vue.js க்கான WebdriverIO கூறு சோதனை தொகுப்பின் முழு எடுத்துக்காட்டை எங்கள் எடுத்துக்காட்டு களஞ்சியத்தில் காணலாம்.