Reputation: 127
I want to automate certain tasks which needs it to go through Remote Desktop Connection.
I will share the code which I wrote till now.
public class MainClass
{
static WebDriverWait wait;
static WebDriver driver;
public static void main(String args[])
{
driver = new HtmlUnitDriver(true);
driver.get("https://mysite");
WebElement submit_element=driver.findElement(By.id("Log_On"));
driver.findElement(By.id("Enter user name")).sendKeys("my_username");
driver.findElement(By.name("passwd")).sendKeys("my_password");
submit_element.click();
driver.findElement(By.id( "folderLink_0")).click();
driver.findElement(By.id( "folderLink_2")).click();
driver.manage().timeouts().implicitlyWait(100, TimeUnit.SECONDS);
System.out.println(driver.getPageSource());
driver.findElement(By.id("idCitrix.M")).click();
System.out.println(driver.getPageSource());
}
}
The line of code
`driver.findElement(By.id("idCitrix.M")).click();`
opens the remote desktop in a new window.
The line
`System.out.println(driver.getPageSource());`
is retrieving the same code in both places.
I believe this cannot be done solely by Selenium. By browsing through the Internet I learnt it is possible to do this using AutoIt.
How can I do it?
Upvotes: 3
Views: 11804
Reputation: 2507
Selenium can be used for the parts that are automating your web browser whereas AutoIT should be used for automating Windows applications (in your case, its probably logging into the remote machine).
This link provides good information on how to use AutoIT alongwith Selenium: http://www.toolsqa.com/selenium-webdriver/autoit-selenium-webdriver/
Here is what you have to do:
Download/install AutoIT
You will be able to create .au3 scripts using AutoIT SciTe Editor
Compiling the .au3 script will give you a .exe file
Then you can invoke the .exe file from your Selenium script using
Runtime.getRuntime().exec("D:\AutoIt\AutoItTest.exe");
You can get the properties of a window using the AutoIT Window Info (x86) or (x64). Example, title / status bar of a window.
AutoIT also has Au3 Recorder so that you can record your actions that are related to the remote desktop.
Below is a sample script that automates Http authentication:
WinWaitActive("Web page title","","10")
If WinExists("Web page title") Then
Send("userid{TAB}")
Send("password{Enter}")
EndIf
Below script gets the text present in the status bar of Notepad:
WinWaitActive("Untitled - Notepad", "", 30)
Local $hWnd = WinGetHandle("Untitled - Notepad")
Local $sText = StatusbarGetText("Untitled - Notepad","",2)
ConsoleWrite($sText)
I hope this information helps!
Update: Upon further searching, found this library AutoITx4Java - https://code.google.com/p/autoitx4java/
Sample Code
File file = new File("lib", "jacob-1.15-M4-x64.dll"); //path to the jacob dll
System.setProperty(LibraryLoader.JACOB_DLL_PATH, file.getAbsolutePath());
AutoItX x = new AutoItX();
String notepad = "Untitled - Notepad";
String testString = "this is a test.";
x.run("notepad.exe");
x.winActivate(notepad);
x.winWaitActive(notepad);
x.send(testString);
Assert.assertTrue(x.winExists(notepad, testString));
x.winClose(notepad, testString);
x.winWaitActive("Notepad");
x.send("{ALT}n");
Assert.assertFalse(x.winExists(notepad, testString));
Upvotes: 3