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

3 comments:

  1. Interesting to read this as an article. Thanks for all. Best SEO Courses in India

    ReplyDelete
  2. Our comprehensiveAutomation Testing Training in Noida is the perfect opportunity for you to become an expert in this dynamic field. With hands-on experience and an industry-relevant curriculum, we offer a tailored program that caters to both beginners and experienced professionals. During our training, you will learn essential automation testing concepts, methodologies, and tools that will propel your career to great heights. Our expert trainers guide you through various automation testing frameworks, such as Selenium WebDriver and Appium, equipping you with the skills needed to automate software testing processes efficiently.

    ReplyDelete