Sunday, November 27, 2016

How to run test with random data in Selenium IDE: store and storeText Command

Selenium IDE is a tool for record and play functionality, which runs the script with same set of data, however we can generate random data. store the values in a variable , and use the value stored in the variable in the later steps in the test.


Expected Learning from this article:

  • Store command to store random generated data in the a variable. 
  • Using the stored information in later steps in the test.
  • Using command storeText to store value of an object in the test and storing in a test.
  • Using the stored information in later stage in the test.



Below screenshot shows how to use store and storetext in the test:




  • In the above test, we open an application and save the text of the link in variable using command storeText. test in Value is the variable in each we can store the value of the link/object.
  • In the next step, we can use the value in the variable using ${variable_name} which is ${test} in our example.
  • Similarly using store command and javascript, we can generate random data, store in the variable and use further in the test.
  • We have saved the test in an html file and the test file looks as below:


<?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="https://www.google.co.in/" />
<title>testing stored value</title>
</head>
<body>
<table cellpadding="1" cellspacing="1" border="1">
<thead>
<tr><td rowspan="1" colspan="3">testing stored value</td></tr>
</thead><tbody>
<tr>
 <td>open</td>
 <td>/search?q=selenium&amp;ie=utf-8&amp;oe=utf-8&amp;client=firefox-b-ab&amp;gfe_rd=cr&amp;ei=r4E6WIqnEeXI8AfOn6awBw</td>
 <td></td>
</tr>
<tr>
 <td>storeText</td>
 <td>link=Selenium - Web Browser Automation</td>
 <td>test</td>
</tr>
<tr>
 <td>type</td>
 <td>id=lst-ib</td>
 <td>${test}</td>
</tr>
<tr>
 <td>click</td>
 <td>name=btnG</td>
 <td></td>
</tr>
<tr>
 <td>store</td>
 <td>javascript{&quot;Selenium&quot; +Math.random();}</td>
 <td>testrandom</td>
</tr>
<tr>
 <td>type</td>
 <td>id=lst-ib</td>
 <td>${testrandom}</td>
</tr>
<tr>
 <td>click</td>
 <td>name=btnG</td>
 <td></td>
</tr>

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

Copy paste the code in a text file and save in html format. Open the test in Selenium Ide and try to run the test and understand how to run test with random data in selenium IDE.

No comments:

Post a Comment