Monday, June 16, 2014

Changing proxy configuration automatically

For our automation scripts we are testing various type of applications. Some of these applications needs proxy configuration to access the application page while for some of them proxy mustn't be configured.
To solve this we use a function named "initAutomation" that takes application name as a parameter. This function is being called at the beginning of the test script and checks the application name and then decides to configure proxy settings before the execution.

Following piece of code accomplishes this functionality.



Function getVal(p_key)
  v_retVal = "N/A"
  Select Case p_key
    Case "AutoConfigURL" v_retVal = "http://<<<autoconfigURL>>>"
    Case "QCDBNAME" v_retVal = "QCTEST"
  End Select
  getVal = v_retVal
End Function

Function initAutomation(p_appName)
  If p_appName="APP1" OR p_appName="APP2" Then
    SystemUtil.Run "cmd.exe", "/D /C reg delete ""HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet Settings"" /v AutoConfigURL /f"
  Else
    SystemUtil.Run "cmd.exe", "/D /C reg add ""HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet Settings"" /v AutoConfigURL /t REG_SZ /d """ & getVal("AutoConfigURL")  & """ /f"
  End If
End Function

No comments: