Wednesday, 27 April 2011

Example – Debug the script

Aim:
Take an existing Selenium script and demonstrate, step by step, how to debug it so that it works.

Pre-requisites:
Steps:
  1. copy this script into the IDE and run and notice the failures ( there are 3 failures in total)
  2. use debugging methods to create start and breakpoints to debug the errors one by one and then modify the commands in the IDE so that they pass
  3. work through all three failure points until the script passes
  4. run the corrected script and notice that it now passes without failures.

What you learned?
  • degbugging via the Selenium IDE using breakpoints and start points
  • modification of scripts using Notepad++

Zip file location: ( download from here)

  • C:\FoundationSelenium\DebugScript\FailureScript.html,
  • C:\FoundationSelenium\DebugScript\ModifiedFailureScript.html

Related Entries

  • none



Failure Script

<?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>FailureScript</title>
</head>
<body>
<table cellpadding="1" cellspacing="1" border="1">
<thead>
<tr><td rowspan="1" colspan="3">FailureScript</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=userlogin</td>
<td>admin</td>
</tr>
<tr>
<td>type</td>
<td>id=user_pass</td>
<td>time4test</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>
<tr>
<td>clickAndWait</td>
<td>link=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=publishPost</td>
<td></td>
</tr>
<tr>
<td>clickAndWait</td>
<td>link=AddUsers</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{&quot;Test&quot; + new Date().getMilliseconds();}</td>
</tr>
<tr>
<td>type</td>
<td>id=email</td>
<td>javascript{&quot;Test&quot; + new Date().getMilliseconds()+&quot;@gmail.com&quot;;}</td>
</tr>
<tr>
<td>type</td>
<td>id=first_name</td>
<td>TestFirst</td>
</tr>
<tr>
<td>type</td>
<td>id=last_name</td>
<td>TestLast</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>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>




Rectified Script

<?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>RectifiedScriptt</title>
</head>
<body>
<table cellpadding="1" cellspacing="1" border="1">
<thead>
<tr><td rowspan="1" colspan="3">RectifiedScriptt</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>type</td>
<td>id=user_pass</td>
<td>time4test</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>
<tr>
<td>clickAndWait</td>
<td>link=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>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{&quot;Test&quot; + new Date().getMilliseconds();}</td>
</tr>
<tr>
<td>type</td>
<td>id=email</td>
<td>javascript{&quot;Test&quot; + new Date().getMilliseconds()+&quot;@gmail.com&quot;;}</td>
</tr>
<tr>
<td>type</td>
<td>id=first_name</td>
<td>TestFirst</td>
</tr>
<tr>
<td>type</td>
<td>id=last_name</td>
<td>TestLast</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>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>



Helpful Video File


5 comments:

  1. Notes for Vipin:
    this is an example that will be executed by the tutor to the delegates.
    Create an example, similar to Exercise 3. ( not the same one! something different )

    ReplyDelete
  2. Hi Vipin, can you confirm that this is different from exercise 3? what about it is different? Viresh

    ReplyDelete
  3. Actually Viresh, it's a new script from the script created under Exercise 3, also in the current exercise I show how to rectify the failure points one by one using Debug/Breakpoints.

    ReplyDelete

Thank you for your comment
- Time2test Team