27 November 2014

Onscreen Display of Execution Progress for Selenium using AutoIT

The post describes a method of displaying the execution progress on screen for Selenium. All you need is an AutoIT script that you can convert to a ".exe" tooltip utility file and change a registry value which is read by the utility file. The below info-graphic displays the control flow.


The key to this design is the creation of a registry key on the system which is continuously read by the tooltip file and the value is displayed at the top right of the screen. Hence, as the registry key value is changed, the code in the tooltip utility refreshes the onscreen display with the new value. The utility needs to be launched only once at the start of the test execution. You can set this in the driver of your framework. Also, you need not kill the process every-time you start your test execution as you can set the registry value as 'EXIT' such that the utility exits itself. 


Here is a small video that displays the idea in action.




The code below shows the code for creation of the registry key depending upon whether it exists or not and displays appropriate messages on the console.

@Test
public void main() throws Exception {
/*check environment registry for tooltip*/
System.out.println("====>>>>>>regkeyexist>>>>>>"+Advapi32Util.registryKeyExists(HKEY_CURRENT_USER, "Environment\\selenium"));
  if (!Advapi32Util.registryKeyExists(HKEY_CURRENT_USER, "Environment\\selenium")) {
   Advapi32Util.registryCreateKey(HKEY_CURRENT_USER, "Environment\\", "selenium");
                 Advapi32Util.registrySetStringValue(HKEY_CURRENT_USER, "Environment\\selenium", "envvariable", "tooltip_exists");
   System.out.println("====>>>>>>regkeyexistcreated?>>>>>>"+Advapi32Util.registryKeyExists(HKEY_CURRENT_USER, "Environment\\selenium"));
   if (!Advapi32Util.registryGetStringValue(HKEY_CURRENT_USER, "Environment\\selenium", "envvariable").contains("tooltip_exists")) {
    System.out.println("====>>>>>>regkeykeyvaluenot initiated>>>>>>");
   } else 
                        {                               System.out.println("====>>>>>>regkeycurrentvalueinitiated>>>>>>"+Advapi32Util.registryGetStringValue(HKEY_CURRENT_USER,"Environment\\selenium", "envvariable"));
   }
  } else {
   System.out.println("====>>>>>>regkeyexistchecktrue>>>>>>"+Advapi32Util.registryKeyExists(HKEY_CURRENT_USER, "Environment\\selenium"));
   System.out.println("====>>>>>>regkeycurrentvalue>>>>>>"+Advapi32Util.registryGetStringValue(HKEY_CURRENT_USER, "Environment\\selenium", "envvariable"));
  }

You need to import the Advapi32util class -

import com.sun.jna.platform.win32.Advapi32Util;

You can create a function as shown below and call it with the string that you want to display on the screen at run time -

public void settooltip(String var) {

  Advapi32Util.registrySetStringValue(HKEY_CURRENT_USER, "Environment\\selenium", "envvariable", var);

 }

The AutoIT script for the utility is written below. You just need to use the AutoIT suite to create the script and convert it into an exe and call it in your code.

$Env = RegRead("HKEY_CURRENT_USER\Environment\selenium", "envvariable")
$TEMP = $Env
ToolTip($Env, 0, 0)

While 1
 $Env = RegRead("HKEY_CURRENT_USER\Environment\selenium", "envvariable")

 If $Env<>$TEMP Then
  ToolTip("............", 0, 0)
  Sleep (1000)
  $TEMP = $Env
  ToolTip($Env, 0, 0)
  If $Env=="EXIT" Then
     Exit
  EndIf
 EndIf
WEnd

No comments:

Post a Comment