Thursday 1 March 2018

How to Automate Non Browser Based Functionality with Selenium + AutoIT

Selenium can automate only browser based functionality if there is scenario that any non browser based functionality like windows dialog box comes than selenium can not handle. We need to use other tool for handle such scenario.

AutoIT is best open source tool for automate non browser based functionality with selenium. We have to first configure AutoIT with selenium before use.

For configuration part please go to below link and Configure AutoIT.

Configure AutoIT with Selenium

Don't forget to register 'AutoItX3_x64.dll' because it is very important. You can not use that .dll without register.

Once you are done with configuration then create one project for automate calculator.


 public static void main(String[] args) throws InterruptedException
 {  
  String jacobDllVersion;
  if (jvmBitVersion().contains("32"))
  {
   jacobDllVersion = "jacob-1.18-M2-x86.dll";
  }
  else
  {
   jacobDllVersion = "jacob-1.18-M2-x64.dll";
  }
 
  File file = new File("lib",jacobDllVersionToUse);
  System.setProperty(LibraryLoader.JACOB_DLL_PATH, file.getAbsolutePath());
 
  AutoItX autoIT = new AutoItX();
  autoIT.run("calc.exe");
  autoIT.winActivate("Calculator");
  autoIT.winWaitActive("Calculator");
  // Do 5 * 5 = 25
  //Enter 5
  autoIT.controlClick("Calculator", "", "135") ;
  Thread.sleep(1000);
  //Enter *
  autoIT.controlClick("Calculator", "", "92") ;
  Thread.sleep(1000);
  //Enter 5
  autoIT.controlClick("Calculator", "", "135") ;
  Thread.sleep(1000);
  //Enter =
  autoIT.controlClick("Calculator", "", "121") ;
  Thread.sleep(1000);
  // Get total and verify it should be 25
  String vTotal = autoIT.controlGetText("Calculator", "", "#32770");
  
  if(vTotal.equals("25"))
  {
   System.out.println("Test case Pass.");
  }
  else
  {
   System.out.println("Test case Fail.");
  }
  
 }

To get the Calculator button ids for the number 5 and = I used the Au3info application that is in the install directory of autoit-v3 that you downloaded and extracted.




Please add comment if you have any question.



1 comment:

Popular