Detailed Example to be presented to the delegates on the workshop. Covers many Selenium IDE features.
Pre-requisites:
- Firefox browser with Selenium IDE installed ,use link How to install Selenium IDE?
- once copied and pasted , locate the CaptureEntireScreenshot Command correct the path.
Key Steps
- Save all the scripts on the PC first in same folder.
- Go with the embedded video file and view the execution
- Many commands demonstrated.
What you will learn?
- Test Suites
- Test Cases
- User extension
- echo command
- asserts
- xpaths
- javascript functions
- captureEntirePageScreenshot command
- variable usage
- random variables
- verify command
Related Entries
- none
Test suite script, save it with name 'Solution2Suite.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> <meta content="text/html; charset=UTF-8" http-equiv="content-type" /> <title>Test Suite</title> </head> <body> <table id="suiteTable" cellpadding="1" cellspacing="1" border="1" class="selenium"><tbody> <tr><td><b>Test Suite</b></td></tr> <tr><td><a href="testcase1.html">testcase1</a></td></tr> <tr><td><a href="testcase2.html">testcase2</a></td></tr> <tr><td><a href="testcase3.html">testcase3</a></td></tr> </tbody></table> </body> </html>
first test case, save it with name 'testcase1.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="http://foundation.time2test.co.uk/" />
<title>TestCase1</title>
</head>
<body>
<table cellpadding="1" cellspacing="1" border="1">
<thead>
<tr><td rowspan="1" colspan="3">TestCase1</td></tr>
</thead><tbody>
<tr>
<td>open</td>
<td>/</td>
<td></td>
</tr>
<tr>
<td>clickAndWait</td>
<td>link=Log in</td>
<td></td>
</tr>
<tr>
<td>assertTextPresent</td>
<td>Username</td>
<td></td>
</tr>
<tr>
<td>assertTextPresent</td>
<td>Password</td>
<td></td>
</tr>
<tr>
<td>type</td>
<td>id=user_login</td>
<td>admin</td>
</tr>
<tr>
<td>storeValue</td>
<td>id=user_login</td>
<td>loginVariable</td>
</tr>
<tr>
<td>type</td>
<td>id=user_pass</td>
<td>time4test</td>
</tr>
<tr>
<td>storeValue</td>
<td>id=user_pass</td>
<td>passwordVariable</td>
</tr>
<tr>
<td>echo</td>
<td>"Print the Creadential:"</td>
<td></td>
</tr>
<tr>
<td>echo</td>
<td>${loginVariable}</td>
<td></td>
</tr>
<tr>
<td>echo</td>
<td>${passwordVariable}</td>
<td></td>
</tr>
<tr>
<td>clickAndWait</td>
<td>id=wp-submit</td>
<td></td>
</tr>
<tr>
<td>waitForElementPresent</td>
<td>//div[@id='user_info']/p/a[2]</td>
<td></td>
</tr>
</tbody></table>
</body>
</html>
second test case, save it with name 'testcase2.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="http://foundation.time2test.co.uk/" /> <title>TestCase2</title> </head> <body> <table cellpadding="1" cellspacing="1" border="1"> <thead> <tr><td rowspan="1" colspan="3">TestCase2</td></tr> </thead><tbody> <tr> <td>clickAndWait</td> <td>link=Posts</td> <td></td> </tr> <tr> <td>verifyTextPresent</td> <td>Posts</td> <td></td> </tr> <tr> <td>waitForElementPresent</td> <td>//div[@id='wpbody-content']/div[3]/h2</td> <td></td> </tr> <tr> <td>clickAndWait</td> <td>link=Add New</td> <td></td> </tr> <tr> <td>type</td> <td>id=title</td> <td>MyPost</td> </tr> <tr> <td>clickAndWait</td> <td>id=publish</td> <td></td> </tr> <tr> <td>waitForElementPresent</td> <td>//div[@id='wpbody-content']/div[3]/h2</td> <td></td> </tr> </tbody></table> </body> </html>
Third test case, save it with name 'testcase3.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="http://foundation.time2test.co.uk/" />
<title>TestCase3</title>
</head>
<body>
<table cellpadding="1" cellspacing="1" border="1">
<thead>
<tr><td rowspan="1" colspan="3">TestCase3</td></tr>
</thead><tbody>
<tr>
<td>clickAndWait</td>
<td>link=Users</td>
<td></td>
</tr>
<tr>
<td>assertTextPresent</td>
<td>Users</td>
<td></td>
</tr>
<tr>
<td>clickAndWait</td>
<td>//li[@id='menu-users']/div[3]/ul/li[2]/a</td>
<td></td>
</tr>
<tr>
<td>type</td>
<td>id=user_login</td>
<td>javascript{"Test" + new Date().getMilliseconds();}</td>
</tr>
<tr>
<td>type</td>
<td>id=email</td>
<td>javascript{"Test" + new Date().getMilliseconds()+"@gmail.com";}</td>
</tr>
<tr>
<td>randomString</td>
<td>10</td>
<td>alphanumeric</td>
</tr>
<tr>
<td>type</td>
<td>id=first_name</td>
<td>javascript{storedVars['alphanumeric'] }</td>
</tr>
<tr>
<td>randomString</td>
<td>10</td>
<td>numeric</td>
</tr>
<tr>
<td>type</td>
<td>id=last_name</td>
<td>javascript{"Test"+storedVars['alphanumeric'] }</td>
</tr>
<tr>
<td>type</td>
<td>id=url</td>
<td>http://www.google.com/</td>
</tr>
<tr>
<td>type</td>
<td>id=pass1</td>
<td>time2test</td>
</tr>
<tr>
<td>type</td>
<td>id=pass2</td>
<td>time2test</td>
</tr>
<tr>
<td>verifyTextPresent</td>
<td>Users</td>
<td></td>
</tr>
<tr>
<td>captureEntirePageScreenshot</td>
<td>C:Image.jpg</td>
<td></td>
</tr>
<tr>
<td>clickAndWait</td>
<td>id=addusersub</td>
<td></td>
</tr>
<tr>
<td>clickAndWait</td>
<td>link=Log Out</td>
<td></td>
</tr>
</tbody></table>
</body>
</html>
Here is the Random.js file which we need to store in IDE first
Selenium.prototype.doRandomString = function( options, varName ) {
var length = 8;
var type = 'alphanumeric';
var o = options.split( '|' );
for ( var i = 0 ; i < 2 ; i ++ ) {
if ( o[i] && o[i].match( /^d+$/ ) )
length = o[i];
if ( o[i] && o[i].match( /^(?:alpha)?(?:numeric)?$/ ) )
type = o[i];
}
switch( type ) {
case 'alpha' : storedVars[ varName ] = randomAlpha( length ); break;
case 'numeric' : storedVars[ varName ] = randomNumeric( length ); break;
case 'alphanumeric' : storedVars[ varName ] = randomAlphaNumeric( length ); break;
default : storedVars[ varName ] = randomAlphaNumeric( length );
};
};
function randomNumeric ( length ) {
return generateRandomString( length, '0123456789'.split( '' ) );
}
function randomAlpha ( length ) {
var alpha = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'.split( '' );
return generateRandomString( length, alpha );
}
function randomAlphaNumeric ( length ) {
var alphanumeric = '01234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'.split( '' );
return generateRandomString( length, alphanumeric );
}
function generateRandomString( length, chars ) {
var string = '';
for ( var i = 0 ; i < length ; i++ )
string += chars[ Math.floor( Math.random() * chars.length ) ];
return string;
}
Selenium.prototype.doRandomString = function( options, varName ) {
var length = 8;
var type = 'alphanumeric';
var o = options.split( '|' );
for ( var i = 0 ; i < 2 ; i ++ ) {
if ( o[i] && o[i].match( /^d+$/ ) )
length = o[i];
if ( o[i] && o[i].match( /^(?:alpha)?(?:numeric)?$/ ) )
type = o[i];
}
switch( type ) {
case 'alpha' : storedVars[ varName ] = randomAlpha( length ); break;
case 'numeric' : storedVars[ varName ] = randomNumeric( length ); break;
case 'alphanumeric' : storedVars[ varName ] = randomAlphaNumeric( length ); break;
default : storedVars[ varName ] = randomAlphaNumeric( length );
};
};
function randomNumeric ( length ) {
return generateRandomString( length, '0123456789'.split( '' ) );
}
function randomAlpha ( length ) {
var alpha = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'.split( '' );
return generateRandomString( length, alpha );
}
function randomAlphaNumeric ( length ) {
var alphanumeric = '01234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'.split( '' );
return generateRandomString( length, alphanumeric );
}
function generateRandomString( length, chars ) {
var string = '';
for ( var i = 0 ; i < length ; i++ )
string += chars[ Math.floor( Math.random() * chars.length ) ];
return string;
}
Helpful Video File
I am not getting the purpose of this exercise, can you please explain?
ReplyDeleteviresh comments:
ReplyDelete1. in this blog entry , we want to demonstate the example located at My dropbox\vipin\helloWolrdExample.
2. this example will be discussed in the course in detail.
3. the example needs to be placed into this blog entry
4. the example covers lots of things e.g. suite, javascript, asserts, verifys, e.t.c
5. the exapmple needs to run against the vm ( so you need to modify the example)
Aim of example:
to cover in detail a first example and introducde the many different types of commands/code/structure e.t.c
It's Done, please review.
ReplyDeletethis example needs to cover:
ReplyDeletescreenshot capture?
echo command?
javascript in a command?
variable usage?
random value?
suite
test cases
assert command
verify command
can you confirm the above? if not, then please modify
it's done, I have covered all the points into the attached HTML scripts.
ReplyDeleteIt's done.
ReplyDeleteEcho command does not appear to work
ReplyDeleteI have uploaded the created video on dailymotion and embedded it with the blog, please look into this and let me know if you still see the same problem
ReplyDeleteChecked this exercise and it seems there are issues to be rectified for the script "testcase3.html"
ReplyDeleteI have rectified the script "testcase3.html".
ReplyDeleteAdd regular expression to this example
ReplyDelete