简体   繁体   English

如何在 JMeter 的 Webdriver Sampler 中获取警报消息?

[英]How can I get an alert-message in Webdriver Sampler for JMeter?

I need to log all alert messages while running JMeter Tests with Webdriver Sampler (and accept the alert boxes).我需要在使用 Webdriver Sampler 运行 JMeter 测试时记录所有警报消息(并接受警报框)。 I already tried to take a screenshot and accept the alert, but it didn't work:我已经尝试截屏并接受警报,但没有成功:

try{
    WDS.browser.switchTo().alert();
    WDS.browser.getScreenshotAs(JavaImporter(org.openqa.selenium).OutputType.FILE).renameTo(new java.io.File("output/screenshot.png"));
    WDS.browser.switchTo().alert().accept();
} catch(exception){
    WDS.log.info(exception);
}

Screenshot of Sampler Result采样器结果截图

Current version of the WebDriver Sampler is 3.1 which assumes Selenium Support library version 3.14.0 WebDriver Sampler的当前版本是3.1 ,它假定Selenium 支持库版本 3.14.0

As of Selenium Support library version 3.14.0 you cannot take screenshots (and in fact do anything else) until the alert is present and active, so it means that you cannot take browser screenshot by means of Selenium.从 Selenium 支持库版本 3.14.0 开始,在警报出现并激活之前,您无法截取屏幕截图(实际上可以做任何其他事情),因此这意味着您无法通过 Selenium 截取浏览器截图。

If you do need the screenshot of your page with the alert you can go for Robot.createScreenCapture() function , the alternative code would be something like:如果您确实需要带有警报的页面屏幕截图,您可以 go for Robot.createScreenCapture() function ,替代代码将类似于:

new org.openqa.selenium.support.ui.WebDriverWait(WDS.browser, 2000).until(org.openqa.selenium.support.ui.ExpectedConditions.alertIsPresent())
javax.imageio.ImageIO.write(new java.awt.Robot().createScreenCapture(new java.awt.Rectangle(java.awt.Toolkit.getDefaultToolkit().getScreenSize())), "png", new java.io.File("output/screenshot.png"));
WDS.browser.switchTo().alert().accept()

More information: The WebDriver Sampler: Your Top 10 Questions Answered更多信息: WebDriver 采样器:您回答的 10 大问题

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM