I've created Keyboard class for working with Robot. But when I starting using methods from this class I have error in logs.
Here's my Keyboard.java
with method pressEscape()
:
public class Keyboard {
private static Robot robot;
private static int time = 1000;
public Keyboard(){
try {
robot = new Robot();
} catch (AWTException e) {
e.printStackTrace();
}
}
public void pressEscape() throws TestException {
if (!getSession().CanRun())
throw new TestException(InvalidStateMessage);
robot.delay(time);
robot.keyPress(KeyEvent.VK_ESCAPE);
robot.delay(time);
robot.keyRelease(KeyEvent.VK_ESCAPE);
robot.delay(time);
}
}
And here's error from log:
[2015/08/13 15:43:29] [ID:7F4315A] [Selenium]: java.lang.NullPointerException
[2015/08/13 15:43:29] [ID:7F4315A] [Selenium]: at Kodak.AutoTest.Framework.Keyboard.pressEscape(Keyboard.java:128)
Change a little method:
public void pressEscape() throws TestException {
if (!getSession().CanRun())
throw new TestException(InvalidStateMessage);
try {
new Robot();
robot.setAutoDelay(time);
robot.keyPress(KeyEvent.VK_ESCAPE);
robot.setAutoDelay(time);
robot.keyRelease(KeyEvent.VK_ESCAPE);
} catch (AWTException e) {
e.printStackTrace();
}
}
but still has the same error on line:
robot.keyPress(KeyEvent.VK_ESCAPE);