我一直在为我们的Nuxt应用程序E2E测试尝试Testcafe,因为我了解它具有VueJS的良好选择器,并且除通过调用放大以进行用户登录/注册的部分外,其工作情况都非常好。这可能是一个测试咖啡馆和扩大问题,而不是前端框架问题,因为登录/注册工作正常。还尝试用普通的REST api调用替换Cognito调用,它也可以正常工作。也曾与Cypress一起尝试过,并且工作正常,但Testcafe在跨浏览器测试方面具有更好的覆盖范围,因此也许是一个更好的选择。您知道我如何解决该错误,或者更好地研究不同的框架吗?将尝试以最佳方式共享我的代码,因为我无法共享自己公司的回购。如有需要,我们将乐意为您提供更多代码或说明。谢谢,找到下面的代码:
我的提交功能:
async submit() {
this.$v.$touch();
if (this.$v.$invalid) return;
this.disabled = true;
try {
await this.registerUser({
username: this.email,password: this.newPassword,attributes: {
given_name: this.firstname,family_name: this.lastname,email: this.email,'custom:isPerson': 'true','custom:dataPrivacy': 'true'
}
});
this.$router.push(this.appendLocalization('/user/confirmuser'));
this.disabled = false;
} catch (error) {
this.$log.error('Could not register user',error);
this.disabled = false;
}
放大功能:
import Auth from '@aws-amplify/auth';
import Amplify from '@aws-amplify/core';
Amplify.configure({
Auth: {
userPoolId: process.env.userPoolId,userPoolWebClientId: process.env.userPoolWebClientId,region: process.env.region
}
});
export const state = () => {
return {
session: {},user: {}
};
};
export const mutations = {
setUser: (state,user) => {
state.user = { ...user };
state.session = state.user.signInUserSession;
}
};
registerUser: ({ commit },credentials) =>
new Promise((resolve,reject) => {
Auth.signUp({
username: credentials.username,password: credentials.password,attributes: credentials.attributes
})
.then((user) => {
commit('setUser',user);
resolve(user);
})
.catch(reject);
}),
我的Testcafe代码:
import { Selector,ClientFunction } from 'testcafe';
fixture`Signup Page`.page`http://localhost:3000/de/user/signup`;
const email = Selector('input').withAttribute('name','email');
const password = Selector('input').withAttribute('name','password');
const checkbox = Selector('input').withAttribute('type','checkbox');
const button = Selector('button').withAttribute('name','submit');
const getLocation = ClientFunction(() => document.location.href);
test('Test successful signup',async (t) => {
const validemail =
'WebFunctionalTest' + new Date().getTime() + '@something.com';
const validpassword = 'password';
await t
.typeText(email,validemail)
.typeText(password,validpassword)
await t.click(button).debug();
await t.expect(getLocation()).contains('userconfirm');
});
注册错误:
RangeError: Maximum call stack size exceeded
at c (hammerhead.js:16)
at i (hammerhead.js:16)
at value (hammerhead.js:6)
at _traverse (commons.app.js:12575)
at _traverse (commons.app.js:12575)
at _traverse (commons.app.js:12575)
at _traverse (commons.app.js:12575)
at _traverse (commons.app.js:12575)
at _traverse (commons.app.js:12575)
at _traverse (commons.app.js:12575)
P.S:我可以看到Testcafe正在进行cognito调用,并在“网络”标签中获得了正确的响应,但是不知何故没有在代码中对其进行处理。我认为Testcafe应该表现得像普通的用户测试一样,例如单击按钮并等待整个序列完成,即成功完成页面转换,但不然。
我花了很长时间试图弄清楚这一点,但无法在此处进行详细介绍,我们将不胜感激。预先感谢。