upload_test.js 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  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 fs = require('fs');
  19. var Browser = require('..').Browser,
  20. By = require('..').By,
  21. until = require('..').until,
  22. io = require('../io'),
  23. remote = require('../remote'),
  24. assert = require('../testing/assert'),
  25. test = require('../lib/test'),
  26. Pages = test.Pages;
  27. test.suite(function(env) {
  28. var LOREM_IPSUM_TEXT = 'lorem ipsum dolor sit amet';
  29. var FILE_HTML = '<!DOCTYPE html><div>' + LOREM_IPSUM_TEXT + '</div>';
  30. var fp;
  31. test.before(function() {
  32. return fp = io.tmpFile().then(function(fp) {
  33. fs.writeFileSync(fp, FILE_HTML);
  34. return fp;
  35. });
  36. })
  37. var driver;
  38. test.before(function*() {
  39. driver = yield env.builder().build();
  40. });
  41. test.after(function() {
  42. if (driver) {
  43. return driver.quit();
  44. }
  45. });
  46. test.ignore(env.browsers(
  47. Browser.IPAD,
  48. Browser.IPHONE,
  49. // Uploads broken in PhantomJS 2.0.
  50. // See https://github.com/ariya/phantomjs/issues/12506
  51. Browser.PHANTOM_JS,
  52. Browser.SAFARI)).
  53. it('can upload files', function*() {
  54. driver.setFileDetector(new remote.FileDetector);
  55. yield driver.get(Pages.uploadPage);
  56. var fp = yield driver.call(function() {
  57. return io.tmpFile().then(function(fp) {
  58. fs.writeFileSync(fp, FILE_HTML);
  59. return fp;
  60. });
  61. });
  62. yield driver.findElement(By.id('upload')).sendKeys(fp);
  63. yield driver.findElement(By.id('go')).click();
  64. // Uploading files across a network may take a while, even if they're small.
  65. var label = yield driver.findElement(By.id('upload_label'));
  66. yield driver.wait(until.elementIsNotVisible(label),
  67. 10 * 1000, 'File took longer than 10 seconds to upload!');
  68. var frame = yield driver.findElement(By.id('upload_target'));
  69. yield driver.switchTo().frame(frame);
  70. yield assert(driver.findElement(By.css('body')).getText())
  71. .equalTo(LOREM_IPSUM_TEXT);
  72. });
  73. });