如何在测试自动化中处理Firefox浏览器的确认消息?

huangapple 未分类评论48阅读模式
英文:

How to handle Firefox browser confirmation messages in Test Automation?

问题

我目前正在进行selenium+java测试自动化项目
我遇到了一个问题,就是在testng.xml中一起运行许多测试类时,火狐浏览器会显示如何在测试自动化中处理Firefox浏览器的确认消息?确认重新提交的弹窗。但是当我只运行单个类时,不会弹出此消息。这个确认弹窗出现在最后一组类开始运行时。我该如何解决这个问题?

英文:

I am currently working on the selenium+java test automation project.
I have encountered a problem that while running many test classes together in testng.xml, firefox display
如何在测试自动化中处理Firefox浏览器的确认消息? confirm resubmission popup.
when I am running a single class this message does not popup. This confirmation popup comes when the last set of classes begins to run. How can I resolve this problem?

答案1

得分: 0

也许,你可以尝试模拟按下回车键或空格键,看看是否起作用。

import java.awt.Robot;
import java.awt.event.KeyEvent;

public void pressEsc(WebDriver driver) {
    try {
        Robot robot = new Robot();
        robot.keyPress(KeyEvent.VK_ENTER);
        robot.keyRelease(KeyEvent.VK_ENTER);
    } catch (Exception e) {
        e.printStackTrace();
    }
}
英文:

May be, you can try to simulate pressing Enter key or Spacebar and see if that works.

import java.awt.Robot;
import java.awt.event.KeyEvent;

public void pressEsc(WebDriver driver) {
try {
	Robot robot = new Robot();
	robot.keyPress(KeyEvent.VK_ENTER);
	robot.keyRelease(KeyEvent.VK_ENTER);
} catch (Exception e) {
	e.printStackTrace(); }
}

huangapple
  • 本文由 发表于 2020年5月3日 16:07:41
  • 转载请务必保留本文链接:https://java.coder-hub.com/61571395.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定