Pages

Search This Blog

Tuesday, September 14, 2010

How to share a variable in two test cases

How to share a variable in more than one test case.
We Create a variable in one test case and use in another test cases. If these test cases are running seperately and independetely then those variable
cannot shared. But if we run all test cases in test suite then one varaible declared in one testcase can be used in another
Follow these steps.
Create your test cases saparetly and call them in a test suite.
1.Create first test case
Test1.html

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Propagate_Negative_API_UK</title>
</head>
<body>
<table cellpadding="1" cellspacing="1" border="1">
<thead>
<tr><td rowspan="1" colspan="3">Propagate_Negative_API_UK</td></tr>
</thead><tbody>
<!------------------ Initialization steps ---------->
<tr>
 <td>store</td>
 <td>varaible from first test1</td>
 <td>vartest1</td>
</tr>


<tr>
 <td>open</td>
 <td>http://www.google.com</td>
 <td></td>
</tr>

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

2.Create second test case
Test2.html
==========

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Propagate_Negative_API_UK</title>
</head>
<body>
<table cellpadding="1" cellspacing="1" border="1">
<thead>
<tr><td rowspan="1" colspan="3">Propagate_Negative_API_UK</td></tr>
</thead><tbody>
<!------------------ Initialization steps ---------->
<tr>
 <td>store</td>
 <td>varaible from first test2</td>
 <td>vartest2</td>
</tr>

<tr>
 <td>open</td>
 <td>http://www.yahoo.com</td>
 <td></td>
</tr>
<tr>
 <td>echo</td>
 <td>${vartest1}</td>
 <td></td>
</tr>

3.Create third test case
Test3.html
=========

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Propagate_Negative_API_UK</title>
</head>
<body>
<table cellpadding="1" cellspacing="1" border="1">
<thead>
<tr><td rowspan="1" colspan="3">Propagate_Negative_API_UK</td></tr>
</thead><tbody>
<!------------------ Initialization steps ---------->
<tr>
 <td>store</td>
 <td>varaible from first test3</td>
 <td>vartest3</td>
</tr>

<tr>
 <td>open</td>
 <td>http://www.gmail.com</td>
 <td></td>
</tr>
<tr>
 <td>echo</td>
 <td>${vartest2}</td>
 <td></td>
</tr>
</tbody></table>
</body>
</html>

4.Create test suite
TestSuite.html
=========


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

     <tr>
       <td>Test suite for sharing variable among test cases </td>
     </tr>

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

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

    <tr>
      <td><a target="testFrame" href="test3.html">test3</a></td>
    </tr>
  </tbody>
</table>
</body>
</html>


Run your test suite and you will see the variable vartest1 decalred in testcase1 being used in testcases2
and variable vartest2 declared in testcase2 being used in testcase3.

Files are attached here . Right click on this link and save as ...
  Download test case and suite

4 comments:

  1. Thanks for sharing great information in your blog. Got to learn new things from your Blog . It was very nice blog to learn about Selenium

    ReplyDelete
  2. Thanks for sharing great information in your blog. Got to learn new things from your Blog . It was very nice blog to learn about Selenium.
    Selenium

    ReplyDelete
  3. It was very nice blog to learn about SAP BASIS. Thanks for sharing.SAP basis

    ReplyDelete
  4. It was very nice blog to learn about Selenium.Thanks for sharing new things.selenium training in chennai

    ReplyDelete