Monday, 7 March 2011

Exercise 1 - Your first Selenium Script

Aim:
Create your first Selenium Record and Playback Test Script and execute against the test site.

Difficulty Level: Easy

What you will learn?
  • Creation of the first selenium script
  • Notepad++ to modify the script and notice the syntax highlighting
  • Saving the script as ".html" is good practice
Pre-requisites:
Tips:
  1. Use ".html" extension when naming the test suite and test cases
  2. Use Notepad++ to edit the files with syntax highlighting
Exercise steps:
  1. navigate to the http://foundation.time2test.co.uk
  2. login using username: admin, password: time4test
  3. Click on "user info"
  4. click on "posts"
  5. click on "add new"
  6. Enter "title"
  7. Click "publish"
  8. Click on Logout
  9. ( also ensure to add in the assertion command to your script)
Solution:

Commands Used in Example

  1. open
  2. clickAndWait
  3. assertTextPresent
  4. type



What you learned?

  1. Selenium IDE to record a script against a content management system
  2. Selenium IDE commands
  3. Syntax Highlighting in Notepad++ helps with debugging
  4. Selenium IDE scripts saving and opening
  5. Concept of asserting for text

Nov 2012 - Please use the script on this entry as the download version may be out of date.
Zip file location: ( download from here)
C:\FoundationSelenium\Ex1\FirstScript.html

Script in 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>FirstScript</title>
</head>
<body>
<table cellpadding="1" cellspacing="1" border="1">
<thead>
<tr><td rowspan="1" colspan="3">FirstScript</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>assertTextPresent</td>
 <td>Dashboard</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>MyFirstPost</td>
</tr>
<tr>
 <td>clickAndWait</td>
 <td>id=publish</td>
 <td></td>
</tr>
<tr>
 <td>clickAndWait</td>
 <td>link=Log Out</td>
 <td></td>
</tr>
<tr>
 <td>assertElementPresent</td>
 <td>id=user_login</td>
 <td></td>
</tr>
<tr>
 <td>assertElementPresent</td>
 <td>id=user_pass</td>
 <td></td>
</tr>
</tbody></table>
</body>
</html>


Helpful Video:


5 comments:

  1. notes:
    the video needs to show the scipt being recorded.

    ReplyDelete
  2. I have updated exercise's slide as well.

    ReplyDelete
  3. Add an assertion at the end of the recorded script after the Logout.

    ReplyDelete

Thank you for your comment
- Time2test Team