![]() |
constants in qtp - Printable Version +- Micro Focus QTP (UFT) Forums (https://www.learnqtp.com/forums) +-- Forum: Micro Focus UFT (earlier known as QTP) (https://www.learnqtp.com/forums/Forum-Micro-Focus-UFT-earlier-known-as-QTP) +--- Forum: UFT / QTP Beginners (https://www.learnqtp.com/forums/Forum-UFT-QTP-Beginners) +--- Thread: constants in qtp (/Thread-constants-in-qtp) |
constants in qtp - diya - 12-05-2012 How to execute a constant suppose const my browser="GMAIL.COM" so how to execute it and what is the use Suppose i want to give a const value to my browser so that it does not change how can i give that and how can i call or execute it in qtp please let me know..... RE: constants in qtp - kalaivanan123 - 12-05-2012 Try to give like below, Code: const url="www.google.co.in" RE: constants in qtp - diya - 12-05-2012 thanks... is this the way...i mean i have data table and few things i need to keep permanent rather changing to be used some where else also. like broswer,firstname,lastname i need to use constant and execute using datatable ...how do i proceed RE: constants in qtp - diya - 12-06-2012 can someone please help as how to use constants with datatable. I have few fileds which i dont want them to change...how to achieve it using constants. Please help RE: constants in qtp - elango87 - 12-07-2012 I don't think its possible to declare the value of a constant from data table. When you declare a constant, you have to implicitly specify the value of that constant. Say for example that you have "gmail.com" as value in column "A" row "1". You cant simply declare, Code: const mybrowser = Datatable.Value("A",1) you have to literally specify the value which the constant is gonna hold which will be Code: const mybrowser = "gmail.com --- i would suggest you to use external environment variable file to store the values and access them thru code. Let me know if you need any help. Thanks, Elango RE: constants in qtp - diya - 12-07-2012 Thanks elango... so you mean in order to make sure the values dont change use environment values. Like i want few fields not to change...... so what is the best option and also environment i donno how to use... Please suggest as what i should use if i want to keep the values same as i dont want them to change RE: constants in qtp - elango87 - 12-07-2012 An external environment variable file can either be a xml file or an ini file. I would suggest you to use ini as it is easy to maintain. If you want to use xml, read QTP help or google it. Just create a text file with extension as ".ini". E.g.: "Environment.ini" In the beginning of the file, add [Environment] Following that, you can specify the variables and their values... it will look some thing like this... --- [Environment] Code: mybrowser = "www.google.com" To use this file, you have to import it to your script. Use Environment.Loadfromfile("Path of your environment file") Eg: Code: Environment.Loadfromfile("C:\Environment.ini") Now you can use it whenever you want. For example, if you like to open google, Code: SystemUtil.Run "iexplore.exe", Environment.Value("mybrowser") Value is the default property of environment, you can use Code: SystemUtil.Run "iexplore.exe", Environment("mybrowser") Hope this helps. Thanks, Elango RE: constants in qtp - diya - 12-07-2012 Thanks that really helped and thanks a lot for the reply |