Automate Windows Desktop Apps

Step 1:
Download the below jars
http://mvnrepository.com/artifact/com.github.2gis.winium/winium-elements-desktop/0.1.0-1
http://mvnrepository.com/artifact/com.github.2gis.winium/winium-elements-desktop/0.2.0-1

Along with these two jars you need to have selenium latest jar as well. You can get the latest selenium jar from the below path.
http://docs.seleniumhq.org/download/

Step 2:
Download Winium.Desktop.Driver.exe file from https://github.com/2gis/Winium.Desktop/releases (Latest). Extract the zip file

Step 3:
Run the Winium.Desktop.Driver.exe file (by double clicking the Winium. Desktop.Driver.exe file). So that a Winium desktop server will be started and running at port 9999.

Step 4:
Create a sample Java project and add the downloaded jars into the class path of the project and also TestNG Library. Now create a class and use the below code.

package Calculator;package Calculator;
import java.net.URL;
import org.openqa.selenium.By;import org.openqa.selenium.winium.DesktopOptions;import org.openqa.selenium.winium.WiniumDriver;

public class Notepad {

 public static void main(String[] args) throws Exception { 

 DesktopOptions option = new DesktopOptions();

 option.setApplicationPath("C:\\WINDOWS\\system32\\notepad.exe");

 try {

WiniumDriver driver = new WiniumDriver(new URL("http://localhost:9999"), option); 

Thread.sleep(1000); driver.findElement(By.name("Text Editor")).sendKeys("This is sample test");

driver.findElement(By.name("Close")).click(); 

driver.findElementByName("Don't Save").click(); 

} 
catch (Exception e)
{ System.out.println(e.getMessage()); 
}
}
}

Step 5:
Run this code . It opens the notepad and enters the text on the note pad and also tries to close it.

 

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

w

Connecting to %s