Selenium Java code to target on Remote Desktop Connection

Viewed 148

I am trying to run SQL queries on MS SQL Server database which is installed on a Remote machine.

I have managed to open the Windows Remote Desktop Connection using a AutoScript exe, but when I trying to run any following commands they run on local machine instead of the RDP session. I tried opening a Chrome Browser after connecting to Remote machine with AutoScript but the browser opens in local. Is there anything I can use to focus on the RDP session and run the commands on this remote machine?

Any pointers will be helpfull

My Code :

static WebDriver driver;
static String baseURL = "https://www.google.com"; 
public static void main(String[] args) throws IOException, InterruptedException, SQLException, ClassNotFoundException {
    

    Runtime.getRuntime().exec("C:\\Neeraj\\Selenium\\RemoteMachineConnection.exe");
    Thread.sleep(20000);
    
    System.setProperty("webdriver.chrome.driver", "./src/drivers/chromedriver.exe");        
    driver = new ChromeDriver();
    driver.manage().window().maximize();
    driver.get(baseURL);
    
    String url ="jdbc:sqlserver://MachineName:1434;databaseName=DBName;integratedSecurity=true";
    Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
    Connection conn = DriverManager.getConnection(url);
    Statement stmt = conn.createStatement();
        String SQL = "SELECT TOP 10 * FROM [DBNAME].[dbo].[TableName]";
        ResultSet rs = stmt.executeQuery(SQL);
    
}       
0 Answers
Related