Parameters or Global Variables

Ask general questions here.
Posts: 10
Joined: Fri Sep 06, 2013 10:52 am

Parameters or Global Variables

Post by jrob3rts » Wed Sep 18, 2013 9:19 am

Hi All,
I am testing accross multiple browsers. I would like to set a variable called BrowserName, and this defines elements within the script that need to be clicked etc.

For example:

Code: Select all

        	String GraphPos="";
        	// Set the co-ordinates of the Graph Location
        	if (BrowserName == "IE" || BrowserName == "FireFox") {
        	if (BrowserName == "Chrome") {
        	if (BrowserName == "Safari") {
So from the above. I set a location of the graph bar to be clicked based on the Browser. Until now, I have been using local variables per test script / recording module. But I would like to utilise a global parameter if possible and set the BrowserName at a top level.

Any ideas on how I do this? It might seem simple, but when I tried to assign a global parameter, it looked like it wanted to assign every local called BrowserName to itself. For example:

Global Parameter: BrowserName
I have the option of module variables BrowserName (Login) and BrowserName (Logout)
I would only expect to see a single BrowserName. Do I need to assign every instance of BrowserName (local) to the single BrowserName (global)?

I hope that makes sense.


Posts: 2683
Joined: Tue Feb 07, 2012 4:14 pm
Location: Austin, Texas, USA

Re: Parameters or Global Variables

Post by krstcs » Wed Sep 18, 2013 2:03 pm

Each module has it's own INTERNAL variables. You need to bind each one of these to the data source, in this case the global parameter, in order to have data passed in correctly.

If you have both modules in the same test case in the suite, and the variable and parameter names are the same (NOT case-sensitive) you can right-click the test case, select Data Binding, and click the Auto Bind button.

If they aren't in the same test case you will need to bind each variable.

I know it sounds like a pain (and sometimes it is... :D ), but once you get used to how it works you will do it without thinking.

A few pointers:

1. Be consistent with your naming scheme. Make sure the variable names in your scripts and the data parameter names are the same when they are referring to the same THING. This will allow Auto Bind to work correctly. (And, conversely, make sure you DON'T name things the same if they don't mean exactly the same thing...)
2. Try to create your test cases first, populating the modules as you go. Then, at the end, bind ALL the variables in the test case at once (again with Auto Bind).
3. Keep it simple...

Hope that helps.
Shortcuts usually aren't...

Posts: 10
Joined: Fri Sep 06, 2013 10:52 am

Re: Parameters or Global Variables

Post by jrob3rts » Wed Sep 18, 2013 4:42 pm

Many thanks for that.
It does seem to be a slightly tedious task but shall do that from now on.
Thanks for your clarifications.