Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
constants in qtp
#1
Solved: 11 Years, 3 Months, 4 Weeks ago
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.....
Reply
#2
Solved: 11 Years, 3 Months, 4 Weeks ago
Try to give like below,
Code:
const url="www.google.co.in"
SystemUtil.Run "iexplore.exe",url
Reply
#3
Solved: 11 Years, 3 Months, 4 Weeks ago
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
Reply
#4
Solved: 11 Years, 3 Months, 4 Weeks ago
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
Reply
#5
Solved: 11 Years, 3 Months, 4 Weeks ago
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
Reply
#6
Solved: 11 Years, 3 Months, 4 Weeks ago
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
Reply
#7
Solved: 11 Years, 3 Months, 4 Weeks ago
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"
Firstname = "diya"
Lastname = "lastname"
---

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")
or
Value is the default property of environment, you can use
Code:
SystemUtil.Run "iexplore.exe", Environment("mybrowser")

Hope this helps.

Thanks,
Elango
Reply
#8
Solved: 11 Years, 3 Months, 4 Weeks ago
Thanks that really helped and thanks a lot for the reply
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Constants shayk1985 2 3,228 12-08-2012, 12:30 AM
Last Post: shayk1985

Forum Jump:


Users browsing this thread: 1 Guest(s)