Question
When we run a script, we would like to have a msg - ' Which Environment you would like to run the script? Also need a drop-down list of Dev, IT and UAT. So that user can select whatever test environment they want to run the script. once user selects it, the script should open particular test environment in browser. Help me to write the script.
(One of my group member posted this question in my group)
Script to Select Environment by Creating .Net Windows Form using DotnetFactory Utility Object
When we run a script, we would like to have a msg - ' Which Environment you would like to run the script? Also need a drop-down list of Dev, IT and UAT. So that user can select whatever test environment they want to run the script. once user selects it, the script should open particular test environment in browser. Help me to write the script.
(One of my group member posted this question in my group)
Script to Select Environment by Creating .Net Windows Form using DotnetFactory Utility Object
Set SelectEnvForm = DotNetFactory.CreateInstance("System.Windows.Forms.Form", "System.Windows.Forms")
Set EnvComboBox= DotNetFactory.CreateInstance("System.Windows.Forms.ComboBox", "System.Windows.Forms")
Set btnSubmit = DotNetFactory.CreateInstance("System.Windows.Forms.Button", "System.Windows.Forms")
Set objPositions = DotNetFactory.CreateInstance("System.Drawing.Point","System.Drawing",x,y)
With objPositions
.X = 80
.Y = 80
End With
With EnvComboBox
.Location = objPositions
.DropDownWidth = 100
.Items.Add "DEV"
.Items.Add "IT"
.Items.Add "UAT"
End With
With objPositions
.X = 100
.Y = 125
End With
With btnSubmit
.Location = objPositions
.Text = "Submit"
End With
With SelectEnvForm
.Controls.Add EnvComboBox
.Controls.Add btnSubmit
.CancelButton = btnSubmit
.Text = "Select Environment Form"
.ShowDialog
End With
Msgbox EnvComboBox.SelectedItem
Script to Select Environment by Creating HTML FormSave the below script into a library file and associate to QTP Test. When we run QTP test it automatically displays a dialog to select environment. Select the environment and click on submit button.
In script you can use a variable ExecutionEnvironment to know which environment is selected.
Dim htmlCode
Dim ResPath
Dim fso
Dim FlPath
Dim fl
Dim wshShell
Dim wshSystemEnv
Dim ExecutionEnvironment
htmlCode=""
htmlCode=htmlCode&vbnewline&"Select Environment
Select Environment
"
htmlCode=htmlCode&vbnewline&""
htmlCode=htmlCode&vbnewline&" "
ResPath=Environment("ResultDir")
FlPath=ResPath&"SelectEnvironment.hta"
Set fso=CreateObject("scripting.filesystemobject")
Set fl=fso.CreateTextFile(FlPath,True)
fl.Write(htmlCode)
fl.Close
SystemUtil.Run FlPath
if Window("text:=Select Environment").Exist(10) then
While Window("text:=Select Environment").Exist(0)=true
wait(1)
Wend
End If
fso.DeleteFile FlPath
Set wshShell = CreateObject("WScript.Shell")
Set wshSystemEnv = wshShell.Environment("SYSTEM")
ExecutionEnvironment = wshSystemEnv("ExecutionEnv")
'Using Environment Name in Script
Msgbox ExecutionEnvironment
HI,
ReplyDeleteIts really very good article. For coming of this in automation framework, .Net Needs to be installed?
Thanks,
Ken