[selenium-users] How to assign the values to variables in Selenium IDE?

1,426 views
Skip to first unread message

shivani angra

unread,
May 5, 2010, 5:56:22 AM5/5/10
to Selenium Users
Hello,
I am using Selenium IDE 1.0.6. Is there any way to
assign the values to variables. Eg if i am using same URL in all test
cases and if there is a common changes of values in all scripts then i
have to change in all test cases individally. so is there any way
that rather than changing the values in all test cases i assigned one
value apply to all test cases.

Please suggest.

Thanks

--
You received this message because you are subscribed to the Google Groups "Selenium Users" group.
To post to this group, send email to seleniu...@googlegroups.com.
To unsubscribe from this group, send email to selenium-user...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/selenium-users?hl=en.

Niraj Kumar

unread,
May 5, 2010, 6:01:48 AM5/5/10
to seleniu...@googlegroups.com
<tr>
    <td>store</td>
    <td>staging</td>
    <td>var</td>
</tr>
<tr>
    <td>open</td>
    <td>http://www.${var}.com</td>
    <td></td>
</tr>
--
Thanks & Regard,
Niraj Kumar

shivani angra

unread,
May 5, 2010, 6:14:58 AM5/5/10
to Selenium Users
Thanks for reply but how it'll change in all test cases which value
i'll change which affect in all test cases. I know its silly question
but i m beginner in selenium. Please suggest.

Niraj Kumar

unread,
May 5, 2010, 6:20:13 AM5/5/10
to seleniu...@googlegroups.com
store the value in the variable in the beginning and run the test case. but if you feel this particular URL should open with different variable value then you should change just before that.
same steps for assigning variable you should use wherever u feel to change
--
Thanks & Regard,
Niraj Kumar

shivani angra

unread,
May 5, 2010, 6:47:50 AM5/5/10
to Selenium Users

Ok i got which you said but whether it'll implement in case of Test
suite or not like if i changed the value in Test case1 would it be
change in test case2 itself or not.?

Niraj Kumar

unread,
May 5, 2010, 6:52:13 AM5/5/10
to seleniu...@googlegroups.com
Yes of course you can do . Just create one test suite and define our variable and assign the value and call your tests . you just change the value in one place will be replace everywhere in your tests
--
Thanks & Regard,
Niraj Kumar

Niraj Kumar

unread,
May 5, 2010, 7:21:26 AM5/5/10
to seleniu...@googlegroups.com
just create one suit like this



<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
 <head></head>
  <body>
   <table>
    <tbody>

<tr>
       <td>Test suite for Propagate Testing</td>
</tr>

<tr>
      <td><a target="testFrame" href="varaible.html">variable declaration</a></td>
</tr>

<tr>
      <td><a target="testFrame" href="1.html">google1</a></td>
</tr>


<tr>
      <td><a target="testFrame" href="2.html">google2</a></td>
</tr>

<tr>
      <td><a target="testFrame" href="3.html">google3 </a></td>
</tr>

     </tbody>
</table>
</body>
</html>


Variable.html

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head profile="http://selenium-ide.openqa.org/profiles/test-case">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<link rel="selenium.base" href="" />
<title>1</title>
</head>
<body>
<table cellpadding="1" cellspacing="1" border="1">
<thead>
<tr><td rowspan="1" colspan="3">1</td></tr>
</thead><tbody>
<tr>
    <td>store</td>
    <td>jagu</td>
    <td>search</td>
</tr>

</tbody></table>
</body>
</html>



1. html

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head profile="http://selenium-ide.openqa.org/profiles/test-case">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<link rel="selenium.base" href="" />
<title>1</title>
</head>
<body>
<table cellpadding="1" cellspacing="1" border="1">
<thead>
<tr><td rowspan="1" colspan="3">1</td></tr>
</thead><tbody>
<tr>
    <td>open</td>
    <td>http://www.google.co.in/</td>
    <td></td>
</tr>
<tr>
    <td>type</td>
    <td>q</td>
    <td>${search}</td>
</tr>
<tr>
    <td>click</td>
    <td>btnG</td>
    <td></td>
</tr>
<tr>
    <td>pause</td>
    <td>5000</td>
    <td></td>
</tr>

</tbody></table>
</body>
</html>



