UNPKG

2.26 kBJavaScriptView Raw
1// Licensed to the Software Freedom Conservancy (SFC) under one
2// or more contributor license agreements. See the NOTICE file
3// distributed with this work for additional information
4// regarding copyright ownership. The SFC licenses this file
5// to you under the Apache License, Version 2.0 (the
6// "License"); you may not use this file except in compliance
7// with the License. You may obtain a copy of the License at
8//
9// http://www.apache.org/licenses/LICENSE-2.0
10//
11// Unless required by applicable law or agreed to in writing,
12// software distributed under the License is distributed on an
13// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14// KIND, either express or implied. See the License for the
15// specific language governing permissions and limitations
16// under the License.
17
18'use strict';
19
20var fail = require('assert').fail;
21
22var Browser = require('..').Browser,
23 By = require('..').By,
24 error = require('..').error,
25 until = require('..').until,
26 assert = require('../testing/assert'),
27 test = require('../lib/test'),
28 Pages = test.Pages;
29
30
31test.suite(function(env) {
32 var driver;
33 test.before(function*() { driver = yield env.builder().build(); });
34 test.after(function() { return driver.quit(); });
35
36 // Element never goes stale in Safari.
37 test.ignore(env.browsers(Browser.SAFARI)).
38 it(
39 'dynamically removing elements from the DOM trigger a ' +
40 'StaleElementReferenceError',
41 function*() {
42 yield driver.get(Pages.javascriptPage);
43
44 var toBeDeleted = yield driver.findElement(By.id('deleted'));
45 yield assert(toBeDeleted.getTagName()).isEqualTo('p');
46
47 yield driver.findElement(By.id('delete')).click();
48 yield driver.wait(until.stalenessOf(toBeDeleted), 5000);
49 });
50
51 test.it('an element found in a different frame is stale', function*() {
52 yield driver.get(Pages.missedJsReferencePage);
53
54 var frame = yield driver.findElement(By.css('iframe[name="inner"]'));
55 yield driver.switchTo().frame(frame);
56
57 var el = yield driver.findElement(By.id('oneline'));
58 yield driver.switchTo().defaultContent();
59 return el.getText().then(fail, function(e) {
60 assert(e).instanceOf(error.StaleElementReferenceError);
61 });
62 });
63});