UNPKG

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