2.html

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head profile="http://selenium-ide.openqa.org/profiles/test-case">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<link rel="selenium.base" href="" />
<title>1</title>
</head>
<body>
<table cellpadding="1" cellspacing="1" border="1">
<thead>
<tr><td rowspan="1" colspan="3">1</td></tr>
</thead><tbody>
<tr>
    <td>open</td>
    <td>http://www.google.co.in/</td>
    <td></td>
</tr>
<tr>
    <td>type</td>
    <td>q</td>
    <td>${search}</td>
</tr>
<tr>
    <td>click</td>
    <td>btnG</td>
    <td></td>
</tr>
<tr>
    <td>pause</td>
    <td>5000</td>
    <td></td>
</tr>

</tbody></table>
</body>
</html>

3.html

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head profile="http://selenium-ide.openqa.org/profiles/test-case">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<link rel="selenium.base" href="" />
<title>1</title>
</head>
<body>
<table cellpadding="1" cellspacing="1" border="1">
<thead>
<tr><td rowspan="1" colspan="3">1</td></tr>
</thead><tbody>
<tr>
    <td>open</td>
    <td>http://www.google.co.in/</td>
    <td></td>
</tr>
<tr>
    <td>type</td>
    <td>q</td>
    <td>${search}</td>
</tr>
<tr>
    <td>click</td>
    <td>btnG</td>
    <td></td>
</tr>
<tr>
    <td>pause</td>
    <td>5000</td>
    <td></td>
</tr>

</tbody></table>
</body>
</html>

put all your test files and suit in same directory and open that suit from IDE not the test file. open the suit.html throuth open suit option and run. When ever you feel to change the variable just to go variable.html and change that and run the suit again . your all test cases will use the same variable with new value.
--
Thanks & Regard,
Niraj Kumar

shivani angra

unread,
May 5, 2010, 7:53:12 AM5/5/10
to Selenium Users
Thanks a lot, It really helps me.

Thanks

shivani angra

unread,
May 5, 2010, 8:06:13 AM5/5/10
to Selenium Users
Hi,
But one problem which will always created is if i am
running the test case individually then it is not running because test
case will not find that variable.

Niraj Kumar

unread,
May 5, 2010, 8:14:35 AM5/5/10
to seleniu...@googlegroups.com
See we are creating test suit for running multiple tests together or in priority basis . sometimes we use suit to pass environment variable to our tests.

see below as an example

<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite name="Payment" parallel="tests" thread-count="5">

<parameter name="selenium.host" value="localhost"></parameter>
    <parameter name="selenium.port" value="4444"></parameter>
    <parameter name="selenium.browser" value="*iexplore"></parameter>
    <parameter name="Server" value="fp002"></parameter>



  <test verbose="2" name="Cartpayment" annotations="JDK">
    <classes>
      <class name="Cartpayment"/>
     <class name="Msqpayment"/>
     <class name="BINpayment"/>
    </classes>
  </test>
</suite>


This suit runs 50 + test cases and all  will run a particular server so we are passing the value in Server that will be used through out all tests. and Here we are passing browser as well means i want to run all test cases in IE. so in this case we create suite. Suite has some useful reason and dependencies. In case i want to run a particular test i cant.  i have to supply all variable locally from the test itself so decide what you really want.
--
Thanks & Regard,
Niraj Kumar

Shaba K

unread,
May 5, 2010, 6:16:28 AM5/5/10
to seleniu...@googlegroups.com
Can't we have a Single Properties file were you set/define all your variables.

Niraj Kumar

unread,
May 5, 2010, 8:38:04 AM5/5/10
to seleniu...@googlegroups.com
yes you can have but again if you run test cases independently again it will create problem
--
Thanks & Regard,
Niraj Kumar

Bob McConnell

unread,
May 5, 2010, 8:52:13 AM5/5/10
to seleniu...@googlegroups.com
From: Niraj Kumar

> yes you can have but again if you run test cases
> independently again it will create problem
>
> On Wed, May 5, 2010 at 3:46 PM, Shaba K <shaba...@gmail.com> wrote:
>
> Can't we have a Single Properties file were you set/define all
your variables.
>
> On Wed, May 5, 2010 at 3:44 PM, shivani angra
<angras...@gmail.com> wrote:
>
> Thanks for reply but how it'll change in all test cases
which value
> i'll change which affect in all test cases. I know its
silly question
> but i m beginner in selenium. Please suggest.

