![]()
API Guide - Textarea |
Courses in c#, ruby, shell scripting, Software testing courses and more
|
|||||||||||||||||||||||||
|
||||||||||||||||||||||||||
| Class | WET::WebTextarea |
| In: |
WebTextarea.rb
|
| Parent: | WebObject |
Class represents aWeb Text Area.This class extends Watir::TextField and most of the core functionality is implemented in Watir::Textfield class The textarea controls are the multiline text controls that allow you to input larger text data as compared to
ordinary textfields.
Create an instance of the class.Scripts should not directly instantiate this class.Instead you should use the WebContainer.Testarea(*args)method provided by containers like browser/frame
The textarea controls are the multiline text controls that allow you to input larger text data as compared to ordinary textfields.
The syntax to get the reference of a textfield is:
Container.TextArea("name:=value")
Where
Container is a Browser,Frame,Table or any other container that can hold HTML elements as its children.
name is the name of the attribute to be checked
value is the value of that attribute
Example:
Browser('title:=Controls').Textarea('name:=ta001')
The commonly used attributes to identify a Textarea are:
name The HTML name attribute of the textarea
id The HTML id attribute of the textarea
Tip:To construct the definition for a textarea,use the container's show_objects('Textarea')method.Then pick the
one that is appropriate for the textarea of interest and copy paste it into your script.For example,if you
were to say
Browser('title:=Controls').Textarea('name:=ta001')
Copy paste the Browser(..)line in your script and you can get a reference of the required Textarea
Actions:
1) Type the following lines into a new Ruby script
#####################################
require 'WET'
include WET
ie = Browser.new()
ie.goto "http://wet.qantom.org/userguide/browser_sample.html"
tf = ie.Textarea('name:=ta001')
puts "id=#(tf.id)"
#####################################
2)Run the script
Result:
After the script runs the following output is generated:
id=ta001
In the above script,the first few lines,created a new browser and navigates to the sample page.The line,
tf = ie.Textarea('name:=ta001')finds the textarea whose name(html attribute)is 'ta001'.The next line prints
out the html ID of this textarea.
Check to see if the textarea actually exists on the page.If the textarea actually does exist on the page.If the textarea actually does exit,then prints out a success message in the test report.If it doesn’t exist,then it prints out a failure in the report.One example of using this check is immediately after performing ‘add’ operaions.For example,after adding a new user,you may want to check that the user link actually does exist.
Check to see if the textarea *does not* exist on the page.If the textarea does not exist,then prints out a success message in the test report.If it actually does exist,then it prints out a failure in the report.One example of using this check is immediately after performing ‘delete’ operations.For example,after deleting user ‘abc’,you may want to check that the user link for ‘abc’ has been deleted.
Check if a property’s actual value matches the expected value.The property to be checked is the first parameter and the expected value is the second parameter.The common properties that are checked for a textarea are:
name - The html name attribute of the textarea id - The html id attribute of the textarea text - The current value of the textarea Besides the above properties you could use any of the properties of the MSHtml Textarea object.The properties are enumerated at: http://msdn.microsoft.com/library/default.asp?url=/workshop/author/dhtml/reference/objects/textarea.asp If the result is a success then prints a Success to the report.Otherwise prints a failure.
Example: Actions:
Here we will check out the usage of the check_text commands.For the purpose of this section of the tutorial,
we will print out the results as a numeriv value.In a real test,the result is outputed to a HTML reporter.
1)Open a new script and type the following:
#####################################
require 'WET'
include WET
ie = Browser.new()
ie.goto "http://www.wet.qantom.org/userguide/browser_sample.html"
tf = ie.Textarea('name:=ta001')
tf.check_property("id,"ta001")
puts"result=#{reporter.result_status}"
#####################################
2)Run the script
Result:
After running the script outputs the following:
result=1
indicating that the test completed successfully.
Check to see if the expected text matches the text of the textarea.If the text area’s text matches the search_text, then a success message is printed in the test report.Otherwise,a failure is printed out in the report.
Check to see if the expected text does not match the text of the textarea.If the check is successful,that is, the textarea’s text does not match the expected text,then a success is printed in the test report.If the check fails,then a failure is printed in the test report.
Opposite of set() method. Clears the text of any Textarea
Actions:
1) First open an IE browser and navigate to http://www.wet.qantom.org/userguide/browser_sample.html
2) Now enter some text in the first textfield
Note : The above two steps can be skipped if you have already run the previous script and the browser is open.
3) Create a new Ruby script and put the following lines into it:
#####################################
require 'WET'
include WET
tf = Browser('title:=Controls').Textarea('name:=ta001')
tf.clear
#####################################
4) Run the above ruby script.
Result:
The result is that all the text entered in the first textarea of the sample page is wiped out.
Set the text of the Textarea .
Actions:
1)Create a new Ruby script and put the following lines into it.
#####################################
require 'WET
include WET
ie = Browser.new()
ie.goto "http://www.wet.qantom.org/userguide/browser_sample.html"
tf = ie.Textarea('name:=ta001')
tf.set "HELLO WORLD
More lines will be printed
than a simple textfield"
#####################################
2)Run the above script
Result:
The result is that the sample web page in a new IE window and its textarea,the text
HELLO WORLD
More lines will be printed
than a simple textfield
is entered.
Check to see if the object exists or not at runtime.
Returns true if the object exists, false if it doesn’t
| WET is a opensource automated web testing tool which uses Watir as the library to drive web pages. WET drives an IE Browser directly and so the automated testing done using WET is equivalent to how a user would drive the web pages. WET extends the scripting abilities of Watir and also offers the convenience of recorders. It is licensed under LGPL and BSD style open source licenses. |