ssl - 在使用 TestCafe 时尝试登录 gmail

标签 ssl testing automated-tests gmail testcafe

我正在学习 TestCafe 并尝试在网站上创建一个帐户,然后登录到 Gmail 以查找激活链接。当我尝试这样做时,我只是在进入输入密码的部分时收到浏览器不安全消息。如何让 Gmail 信任 TestCafe?

最佳答案

虽然您可能会成功这样做,但这不是一个好方法,因为:

  • 通过 GUI 执行此操作很慢
  • 它很脆弱,因为选择器可能会改变,而且你无法控制谷歌电子邮件选择器,所以你甚至不知道它们是否会改变它们

  • 更好的方法是使用像 Mailosaur 这样的服务,您可以在其中创建一个帐户并接收您以后可以通过 API 查询的电子邮件。您无需在 GUI 上进行整个 e2e 流程,而是在 Mailosaur 的 API 上请求一封电子邮件,如果存在这样的电子邮件,您将收到可以解析和检查各种内容的响应。
    我过去做过这个,你可以在这里看到我的帖子:https://sqa.stackexchange.com/questions/40427/automating-verification-of-sent-email-sms-messages/45721#45721 这正是 Mailosaur 和 Testcafe(加上它需要 axios 作为一个包),所以它似乎是你要找的。
    在此处添加相同的代码:
    import config from '../config';
    import { customAlphabet } from 'nanoid';
    import axios from 'axios';
    import Newsletter from '../Objects/newsletter';
    
    async function request (reqObject) {  
        try {
            return await axios(reqObject);            
        } catch (error) {
            console.error(error);
        }
    }
    
    function serverId () {
        return process.env.MAILOSAUR_SERVER_ID;
    }
    
    function mailosaurFullEmail (id) {
        return (id ? id : nanoid()) + '.' + serverId() 
            + '@' + config.mailosaurDomain;
    }
    
    fixture `Newsletter`    
        .page(baseUrl);
    
    test             
        ('Sign Up For Newsletter', async t => {
    
            const id = (customAlphabet('1234567890', 10))();
    
            await t
                .typeText(Newsletter.newsEmailInput, mailosaurFullEmail(id))
                .click(Newsletter.consent)
                .click(Newsletter.sendButton);
    
            let res = await request({
                method: 'POST',
                url: config.mailosaurUrlEmail + serverId(),
                headers: {
                    'Authorization': 'Basic ' 
                        + Buffer.from(process.env.MAILOSAUR_API_KEY)
                            .toString('base64'),
                    'Content-Type': 'application/json'
                },
                data: {
                    sentTo: mailosaurFullEmail(id)
                }
            });       
            
            await t
                .expect(res.status).eql(200);
    });
    
    它需要一些配置值:
    {
        "mailosaurUrlEmail": "https://mailosaur.com/api/messages/await?server=",
        "mailosaurDomain": "mailosaur.io"
    }
    
    这肯定要好得多,但它仍然有一些限制:
  • Mailosaur的API仍然可以改变,所以它不会完全没有任何维护
  • 它假定在用户操作后立即发送电子邮件(在我的情况下为时事通讯),但这在许多情况下可能与现实相去甚远,例如当电子邮件被发送到队列时,很容易需要几分钟才能发送电子邮件

  • 如果您绝对必须通过 Gmail 进行操作,您最好还是查看他们的 API,它应该允许您搜索和查询电子邮件消息。

    关于ssl - 在使用 TestCafe 时尝试登录 gmail,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64894932/

    相关文章:

    PHPMailer错误连接: opening to ssl://smtp. gmail.com :465,超时=300,选项=数组()

    typescript - 用 Jest 在 typescript 中模拟导入的类

    performance - JMeter 是否最终以前端作为入口点测试 Web 应用程序的后端?

    android - Retrofit 不支持 CLEARTEXT 通信

    node.js - 在 nodejs : cert. crt 和 sf_bundle-g1-g2.crt 中使用 GoDaddy 的 HTTPS 证书

    android - 使用 Espresso 在底页中找不到 View

    testing - 选项不适用于运行者

    continuous-integration - 如何自动测试 Prometheus 警报?

    windows - 我可以使用什么脚本工具来自动测试 Delphi 程序?

    java - Spring Kafka 客户端 SSL 设置