Wednesday, 9 March 2011

Regular Expressions and xpaths

Aim
In this exercise script does a dynamic registration and finally it verifies the dynamically generated email address using Regular Expression. Here is the aim of exercise is actually how can users use Regular expression in verifying the elements on the page.

What you will learn?
  • debugging
  • xpaths and regular expressions

Pre-requisites:
Key Steps what we are showing into the embedded video file
1. First we open the test scripts (in which regular expression is used) into the Selenium IDE.
2. Script uses verify command using regular expression.
3. Finally script creates an user.
4. Scripts verifies that user has been created using regular expression.


Conclusions

  • run the script many times and notice that the email is randomly generated and the verification passes accordingly - see verifyTextPresent in the script

Related Entries

Zip file location: ( download from here)
C:\FoundationSelenium\Ex11\RegularExpressionScript.html.


here is the screen of HTML script:



















here is the script in text format:
---------------------------------------------------

<?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>RegularExpression</title>
</head>
<body>
<table cellpadding="1" cellspacing="1" border="1">
<thead>
<tr><td rowspan="1" colspan="3">RegularExpression</td></tr>
</thead><tbody>
<tr>
<td>open</td>
<td>/</td>
<td></td>
</tr>
<tr>
<td>clickAndWait</td>
<td>//ul/li[@id='meta-2']/ul/li[1]/a</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>//input[@id='user_login']</td>
<td>admin</td>
</tr>
<tr>
<td>type</td>
<td>//input[@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>javascript{&quot;Post&quot; + new Date().getMilliseconds();}</td>
</tr>
<tr>
<td>clickAndWait</td>
<td>id=publish</td>
<td></td>
</tr>
<tr>
<td>clickAndWait</td>
<td>css=a.wp-first-item.current</td>
<td></td>
</tr>
<tr>
<td>verifyTextPresent</td>
<td>regexpi: Post[0-9]{2,3}</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>css=a.wp-first-item.current</td>
<td></td>
</tr>
<tr>
<td>waitForElementPresent</td>
<td>//tr[@id='user-1']/td[1]/strong/a</td>
<td></td>
</tr>
<tr>
<td>verifyTextPresent</td>
<td>regexpi: Test[0-9]{2,3}</td>
<td></td>
</tr>
<tr>
<td>clickAndWait</td>
<td>link=Log Out</td>
<td></td>
</tr>
</tbody></table>
</body>
</html>



----------------------------------------------

here is the embedded video file:


10 comments:

  1. notes
    use html syntaxhighlighter

    ReplyDelete
  2. notes
    the slide needs to change to use wordpress

    ReplyDelete
  3. html syntaxhighlighter is done, I am also not getting what line 'slide needs to change to use wordpress ' says here, please let me know?

    ReplyDelete
  4. notes:
    slide needs to change -action for viresh , i need to update the presentation slide.

    ReplyDelete
  5. notes:
    the syntax does not appear correctly on the blog page. it all appears on one line

    ReplyDelete
  6. Exercise 11
    notes:
    can you add a section at the top of this blog showing the key steps of what this script is trying to show.

    ReplyDelete
  7. Notes for Vipin:
    this exercise needs to be modified so that it has an aim and purpose. E.g

    Take an existing script that does something ( in this case does a dynamic registration - i think?) . Then, the aim is for the delegate to add a final verify step that uses a regular expression to check that the dynamic email that was created exists.

    Without making a change like this, this is not an exercise and the delegate will not learn anything.

    ReplyDelete

Thank you for your comment
- Time2test Team