1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 |
|
15 |
|
16 |
|
17 |
|
18 | 'use strict';
|
19 |
|
20 | var fs = require('fs');
|
21 |
|
22 | var 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 |
|
31 | test.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 |
|
58 |
|
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 |
|
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 | });
|