0

我在Windows 11上使用 Cucumber+Selenium Java(Eclipse) 在 Chrome 浏览器上执行自动化测试用例,为从电子邮件收到的帐户确认屏幕添加 OTP。控制台上显示以下错误消息:

javax.mail.AuthenticationFailedException: [ALERT] Please log in via your web browser: https://support.google.com/mail/accounts/answer/78754 (Failure)
    at com.sun.mail.imap.IMAPStore.protocolConnect(IMAPStore.java:732)
    at javax.mail.Service.connect(Service.java:366)
    at javax.mail.Service.connect(Service.java:246)
    at utils.OTPNumberReader.OTPNumberValue(OTPNumberReader.java:41)

当我在Windows 10 Chrome上执行相同的测试用例时,OTP 被输入到帐户确认屏幕。

try {
    Properties properties = new Properties();
    FileInputStream fis = new FileInputStream(
            System.getProperty("user.dir") + File.separator + "src"
        + File.separator + "test" + File.separator + "resources" + File.separator + "data.properties");
    //FileInputStream fis = new FileInputStream(System.getProperty("user.dir") + "/src/test/resources/data.properties");
    properties.load(fis);
    String host = properties.getProperty("host");
    String username = properties.getProperty("username");
    String password = properties.getProperty("password");
    properties.put("mail.imap.host", host);
    properties.put("mail.imap.port", "993");
    properties.put("mail.imap.starttls.enable", "true");
    properties.put("mail.imap.ssl.trust", host);
    Session emailSession = Session.getDefaultInstance(properties);
    Store store = emailSession.getStore("imaps");
    store.connect(host, username, password); //<- Error on This line
    Folder inbox = store.getFolder("INBOX");

    inbox.open(Folder.READ_ONLY);

    Message msg = inbox.getMessage(inbox.getMessageCount());
    Address[] in = msg.getFrom();

    for (Address address : in) {

    }

需要帮助。

4

0 回答 0