gpt4 book ai didi

Java 'Email Sending Code' > 已知异常(索引 : 14, 大小 : 14)?

转载 作者:行者123 更新时间:2023-12-02 13:05:44 25 4
gpt4 key购买 nike

我有一个自动化框架,当测试失败时,它会发送电子邮件,大多数时候代码都会工作,但是当触发以下异常时,我似乎会遇到一个奇怪的异常,因为不会发送任何电子邮件列出的异常(exception):

public class SendEmailFile {
public static void sendEmailReport(String detailsEmailTitle, String detailsEmailBody) {
{
// Recipient's email ID needs to be mentioned.
String to = "user123@mail.com";
// Sender's email ID needs to be mentioned
String from = "user123@mail.com";

// Assuming you are sending email from localhost
String host = "cluxxxx.eu.messagelabs.com";
// Get system properties
Properties properties = System.getProperties();
// Setup mail server
properties.setProperty("mail.smtp.host", host);
// Get the default Session object.
Session session = Session.getDefaultInstance(properties);

try {
// Create a default MimeMessage object.
MimeMessage message = new MimeMessage(session);

// Set From: header field of the header.
message.setFrom(new InternetAddress(from));

// Set To: header field of the header.
message.addRecipient(Message.RecipientType.TO, new InternetAddress(to));

//CC code works:
message.addRecipients(Message.RecipientType.CC, InternetAddress.parse("user321@buyagift.co.uk"));

// Set Subject: header field
message.setSubject(detailsEmailTitle);

// Create the message part
BodyPart messageBodyPart = new MimeBodyPart();


// Create a multipar message
Multipart multipart = new MimeMultipart();

// Set text message part
messageBodyPart.setContent(EmailTemplate.setupTemplate(), "text/html");
multipart.addBodyPart(messageBodyPart);

//messageBodyPart.setContent("<h1>This is actual message embedded in HTML tags</h1>" + "<h2>example text</h2>", "text/html");

/**Report Sending Functionality
messageBodyPart = new MimeBodyPart();
String filename ="C:\\Users\\xxxxx\\Desktop\\xxxxx\\xxxx\\target\\surefire-reports\\emailable-report.html";
DataSource source = new FileDataSource(filename);
messageBodyPart.setDataHandler(new DataHandler(source));
messageBodyPart.setFileName(filename);
multipart.addBodyPart(messageBodyPart);
***/

// Send the complete message parts
message.setContent(multipart);

// Send message
Transport.send(message);
System.out.println("Sent message successfully....");

} catch (MessagingException mex) {
System.out.println("Unable to Send Email!, Exception: " + mex.getMessage());
mex.printStackTrace();
}
}
}
}

尝试发送电子邮件时在 Jenkins 构建中捕获的异常:

TEST CLASS END TIME: 05.22.45
Unable to send email which contains test details, Exception: Index: 14, Size: 14
Tests run: 307, Failures: 81, Errors: 0, Skipped: 204, Time elapsed: 41.355 sec <<< FAILURE! - in TestSuite
clickOn_PaySecurelyNowButton(BuyFramework.complete.AddingDrivingExperienceToBasketTest) Time elapsed: 0.246 sec <<< FAILURE!
java.lang.NullPointerException
at BuyFramework.complete.AddingDrivingExperienceToBasketTest.clickOn_PaySecurelyNowButton(AddingDrivingExperienceToBasketTest.java:51)

EmailFormatAndDataCapture(BuyFramework.complete.AddingDrivingExperienceToBasketTest) Time elapsed: 0.252 sec <<< FAILURE!
org.openqa.selenium.UnhandledAlertException:
unexpected alert open: {Alert text : Click OK to confirm your personal message is correct as this is exactly how it will be printed.}
(Session info: chrome=58.0.3029.110)
(Driver info: chromedriver=2.29.461591 (62ebf098771772160f391d75e589dc567915b233),platform=Windows NT 10.0.10240 x86_64) (WARNING: The server did not provide any stacktrace information)
Command duration or timeout: 2 milliseconds: null
Build info: version: '3.4.0', revision: 'unknown', time: 'unknown'
System info: host: 'BG146', ip: '172.16.2.162', os.name: 'Windows 10', os.arch: 'amd64', os.version: '10.0', java.version: '1.8.0_111'
Driver info: org.openqa.selenium.chrome.ChromeDriver
Capabilities [{applicationCacheEnabled=false, rotatable=false, mobileEmulationEnabled=false, networkConnectionEnabled=false, chrome={chromedriverVersion=2.29.461591 (62ebf098771772160f391d75e589dc567915b233), userDataDir=C:\Users\Gxxxx~1.BRU\AppData\Local\Temp\scoped_dir11396_18538}, takesHeapSnapshot=true, pageLoadStrategy=normal, databaseEnabled=false, handlesAlerts=true, hasTouchScreen=false, version=58.0.3029.110, platform=XP, browserConnectionEnabled=false, nativeEvents=true, acceptSslCerts=true, locationContextEnabled=true, webStorageEnabled=true, browserName=chrome, takesScreenshot=true, javascriptEnabled=true, cssSelectorsEnabled=true, unexpectedAlertBehaviour=}]
Session ID: a9648e2aa647ebcbc6b69366b783b50c

最佳答案

我想这可能是你的线索:

org.openqa.selenium.UnhandledAlertException: unexpected alert open: {Alert text : Click OK to confirm your personal message is correct as this is exactly how it will be printed.}

看起来您的代码没有预料到,因此不会处理弹出警报?

理想情况下,您应该在 try/catch 中添加通用异常捕获行。

关于Java 'Email Sending Code' > 已知异常(索引 : 14, 大小 : 14)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44153026/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com