When I call the JFrame from another class to test, the JFrame works, but when I insert it into my Selenium test, the JFrame and the browser open so quickly that there's no time to input anything and the test appears like passed.
Sample of the elements that I mention:
@Test
public void Run() throws InterruptedException{
Keys.loginFrame(); //This method is static in another class named 'Keys'
...
}
Is there any way to say to Selenium the following?:
Execute first ONLY Keys.loginFrame();
, then wait till the JFrame is closed. Finally execute the rest of the test code.
Thank you for your answers!
loginFrame()
method to return JFrame
objectpublic static void startFrameThread(JFrame frame) {
Thread thread = new Thread() {
public void run() {
while (frame.isVisible()) {
try {
Thread.sleep(1000);
}
catch (InterruptedException e) {
}
}
}
};
thread.start();
frame.addWindowListener(new WindowAdapter() {
@Override
public void windowClosing(WindowEvent arg0) {
frame.setVisible(false);
}
});
try {
thread.join();
} catch (InterruptedException e) {
}
}
JFrame loginFrame = Keys.loginFrame();
loginFrame.setVisible(true); // if not setting visible in loginFrame() method
startFrameThread(loginFrame);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.