Access Keys:
Skip to content (Access Key - 0)
Log in (Access Key - 5)



Toggle Sidebar

Inject variable values


The selenium-core API allows parameterization of test commands.
Variables can be used in target and value parameters of commands. One exception will apply: Variables cannot be used in javascript parameters, example:

open | ${baseurl}/login.html
type | loginname | ${user}

${baseurl} will be replaced with the value of the variable baseurl before the open command is executed.
${user} will be replaced with the value of user respectivly.

But how are variable values set?

selenium itself is providing store commands to set variable values. But this does not allow to paramterize testscripts with external files directly.

Molybdenum provides three ways to set variable values, stored separately from the testscript:

  1. autostartArgument
  2. loadVars
  3. loadData

autoStartArgument

The autoStartArgument is passed to Molybdenum on commandline start or starting Molybdenum tests via ANT or Maven. Additionally, the autostartArgument can be set via GUI.
Start firefox the following way to pass a value for the autostartArgument

firefox -mo mytest.xml -autostartarg "myuser"

In the mytest.xml, the variable can be accessed via ${autostartArgument}.
For example, type | loginname | ${autostartArgument} will type myuser in the tetxfiled with id loginname.
Find more information about passing the autostartArgument via commandline in Parameterization.

In Ant, the parameter argument of the molybdenum task is used to pass the value to autostartArgument.

In Maven, the element argument of the molybdenum plugin is used to pass the autostartArgument.

Regardless of the way the autostartArgument is passed to Molybdenum, it can be changed using the UI afterwards to run same tests with a different value again.
The input field can be found in the toolbar of Molybdenum.

loadVars

autostartArgument can pass only one value to the testscript.
The loadVars command can load a simple XML file containing several variables and its values. The format is quite simple:

<myvars>
  <var1>value1</var1>

    ...

  <varn>value n</varn>
</myvars>

The name of the root element doesn't matter. It has to be present to satisfy the XML spec only.

Variable Name Syntax

For variable names, characters and numerics should be used only. Special characters should be avoided.

Variable names, which should work:
var1, myvar, A42

Variable names, which might not work:
var-1, var$[?26

The command to load this variables looks like that:

loadVars | file:///C:/path-to-vars/variables.xml

The one and only argument to be passed to the loadVars command is an absolute URL to the XML file holding the variables. The URL can use the file://, http:// protocol or any other protocol supported by Firefox.

Howto combine loadVars and the autostartArgument to execute tests with different sets of variables is described in Parameterization.

Check also loadVars in the Command Reference...

loadData

loadData is new in version 0.7.0 of Molybdenum. It has following advantages over loadVars:

  • variable files can be loaded with pathes relative to the testsuite file
  • variable files can have scopes. This scopes can be selected via the second parameter of the loadData command
  • variables can be preproccessed by converters written as small javascript snipplets

TODO detailed description

Check also loadData in the Command Reference...

last edited on Mar 14, 2009 13:24
Adaptavist Theme Builder Powered by Atlassian Confluence