我有一個使用 運行的應用程式Vue,并且我正在使用testcafe它來進行端到端測驗。
我的模塊.ts
class MyModule {
public value: string;
constructor() {}
}
export default new MyModule();
測驗咖啡館檔案
import MyModule from '../models/utils/MyModule';
fixture('Getting Started')
.page('http://localhost:8080/en/home/')
.before(async (ctx) => {
MyModule.value = 'Set by Test Cafe';
});
test('Get to the home page', async (t) => {
....
});
應用程式.vue
<template>.....</template>
<script>
import TeMyModulestModule from '@/test/e2e/models/utils/MyModule';
export default {
created() {
console.log('MyModule.value', MyModule.value);
}
}
</script>
實際結果
MyModule.value 未定義
預期結果
MyModule.value '由測驗咖啡館設定'
問題
是否可以通過 testCafe 實作這一目標?如果是這樣,我做錯了什么?
uj5u.com熱心網友回復:
TestCafe 測驗夾具是一個常規的 node.js 腳本,它在服務器端執行。您正在嘗試在不同的背景關系(node.js 服務器端和瀏覽器客戶端)之間共享您的模塊。
您可以使用ClientFunction或Inject Client Scripts方法將指定的值放入全域window物件中,并從 Vue 腳本中獲取。
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/422904.html
標籤:
