pagebot-attribute-tests.html 3.79 KB
Newer Older
Rafael Monnerat's avatar
Rafael Monnerat committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">

<!--
Copyright 2004 ThoughtWorks, Inc

 Licensed under the Apache License, Version 2.0 (the "License");
 you may not use this file except in compliance with the License.
 You may obtain a copy of the License at

     http://www.apache.org/licenses/LICENSE-2.0

 Unless required by applicable law or agreed to in writing, software
 distributed under the License is distributed on an "AS IS" BASIS,
 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 See the License for the specific language governing permissions and
 limitations under the License.
-->
<html>
  <head>
	<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>JsUnit Utility Tests</title>
    <link rel="stylesheet" type="text/css" href="../../jsunit/css/jsUnitStyle.css">
<script language="JavaScript" type="text/javascript" src="../../jsunit/app/jsUnitCore.js"></script>
<script language="JavaScript" type="text/javascript" src="../jsmock/mock.js"></script>
<script language="JavaScript" type="text/javascript" src="../dummy-logging.js"></script>
<script language="JavaScript" type="text/javascript" src="../../core/scripts/htmlutils.js"></script>
<script language="JavaScript" type="text/javascript" src="../../core/scripts/selenium-browserdetect.js"></script>
<script language="JavaScript" type="text/javascript" src="../../core/scripts/selenium-browserbot.js"></script>
<script language="JavaScript" type="text/javascript">

function setUp() {
    pageBot = BrowserBot.createForWindow(window);

    element1 = document.getElementById("id1");
    element2 = document.getElementById("id2");
    element3 = document.getElementById("id3");
    element4 = document.getElementById("document.links[0]");
}


//
// Tests for finding attribute with id.
//
function testFindAttributeThrowsErrorIfNotElementFound() {
    var errorMessage = null;
    try {
        pageBot.findAttribute('noSuchElement@attribute');
    } catch (e) {
        errorMessage = e.message;
    }
    assertEquals("Element noSuchElement not found", errorMessage);
}

function testFindAttributeReturnsNullIfElementDoesNotHaveAttribute() {
    assertNull(pageBot.findAttribute('id1@wrong-attribute'));
}

// Different type of attributes
function testFindAttributeReturnsClassAttributeFromElementWithId() {
    assertEquals("id3class", pageBot.findAttribute('id3@class'));
}

function testFindAttributeReturnsAltAttributeFromElementWithId() {
    assertEquals("the second link", pageBot.findAttribute('id2@alt'));
}

function testFindAttributeReturnsCustomAttributeFromElementWithId() {
    assertEquals("bar", pageBot.findAttribute("id3@foo"));
}

function testFindAttributeReturnsNumericAttributeFromElementWithId() {
    assertEquals("24", pageBot.findAttribute("theInput@maxlength"));
}

// Different ways of locating elements
function testFindAttributeReturnsAttributeFromElementWithDomTraversal() {
    assertEquals("bar", pageBot.findAttribute('document.links[2]@foo'));
}

function testFindAttributeReturnsAttributeFromElementWithXPath() {
    assertEquals("parabar", pageBot.findAttribute('//p/@foo'));
}

function testFindAttributeReturnsAttributeFromElementWithXPathAndAttributeSelector() {
    assertEquals("parabar", pageBot.findAttribute("//p[@name='name1']/@foo"));
}


</script>
  </head>

  <body>
    <a id="id1" href="#id1">this is the first element</a>
    <a id="id2" name="name1" href="#id2" alt="the second link">this is the second element</a>
    <a id="id3" name="name1" href="#id3" class="id3class" foo="bar">this is the third element</a>
    <p id="document.links[0]" name="name1" foo="parabar">dummy element</p>
    <input name="theInput" maxlength="24"/>
  </body>
</html>