Automation for Windows Desktop Applications

AAEAAQAAAAAAAAuhAAAAJDg0MTllY2JlLWJlYjUtNDllOC05M2NmLWMxNzkxMzczYjU2YQ

      There are lots of different automation tools and frameworks are available for windows applications like – Sikuli, AutoIt, Winium etc. I have gone through all of them for desktop application (windows) automation for testing. All of them have different pros and cons.

        Among all of them I found Winium the most easy and handy automation framework for desktop application. Winium is Selenium Remote WebDriver implementation for automated testing of Windows application based on WinFroms and WPF platforms. I have done a POC with Winium. Following are the details:

Prerequisites:

  • Install Microsoft .NET Framework 4.5.1
  • Create Maven Project and add following dependencies in pom.xml file
    • selenium-java
    • selenium-server
    • winium-elements-desktop
    • winium-webdriver

Here I identified notepad.exe for automation.

How can we create a Winium Driver session?

WebDriver driver = null;
String notepadApplicationPath = “C:\\Windows\\System32\\notepad.exe”;
String winiumDriverPath = “D:\\SeleniumDrivers\\Winium.Desktop.Driver.exe”;// To stop winium desktop driver before start another session
Process process = Runtime.getRuntime().exec(“taskkill /F /IM Winium.Desktop.Driver.exe”);
process.waitFor();
process.destroy();
DesktopOptions options = new DesktopOptions(); // Initiate Winium Desktop Options
options.setApplicationPath(notepadApplicationPath); // Set notepad application path
WiniumDriverService service = new WiniumDriverService.Builder().usingDriverExecutable(new File(winiumDriverPath)).usingPort(9999).withVerbose(true).withSilent(false).buildDesktopService();
service.start(); // Build and Start a Winium Driver service
Thread.sleep(5000);
driver = new WiniumDriver(service, options); // Start a winium driver
Thread.sleep(10000);

Once you get the driver you can start your automation scripts like selenium scripting,

Thread.sleep(5000);
driver.findElement(By.name(“Format”)).click();
Thread.sleep(1000);
driver.findElement(By.name(“Font…”)).click();
Thread.sleep(1000);
driver.findElement(By.name(“Bold”)).click();
Thread.sleep(1000);
driver.findElement(By.name(“OK”)).click();
Thread.sleep(1000);
driver.findElement(By.className(“Edit”)).sendKeys(“Welcome to Winium”);
Thread.sleep(1000);
driver.findElement(By.name(“File”)).click();
Thread.sleep(1000);
driver.findElement(By.name(“Save”)).click();
Thread.sleep(1000);
driver.findElement(By.name(“File name:”)).sendKeys(“NewFile”);
Thread.sleep(1000);
driver.findElement(By.name(“Save”)).click();
Thread.sleep(1000);
driver.findElement(By.name(“Close”)).click();

NOTE: 

Process process = Runtime.getRuntime().exec(“taskkill /F /IM Winium.Desktop.Driver.exe”);
process.waitFor();
process.destroy();

make it perfect !

Different Driver Services in Selenium and Appium

     mobile-application-testing-with-selenium-and-appium

     As we know that the importance of Automation is increasing day-by-day. And also most of them are looking for open source tools like Selenium and Appium. In 2017, there are some modification happened in Driver instantiation for Selenium Drivers and Appium Drivers. They are commonly using DriverServices to build and start the services for different automation sessions. Here I would like to explain important Driver Services from Selenium and Appium.

For Internet Explorer:
WebDriver driver;
InternetExplorerDriverService service = new InternetExplorerDriverService.Builder().usingDriverExecutable(new File(<path to IEdriver executable>)).usingAnyFeePort().withLogFile(new File(System.getProperty(“userdir”)+”\\Logs\\Browser_logs\\InterntExplorer_”+getCurrentDateAndTime()+”.txt”)).withLogLevel(InternetExploreDriverLogLevel.DEBUG).build();
driver = new InternetExplorerDriver(service);

For Chrome:

