Source Code Cross Referenced for VerifyElement.java in  » Testing » webtest » com » canoo » webtest » steps » verify » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Testing » webtest » com.canoo.webtest.steps.verify 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        // Copyright © 2002-2005 Canoo Engineering AG, Switzerland.
002:        package com.canoo.webtest.steps.verify;
003:
004:        import com.canoo.webtest.engine.Context;
005:        import com.canoo.webtest.engine.StepFailedException;
006:        import com.gargoylesoftware.htmlunit.html.HtmlElement;
007:        import com.gargoylesoftware.htmlunit.html.HtmlPage;
008:
009:        import java.util.Iterator;
010:        import java.util.List;
011:
012:        /**
013:         * @author unknown
014:         * @author Marc Guillemot
015:         * @webtest.step category="Core"
016:         * name="verifyElement"
017:         * alias="verifyelement"
018:         * description="This step verifies the existence of a particular <key>HTML</key> element (tag) in the result page. It is identified by its <key>HTML</key> element type (e.g. TITLE, HEAD, etc.) and the <em>text</em> value of the NAME attribute."
019:         */
020:        public class VerifyElement extends AbstractVerifyTextStep {
021:            private String fType;
022:
023:            public String getType() {
024:                return fType;
025:            }
026:
027:            /**
028:             * @webtest.parameter required="yes"
029:             * description="The <key>HTML</key> element type, e.g. "INPUT" for a <INPUT.../>  tag or "title" for <title>...</title>."
030:             */
031:            public void setType(final String newType) {
032:                fType = newType;
033:            }
034:
035:            public void doExecute() {
036:                int numberOfHits = getNumberOfHits();
037:
038:                if (numberOfHits > 1) {
039:                    throw new StepFailedException(
040:                            "More than 1 element with type \"" + fType
041:                                    + "\" and name \"" + getText()
042:                                    + "\" found!", this );
043:                }
044:                if (numberOfHits == 0) {
045:                    throw new StepFailedException("No element of type \""
046:                            + fType + "\" and name \"" + getText()
047:                            + "\" found!", this );
048:                }
049:            }
050:
051:            /**
052:             * Gets the number of hits in the current response.
053:             * @deprecated Use {@link #getNumberOfHits()}.
054:             * @param context The execution context.
055:             * @return The number of hits.
056:             */
057:            protected int getNumberOfHits(final Context context) {
058:                return getNumberOfHits();
059:            }
060:
061:            protected int getNumberOfHits() {
062:                Context context = getContext();
063:                int numberOfHits = findElementAttributeValue(context,
064:                        getType(), ELEMENT_ATTRIBUTE_NAME, getText());
065:
066:                if (numberOfHits == 0) {
067:                    numberOfHits = findElementAttributeValue(context,
068:                            getType(), ELEMENT_ATTRIBUTE_ID, getText());
069:                }
070:                return numberOfHits;
071:            }
072:
073:            protected void verifyParameters() {
074:                super .verifyParameters();
075:                nullParamCheck(getType(), "type");
076:            }
077:
078:            private int findElementAttributeValue(final Context context,
079:                    final String elementType, final String attributeName,
080:                    String value) {
081:                final List li = getAllElementsOfType(context, elementType
082:                        .toLowerCase());
083:                return getNumberOfOccurances(li, value, attributeName);
084:            }
085:
086:            /**
087:             * Gets all elements of the given type from the current html response
088:             *
089:             * @param context
090:             * @param type
091:             * @return a list of {@link com.gargoylesoftware.htmlunit.html.HtmlElement}
092:             */
093:            protected static List getAllElementsOfType(final Context context,
094:                    final String type) {
095:                return ((HtmlPage) context.getCurrentResponse())
096:                        .getDocumentHtmlElement()
097:                        .getHtmlElementsByTagName(type);
098:            }
099:
100:            /**
101:             * Gets the number of elements having the value of the specified attribute matching the test
102:             * @param li
103:             * @param expectedString
104:             * @param attributeName
105:             */
106:            protected int getNumberOfOccurances(final List li,
107:                    final String expectedString, final String attributeName) {
108:                int numberOfHits = 0;
109:                for (Iterator iter = li.iterator(); iter.hasNext();) {
110:                    HtmlElement elt = (HtmlElement) iter.next();
111:                    if (verifyStrings(expectedString, elt
112:                            .getAttributeValue(attributeName))) {
113:                        ++numberOfHits;
114:                    }
115:                }
116:                return numberOfHits;
117:            }
118:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.