0

I have two test cases of checking file upload which is using same piece of code as written below. For 1 test case it's pasting correct path of file upload but for other test case its only pasting character 'v' and also have anybody have idea why robot class does not work in case of if we run test cases on remote machine on jenkins.

// Lines of code for file upload test case

Robot rob = new Robot();
StringSelection ss = null;
ss = new StringSelection("C:\\repository\\A\\B\\C\\resources\\no_fog.png");
rob.setAutoDelay(2000);
Toolkit.getDefaultToolkit().getSystemClipboard().setContents(ss, null);
rob.setAutoDelay(1000);
rob.keyPress(KeyEvent.VK_CONTROL);
rob.keyPress(KeyEvent.VK_V);
rob.keyRelease(KeyEvent.VK_CONTROL);
rob.keyRelease(KeyEvent.VK_V);
rob.setAutoDelay(1000);
rob.keyPress(KeyEvent.VK_ENTER);
rob.keyRelease(KeyEvent.VK_ENTER);
rob.setAutoDelay(1000);

Can somebody provide any help on this

1 Answer 1

2

I have used Robot class for file upload and it's working fine for me try this:

Robot robot = new Robot();
StringSelection sel = new StringSelection("Path of image");
Toolkit.getDefaultToolkit().getSystemClipboard().setContents(sel, null);

 robot.delay(300);

  // Press Enter
 robot.keyPress(KeyEvent.VK_ENTER);
 robot.keyRelease(KeyEvent.VK_ENTER);

  // Press CTRL+V
 robot.keyPress(KeyEvent.VK_CONTROL);
 robot.keyPress(KeyEvent.VK_V);

// Release CTRL+V
 robot.keyRelease(KeyEvent.VK_CONTROL);
 robot.keyRelease(KeyEvent.VK_V);
 robot.delay(300);

 // Press Enter 
 robot.keyPress(KeyEvent.VK_ENTER);
 robot.keyRelease(KeyEvent.VK_ENTER);
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.