WebDriver driver;
ChromeDriverService chromeservices = new ChromeDriverService.Builder().usingDriverExecutable(new File(<path to chromedriver executable>)).usingAnyFreePort().withLogFile(new File(System.getProperty(“userdir”)+”\\Logs\\Browser_logs\\Chrome_”+ getCurrentDateAndTime() + “.txt”)).withVerbose(true).build();
driver = new ChromeDriver(chromeservices);

For Firefox:

WebDriver driver;
FirefoxOptions options = new FirefoxOptions();
options.setLogLevel(FirefoxDriverLogLevel.DEBUG);
GeckoDriverService geckodriverservice = new GeckoDriverService.Builder().usingDriverExecutable(new File(<path to geckodriver executable>)).usingAnyFreePort().withLogFile(new File(System.getProperty(“user.dir”) + “\\Logs\\Browser_logs\\Firefox”+getCurrentDateAndTime() + “.txt”)).build();
driver = new FirefoxDriver(geckodriverservice, options);

For Edge:

WebDriver driver;
EdgeDriverService edgeservice = new EdgeDriverService.Builder().usingDriverExecutable(new File(<path to edgedriver executable>)).usingAnyFreePort().withLogFile(new File(System.getProperty(“user.dir”)+”\\Logs\\Browser_logs\\Edge_”+ getCurrentDateAndTime() + “.txt”)).build();
driver = new EdgeDriver(edgeservice);

For PhantomJS:

WebDriver driver;
Capabilities caps = new DesiredCapabilities();
((DesiredCapabilities) caps).setJavascriptEnabled(true);
((DesiredCapabilities) caps).setCapability(“takesScreenshot”, true);
PhantomJSDriverService phantomjsservice = new PhantomJSDriverService.Builder().usingPhantomJSExecutable(new File(<path to phantomjs executable>)).usingAnyFreePort().withLogFile(new File(System.getProperty(“user.dir”)+”\\Logs\\Browser_logs\\PhantomJS_”+ getCurrentDateAndTime() + “.txt”)).build();
driver = new PhantomJSDriver(phantomjsservice, caps);

For Electron Rendered Applications:

WebDriver driver;
ChromeOptions options = new ChromeOptions();
options.setBinary();
ChromeDriverService chromeservices = new ChromeDriverService.Builder().usingDriverExecutable(new File(< path to chromedriver executable>)).usingAnyFreePort().withLogFile(new File(System.getProperty(“user.dir”) +”\\Logs\\Browser_logs\\Electron_”+ getCurrentDateAndTime() + “.txt”)).withVerbose(true).build();
driver = new ChromeDriver(chromeservices, options);

For Safari:

WebDriver driver;
SafariOptions options = new SafariOptions();
options.useCleanSession(true);
driver = new SafariDriver(options);

For Appium:

WebDriver driver;
AppiumDriverLocalService driverService = AppiumDriverLocalService.buildService(new AppiumServiceBuilder()
.withAppiumJS(new File()).usingDriverExecutable(new File()).withIPAddress(“127.0.0.1″).usingPort(4723).withArgument(AndroidServerFlag.BOOTSTRAP_PORT_NUMBER,”4724″).withArgument(AndroidServerFlag.CHROME_DRIVER_PORT,”4725”).withLogFile(new File(new File( System.getProperty(“user.dir”) +”\\Appium_logs\\appiumLogs_” + getCurrentDateAndTime() + “.txt”))
.withArgument(GeneralServerFlag.LOG_NO_COLORS));
driverService.start();

For Winium (Windows Desktop Applications):

WebDriver driver;
DesktopOptions options = new DesktopOptions();
options.setApplicationPath(<path to windowsApplication>);
WiniumDriverService service = new WiniumDriverService.Builder().usingDriverExecutable(new File(< path to winiumDriver executable>)).usingPort(9999) .withLogFile(new File(System.getProperty(“user.dir”) + “\\Logs\\Windows_logs\\Win_” + getCurrentDateAndTime() + “.txt”)) .withVerbose(false).withSilent(false).buildDesktopService();
service.start();
driver = new WiniumDriver(service, options);

Try to use above mentioned Driver Services in your automation scripts.

make it perfect !