1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package net.sf.jameleon.plugin.selenium.tags;
20
21 import net.sf.jameleon.function.ContextHelper;
22 import net.sf.jameleon.plugin.selenium.SeleniumFunctionTag;
23
24 /***
25 * Tries to validate a javascript condition during a certain amount of time. If the validation
26 * isn't successful after timeout the test is considered 'failed'.
27 * This tag is useful in AJAX-like applications where page-contents aren't always directly available
28 * after loading a page.
29 * <br/>
30 * The condition is a (set of) javascript call(s) which can call Selenium functions and webapplication-functions.
31 * To get the window of your application, you can use the JavaScript snippet selenium.browserbot.getCurrentWindow(), and then run your JavaScript in there.
32 * For more information on syntax of Selenium's javascript functions, please refer to Selenium's API documentation.
33 * <br/>
34 * To validate the contents of a HTML element with ID <b>SomeElement</b>:
35 * (<span id="SomeTable" >some value</span>)
36 * <pre><source>
37 * <selenium-wait-for-condition
38 * functionId="Validate HTML element contents with ID 'SomeElement' has value 'some value'"
39 * condition="var value = selenium.getValue(\"//span[@id='SomeElement']\"); value.match(\"some value\");">
40 * </source></pre>
41 * @jameleon.function name="selenium-wait-for-condition" type="validation"
42 * @author Sannie Kwakman
43 * @author Christian Hargraves
44 */
45 public class SeleniumWaitForConditionTag extends SeleniumFunctionTag{
46
47 /***
48 * The condition which should return true before timeout
49 * @jameleon.attribute required="true"
50 */
51 protected String condition;
52
53 /***
54 * Amount of milliseconds to wait for the condition.
55 * @jameleon.attribute contextName="seleniumWaitForTimeoutSeconds" default=20000
56 */
57 protected int timeout = 20000;
58
59 public int getTimeoutSeconds(){
60 return ContextHelper.getValueAsIntWithConfig(context, "seleniumWaitForTimeoutSeconds", "seleniumWaitForTimeoutSeconds", timeout);
61 }
62
63 public void testBlock(){
64 try
65 {
66 session.waitForCondition(condition, ""+getTimeoutSeconds());
67 }
68 catch (Exception e)
69 {
70
71 fail("selenium-ait-for-condition failed: "+e.getLocalizedMessage());
72 }
73 }
74
75 }