blob: 5eb0b439e9b8b191dd2485737a3dfe2386b2416c [file] [log] [blame]
<!DOCTYPE html>
<!--
Copyright 2011 WebDriver committers
Copyright 2011 Google 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>
<title>execute_script_test.html</title>
<script src="../../test_bootstrap.js"></script>
<script type="text/javascript">
goog.require('goog.userAgent');
goog.require('goog.userAgent.product');
goog.require("goog.testing.jsunit");
goog.require("webdriver.atoms.inject");
goog.require("webdriver.atoms.inject.frame");
</script>
<script type="text/javascript">
function isTestSkipped() {
return goog.userAgent.IE || goog.userAgent.product.SAFARI;
}
function testExecuteScriptWithWindow() {
if (isTestSkipped()) {
return;
}
var func = function () {return document.getElementById('bou').value;};
var win = getValue(webdriver.atoms.inject.frame.findFrameByIdOrName("iframe"));
assertEquals("there", getValue(webdriver.atoms.inject.executeScript(func, [], win)));
}
function testExecuteScriptWithStringFunctionWithWindow() {
if (isTestSkipped()) {
return;
}
var func = "return document.getElementById('bou').value";
var win = getValue(webdriver.atoms.inject.frame.findFrameByIdOrName("iframe"));
assertEquals("there", getValue(webdriver.atoms.inject.executeScript(func, [], win)));
}
function testExecuteScriptWithUnexistingWindow() {
var func = function () {return document.getElementById('bou').value;};
var win = getValue(webdriver.atoms.inject.frame.findFrameByIdOrName("bou"));
try {
webdriver.atoms.inject.executeScript(func, [], win);
fail();
} catch (e) {
// expected
}
}
function testExecuteScriptWithoutWindow() {
var func = function () {return document.getElementById('bou').value;};
assertEquals("here", getValue(webdriver.atoms.inject.executeScript(func, [])));
}
function getValue(rawResult) {
return goog.json.parse(rawResult).value;
}
</script>
</head>
<body>
<p id="x" name="para">Para</p>
<input type="text" id="bou" value="here"/>
<iframe src="nested_iframes.html" id="iframe"></iframe>
</body>
</html>