|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
actiWATE is no longer supported
If you are interested in this product development, please contact rd@actimind.com Tutorial
actiWATE Framework
Section contents
OverviewactiWATE Framework provides a set of objects used for interacting with web application. The main object in actiWATE Framework is ActiwateTestCase. This is the base object for all actiWATE tests. All actiWATE tests are inherited from this class. In most cases this will be the only class you will need to write automated tests. The next object of actiWATE Framework is Window. Window object is an abstraction of a window of real Internet browser.
Several windows that sharing the same HTTP session (same cookies) are joined into ActiwateSession. By default actiWATE test works with one session and one window. But test can create new sessions and windows using methods Other actiWATE Framework objects represent particular HTML elements and used for reading and changing their state. For complete list of classes and their methods see API reference.
actiWATE Framework utilizes the principle of context. Most methods of ActiwateTestCase execute in context of particular HTML page, which can be either Window or Frame or IFrame object. For example, when test searches for text field using the method
The test can change the context using methods In certain cases usage of context reduces size of test code and a number of required local variables, and improves readability of the test code. For example, instead of the code
Window window = session.window();
setText(window.frame("main").textField("username"), "someuser");
setText(window.frame("main").textField("password"), "somepassword");
click(window.frame("main").buttonByText("Login"));
one can use
switchTo(session.window().frame("main"))
setText(textField("username"), "someuser");
setText(textField("password"), "somepassword");
click(buttonByText("Login"));
For detailed information see API reference and samples Frames.java and Popups.java.
HTML pages usually contain redundant space and carriage return characters, which are not displayed by real Internet browsers. If browser encounters sequence of space and/or carriage return characters it displays only one space character.
actiWATE Framework performs similar procedure. Methods that work with text on HTML page such as
actiWATE Framework provides a number of objects representing HTML form controls such as Button, RadioButton, Checkbox, SingleSelect, MultipleSelect, TextField, Textarea, etc. These objects are used for reading and changing state of HTML controls and thus interacting with web application being tested. Classes ActiwateTestCase, ActiwateSession, Window, Frame, IFrame and TableCell contain a number of methods that can be used to find these objects by various criteria. Classes ActiwateTestCase and ActiwateSession provide a number of methods such as setText, setFileName, selectOption, click, etc, which can be used for interacting with these objects.
The following code demonstrates how to set the value of a text field with name "username". It uses method
setText(textField("username"), "jsmith");
For detailed information see API reference and samples Form.java, FileUpload.java, and LiveTestCase.java.
actiWATE Framework provides objects Frame and IFrame which represent FRAME and IFRAME HTML elements correspondingly. These objects are similar to the object Window at large. Frame and IFrame objects can be used as a context of a test (see Test context).
The following code switches the context of the test to the frame with name "main". It uses the method
switchTo(window().frame("main"));
For detailed information see API reference and sample Frames.java.
actiWATE Framework provides classes Table, TableRow and TableCell for working with HTML tables. You can get table row by index and cell by row and cell indexes. Row and cell indexes are order numbers of TR and TD (TH) elements inside TABLE and TR elements correspondingly. Indexes do not depend on colspan and rowspan attributes. The following figure shows values of row and cell indexes in case when rowspans and colspans are used.
![]() Picture 3 Table row and cell indexes
For detailed information see API reference and sample Tables.java.
There are several classes and methods in actiWATE Framework, which simplify lookup of image maps and areas. Image maps are represented by ImageMap class. You can find maps by index or by name / id attribute value. ImageMap class provides you with access to the areas. This class also allows to retrieve all images referencing this map. Area class represents image areas. Image area properties, such as href, coords, shape, etc. are available via this class. For detailed information see API reference and sample ImageMaps.java.
When a web application opens a new browser window, either using JavaScript function open() or using value _blank as a target for a link or a form, actiWATE Framework creates new Window object and adds it to the list of windows of a session. Later on, actiWATE test can get this window using method The following code verifies that clicking on the button opens a new window. When the window is no longer needed the code closes it.
click(buttonByText("Open Pop-Up"));
switchTo(windowWithTitle("This is pop-up window"));
click(buttonByText("Close Pop-Up"));
switchTo(window(0))
For detailed information see API reference and sample Popups.java.
In order to test whether application correctly uses JavaScript functions
For detailed information see API reference and sample AlertConfirmPrompt.java.
There are number of events that are executed asynchronously in browsers. These events include:
The time-line is represented in actiWATE by the container object that implements the
All event objects implement the
The time flow can be emulated by number of methods of the Consider the following example that illustrates the time-line concept: Suppose at some point of time there are three asynchronous events that should be triggered:
![]()
If we call
![]()
Asynchronous event typesactiWATE supports four asynchronous events that are represented by the interfaces described below.
setTimeout("alert(location)", 10);
When this line is executed, the
setInterval("i++", 5);
When this line is executed, the
<META http-equiv="refresh" content="2;url=http://www.actiwate.com">
Normally, after the page containing this tag is parsed by actiWATE, the new
Processing of events
There are two ways of processing asynchronous events: manual and automatic. Manual processing is performed
by calling of Manual mode: Manual processing of events is intended to check Web Application's state before and after some asynchronous event is triggered. For example you might want to check an HTML page content before an AJAX request is send from this page and then check the page once again after the AJAX response is processed.
Automatic mode: Automatic mode can be used in tests that don't verify page behavior in details, i.e. results of every asynchronous event separately. In this mode actiWATE automatically executes events that appear in the time-line during testing. If a tested web application has many asynchronous events, this mode helps to avoid writing of numerous calls to AsyncEvents interface since the events are processed automatically after each action such as clicks or goTo() calls. Automatic mode is configured in actiWATE configuration file using the following two properties:
There is also one peculiarity of this mode: If a subsequent action didn't lead to new events in the time-line, no events are executed independently on whether the time-line already contains events with time offset less than the specified maximum. This means that the automatic execution happens only if new events with time offset property less or equal to the autoExecAsyncEventsOffset value were added in result of an action. This behavior is intended to prevent numerous automatic executions of events on some page in case many actions are performed on the page but no new events are added. For additional information see API reference and XmlHttpRequest.java and Timers.java samles. Most browsers provide JavaScript 'screen' object (window.screen) that contains information about the client's screen and rendering capabilities. Microsoft Internet Explorer 6.0 provides the following screen properties:
actiWATE supports the screen object with the above properties and allows one to change the following ones in a test:
For the following read-only properties actiWATE returns constant values that cannot be changed:
Both bufferDepth and updateInterval properties have default value '0' and can be changed in JavaScript. You can also override default values for availHeight, availWidth, colorDepth, height, and width properties in actiwate.properties file for all actiWATE sessions. For detailed information see:
In certain cases it can be useful to perform some non-standard actions, such as changing value of hidden input element. For such cases actiWATE Framework provides access to HTML DOM. You can use HTML DOM to find certain HTML elements, verify DOM state, read or change element attributes etc. The following methods can be used to access HTML DOM:
actiWATE Framework provides interface for accessing HTTP response data. This can be useful when window or frame contains non-HTML content. In this case you can use the method The following code verifies that window contains a GIF image.
HttpResponse response = window().response();
assertEquals("image/gif", response.getContentType());
For detailed information see API reference and sample NonHTMLContent.java.
In certain cases it can be useful to execute JavaScript right from the test code, for example, to check the value of JavaScript variable declared in HTML page. actiWATE Framework gives an opportunity to do so. For example, in order to verify that value of JavaScript variable currentWizardPage equals to 3 you can use the following code:
assertEquals(new Integer(3), executeJavaScript("currentWizardPage"));
For detailed information see API reference and sample CustomJavaScript.java.
Most of web pages intercept and process actions performed by a user working in a browser, such as mouse movement, click on a mouse button, keystrokes etc. These actions are converted to JavaScript events by the browser. actiWATE allows emulating of these events in order to verify reactions of tested web pages. Currently actiWATE supports only click action for any HTML element. When the click action is performed the following sequence of event is fired: mousedown, focus, mouseup, click. For example, if you need to emulate click on a <div> HTML element, you can write code like this: HTMLElement myDiv = ( HTMLElement ) page().document().getElementById( "myDiv" ); click( myDiv );For detailed information see API reference and sample JavaScriptEvents.java.
actiWATE doesn't support all the client-side technologies of real Internet browser. If HTML page being tested uses the technology that is not yet supported, such as Dynamic HTML behaviors or Macromedia Flash, then automated test can fail. actiWATE provides work-around so that such HTML pages can be tested. For example, suppose that tested page contains the following HTML code that uses getExpression method:
<span id="blueSpan" style="background-color:lightblue; width:200px">
The width of this blue span is set inline at 200 pixels.
</span>
<span id="yellowSpan" style="background-color:lightyellow;width:400px">
The width of this yelllow span is set inline at 400 pixels.
</span>
<span id="greenSpan" style="background-color:lightgreen;
width:expression(blueSpan.style.pixelWidth + yellowSpan.style.pixelWidth)">
Expression is used to set the width of this span.
</span>
<script>
var widthExpr = greenSpan.style.getExpression("width");
...
</script>
Then in order to avoid JavaScript error, you should
disableJavaScript(false);
goTo("...");
page().executeJavaScript("greenSpan.style.getExpression = function(){ "+
"return 'mock getExpression result';};");
page().runPageScripts();
enableJavaScript();
For detailed information see API reference and sample DisableJavaScript.java.
Basic authorization is used to restrict access to Web documents or CGI scripts by user name and password. When a user accesses the restricted content through a browser he is presented with a dialog requesting credentials (user name and password) to access the content. actiWATE provides an ability to specify required credentials before a restricted content is reached. There are two ways to specify credentials:
If you need to reuse test code within one test class simply extract the reusable code to separate method and call it whenever needed. This method can accept parameters if needed. If it is necessary to reuse same method from several test classes then there are two options. The first option is making a superclass for a number of test classes and placing reusable method in it. Sometimes this approach is not applicable, for example, if test classes are so different that having common superclass is confusing. In this case you can use the second option. The second option is putting reusable code into a static method, which accepts object ActiwateSession as one of its parameters. You can call this method from any test class. Methods of class ActiwateTestCase, being non-static, will not be available from the reusable code. This code will use methods of session object passed as parameter. See also sample TestScriptReusing.java.
© Copyright Actimind, Inc. 2000-2007 All rights reserved | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||