我正在使用 Playwright 测试一个登录表单,该表单具有以下两种可能的状态之一:
由于我们的身份验证系统的某些逻辑,完全确定性是不切实际的,因此我需要确保我的测试成功处理每种情况。
一种这样的解决方案是[1]:
if (await page.getByRole('button', { name: 'Sign In' }).count() > 0) {
await page.getByLabel('Password').fill('password');
await page.getByRole('button', { name: 'Sign In' }).click();
} else {
await page.getByLabel('First & last name').fill('Bob Alice');
await page.getByLabel('Password').fill('password');
await page.getByRole('button', { name: 'Save' }).click();
}
Run Code Online (Sandbox Code Playgroud)
但是,这需要页面等待我的超时才能继续。我可以减少条件检查的超时[2],但这会增加测试的脆弱性。
如何在不强制超时的情况下使用条件逻辑来确保执行 Playwright 中的两个代码路径之一?
我正在尝试设置 GCP Cloud Function 来使用 生成电子邮件验证链接admin.auth().generateEmailVerificationLink,但它会引发错误:
Error: Credential implementation provided to initializeApp() via the "credential" property has insufficient permission to access the requested resource. See https://firebase.google.com/docs/admin/setup for details on how to authenticate this SDK with appropriate permissions.
Run Code Online (Sandbox Code Playgroud)
我能够使用以下云函数代码重现此错误:
索引.js:
const admin = require('firebase-admin');
admin.initializeApp();
exports.helloWorld = (req, res) => {
execute(res);
};
const execute = async (res) => {
const email = 'test@test.com';
const url = 'https://example.firebaseapp.com';
const link = await admin.auth().generateEmailVerificationLink(email, { url });
console.log(link);
res.status(200).send(link);
}; …Run Code Online (Sandbox Code Playgroud)