stale_element_test.js 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  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. 'use strict';
  18. var fail = require('assert').fail;
  19. var Browser = require('..').Browser,
  20. By = require('..').By,
  21. error = require('..').error,
  22. until = require('..').until,
  23. assert = require('../testing/assert'),
  24. test = require('../lib/test'),
  25. Pages = test.Pages;
  26. test.suite(function(env) {
  27. var driver;
  28. test.before(function*() { driver = yield env.builder().build(); });
  29. test.after(function() { return driver.quit(); });
  30. // Element never goes stale in Safari.
  31. test.ignore(env.browsers(Browser.SAFARI)).
  32. it(
  33. 'dynamically removing elements from the DOM trigger a ' +
  34. 'StaleElementReferenceError',
  35. function*() {
  36. yield driver.get(Pages.javascriptPage);
  37. var toBeDeleted = yield driver.findElement(By.id('deleted'));
  38. yield assert(toBeDeleted.getTagName()).isEqualTo('p');
  39. yield driver.findElement(By.id('delete')).click();
  40. yield driver.wait(until.stalenessOf(toBeDeleted), 5000);
  41. });
  42. test.it('an element found in a different frame is stale', function*() {
  43. yield driver.get(Pages.missedJsReferencePage);
  44. var frame = yield driver.findElement(By.css('iframe[name="inner"]'));
  45. yield driver.switchTo().frame(frame);
  46. var el = yield driver.findElement(By.id('oneline'));
  47. yield driver.switchTo().defaultContent();
  48. return el.getText().then(fail, function(e) {
  49. assert(e).instanceOf(error.StaleElementReferenceError);
  50. });
  51. });
  52. });