gpt4 book ai didi

java - 在java selenium中执行测试用例之前,我可以在桌面上显示消息吗?

转载 作者:行者123 更新时间:2023-12-01 22:58:26 25 4
gpt4 key购买 nike

我想在启动浏览器之前显示类似“在这个测试用例中我正在登录我的帐户”的消息,例如弹出消息或一些纯文本。我知道我可以使用 System.out.print() 在控制台中打印此语句,但我需要在桌面屏幕本身上显示此消息。

有办法做到这一点吗?

最佳答案

我已经使用这个很多年了。我添加了一个 main 方法,以便您可以在一个类文件中尝试它:

    import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.SwingConstants;

@SuppressWarnings("serial")
public class Popup extends JPanel {

public static void main(String[] args) {
Popup a = new Popup();
a.popup("Title", "Message");
}

public void popup(String title, String message) {
String markup = "<html><font color=#0033CC size=+1>" + message + "</html>";
JLabel l = new JLabel(markup);
l.setHorizontalAlignment(SwingConstants.CENTER);
JPanel p = new JPanel(new java.awt.GridLayout(0, 1));
p.add(l);
JFrame f = new JFrame(title);
f.setContentPane(p);
f.setSize(600, 200);
f.setLocationRelativeTo(null);
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
long startTime = System.currentTimeMillis();
while (System.currentTimeMillis() < (startTime + 5000)) {
f.setVisible(true);
}
f.setVisible(false);
f.dispose();
f = null;
}
}

关于java - 在java selenium中执行测试用例之前,我可以在桌面上显示消息吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58430652/

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