Skip to content

Instantly share code, notes, and snippets.

@thibaut-sticky
Created January 29, 2015 09:32
Show Gist options
  • Save thibaut-sticky/fea9891358d592b2da62 to your computer and use it in GitHub Desktop.
Save thibaut-sticky/fea9891358d592b2da62 to your computer and use it in GitHub Desktop.
Click on Flash element [Helpful for Grid Selenium]
/**
*
*/
package com.tetienne.qa.client.remote;
import com.jcraft.jsch.Channel;
import com.jcraft.jsch.ChannelExec;
import com.jcraft.jsch.JSch;
import com.jcraft.jsch.JSchException;
import com.jcraft.jsch.Session;
/**
* Open a SSH connection with a remote machine and send mouse or keyboard events
*
* @author tetienne
*
*/
public class Control {
private JSch jSch;
private Session session;
private final static String HOST = "192.168.1.69";
private final static String USERNAME = "qa";
private final static String PASSWORD = "'qa";
private final static int SSH_PORT = 22;
private final static String MOVE_CLICK_CMD = "DISPLAY=:0 xdotool mousemove %d %d click 1";
public Control() {
jSch = new JSch();
initConnection();
}
public void leftClickAt(int x, int y) {
try {
String command = String.format(MOVE_CLICK_CMD, x, y);
Channel channel = session.openChannel("exec");
((ChannelExec) channel).setCommand(command);
channel.connect();
}
catch (Exception e) {
System.err.println("Error: " + e);
}
}
private void initConnection() {
try {
session = jSch.getSession(USERNAME, HOST, SSH_PORT);
session.setPassword(PASSWORD);
session.setConfig("StrictHostKeyChecking", "no");
session.connect();
}
catch (JSchException e) {
System.err.println("Ooops. Error Connecting");
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment