![]()
API Guide - Link |
Courses in c#, ruby, shell scripting, Software testing courses and more
|
|||||||||||||||||||||||||
|
||||||||||||||||||||||||||
| Class | WET::WebLink |
| In: |
WebLink.rb
|
| Parent: | WebObject |
Wrapper sitting on top of Watir::Link. Most functionality is taken care of by Watir
These are the HTML Links present in Web pages.
Constructor - Scripts should not initialize a WebLink directly. The creation part should be done using the WebContainer.Link(*args) method provided by containers like Browsers and Frames
These are the HTML Links present in Web pages.
The syntax to get the reference of a Link is:
Container.Link("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").Link("text:=New Blank Link")
The commpnly used attributes to identify a Link are:
text The text displayed for the Link
href The target URL that this link is pointing to
id The HTML id attribute of the textfield
Tip:To construct the definition for a Link,use the container's show_objects('Link')method.Then pick the one
that is appropriate for the Link of interest and copy paste it into your script.For example,if you were to say
Browser('title:=Controls').show_objects('Link')
then the putput is:
Links:
Browser('title:=Controls').Link('text:=New blank Link')
Copy paste the Browser(..)line into your script you can get a reference of the required Link
Actions:
1)Type the following lines into a new Ruby script
#####################################
require 'WET'
include WET
ie = Browser.new()
ie.goto "http://www.wet.qantom.org/userguide/browser_sample.html"
lnk = ie.Link('text:=New blank link')
puts "name=#{lnk.name}"
#####################################
2) Run the script
Result:
After the script runs,the following output is generated:
name=lnk001
In the above script,the first few lines,creates a new browser and navigates to sample page.The line,
tf = ie.Link('text:=New blank link')finds the link whose text is 'New blank link'.The next line prints
out the html name attribute of this textfield.
Check to see if the Link actually exists on the page.If the Link actually does exist,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’ operations.For example,after adding a new user,you may want to check that the user link actually does exist.
Check to see if the Link *does not*exist on the page.If the Link does not exist,then prints put 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 commin properties that are checked for a Link are:
name - The html name attribute of the Link id - The html id attribute of the Link text - The text is displayed by the Link href - What is the target that the link points to?
Besides the above properties you could use any of the properties of the MSHtml Link object.The properties are enumerated at; msdn.microsoft.com/library/default.asp?url=/workshop/author/dhtml/reference/objects/link.asp
If the result is a success then prints a Success to the report.Otherwise prints a failure.
Check to see if the expected text matches the text of the Link.If the Link’s text matches the search_text,then a success message is printed in the test report.Otherwise,a failure is printed out in the reporter.
Check to see if the expected text does not match the text of the Link.If the check is successful,that is,the Link’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.
Perform a click on the link.Calling this method is actually left clicking the Web Link using the mouse.
The click_without_blocking() method performs the same click option but in a separate process.This method is usually used when the browser becomes busy immediately after the link is clicked.When the browser becomes busy,the script cannot proceed to the next line,resulting in a sort of deadlock.
A Typical example of browser becoming busy is when it opens a modal dialog box.For some links,when a click is performed,it blocks the internet explorer window and is usually waiting for some other task to complete.This is most likely due to the fact that a modal popup is currently being displayed and the browser is waiting for this dialog to be dismissed.In your script,the next line may be ready to handle this popup dialog. However,if you use the click() method,then this line in your script is never reached as the browser has gone into a blocking mode.To get around this situation,you need to use a click_without_blocking()method.Here the click is executed in a separate process and immediately returns to the next line of execution.
Example usage:
Browser(...).Link(...).click_without_blocking
Browser(...).Dialog(...).Button('value:=OK').click
Now proceed with the next line of the browser processing.
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. |