I think you have moved beyond the capabilities contemplated for the IDE
and should seriously consider moving on to Se Remote Control. That gives
you a wider choice of languages and more than a couple of options to
solve this problem.

Bob McConnell

Niraj Kumar

unread,
May 5, 2010, 8:55:48 AM5/5/10
to seleniu...@googlegroups.com
In fact i am using Selenium RC(jave) + TestNG+ Maven and Hudson . actually someone in this thread asked one question regarding IDE and he/she is new to Selenium thats why i gave them reply only.
--
Thanks & Regard,
Niraj Kumar

Bob McConnell

unread,
May 5, 2010, 9:53:02 AM5/5/10
to seleniu...@googlegroups.com
From: Niraj Kumar
With all the top posting and broken email clients not correctly
attributing quoted portions of the thread, it is difficult to determine
who is whom. My comment was aimed at the OP, but I tacked it onto the
latest message I saw in the thread so as not to split it.

SiKing

unread,
May 5, 2010, 9:21:37 PM5/5/10
to Selenium Users
See this post
http://groups.google.com/group/selenium-users/browse_thread/thread/399311029fcb5af9/d49acbf65819ee6a?lnk=gst&q=author%3ASiKing+bat+file#d49acbf65819ee6a
You should be able to expand on the idea to do exactly what you want.

HTH.


On May 5, 3:16 am, Shaba K <shabazi...@gmail.com> wrote:
> Can't we have a Single Properties file were you set/define all your
> variables.
>
> On Wed, May 5, 2010 at 3:44 PM, shivani angra <angrashiv...@gmail.com>wrote:
>
>
>
> > Thanks for reply but how it'll change in all test cases which value
> > i'll change which affect in all test cases. I know its silly question
> > but i m beginner in selenium. Please suggest.
>
> > Thanks
>
> > --
> > You received this message because you are subscribed to the Google Groups
> > "Selenium Users" group.
> > To post to this group, send email to seleniu...@googlegroups.com.
> > To unsubscribe from this group, send email to
> > selenium-user...@googlegroups.com<selenium-users%2Bunsu...@googlegroups.com>
> > .
> > For more options, visit this group at
> >http://groups.google.com/group/selenium-users?hl=en.
>
> --
> You received this message because you are subscribed to the Google Groups "Selenium Users" group.
> To post to this group, send email to seleniu...@googlegroups.com.
> To unsubscribe from this group, send email to selenium-user...@googlegroups.com.
> For more options, visit this group athttp://groups.google.com/group/selenium-users?hl=en.

James Johnson

unread,
May 5, 2010, 5:50:14 PM5/5/10
to Selenium Users
There is another way you can have a test suite run from a properties
file where you can run the entire suite OR run any single test by
itself.
http://saucelabs.com/blog/index.php/2010/03/selenium-tip-of-the-week-parametrizing-selenese-tests/

In summary, open up Optionsin Selenium IDE and browser to include a
user-extention.js file.

---- inside the js file -----
storeVars["URL"] = "http://www.fakeapplication.com"
storeVars["username"] = "testuser"
storeVars["password"] = "mypass"
----------------------------------

Now, You can use the above as Variables in any test and across the
entire suite.
${username}


James Johnson

On May 5, 9:53 am, "Bob McConnell" <r...@CBORD.com> wrote:
> From: Niraj Kumar
>
>
>
>
>
> > In fact i am using Selenium RC(jave) + TestNG+ Maven
> > and Hudson . actually someone in this thread asked one
> > question regarding IDE and he/she is new to Selenium
> > thats why i gave them reply only.
>
> > On Wed, May 5, 2010 at 6:22 PM, Bob McConnell <r...@cbord.com> wrote:
>
> >    From: Niraj Kumar
>
> >    > yes you can have but again if you run test cases
> >    > independently again it will create problem
>
> >    > On Wed, May 5, 2010 at 3:46 PM, Shaba K <shabazi...@gmail.com>
> wrote:
>
> >    >       Can't we have a Single Properties file were you
> set/define all
> >    your variables.
>
> >    >       On Wed, May 5, 2010 at 3:44 PM, shivani angra

James Johnson

unread,
May 5, 2010, 5:51:26 PM5/5/10
to Selenium Users
You can parameterize your entire suite and still run 1 test at a time.
http://saucelabs.com/blog/index.php/2010/03/selenium-tip-of-the-week-parametrizing-selenese-tests/
Reply all
Reply to author
Forward
0 new messages