forked from readium/readium-js-viewer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtests.js
336 lines (278 loc) · 11.6 KB
/
tests.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
var chai = require("chai");
var chaiAsPromised = require("chai-as-promised");
var config = require('./config.js');
chai.use(chaiAsPromised);
chai.should();
var wd = require('wd');
var asserters = wd.asserters;
chaiAsPromised.transferPromiseness = wd.transferPromiseness;
var extensionUrl = '';
//var extensionUrl = 'http://google.com';
describe("chrome extension tests", function() {
var browser;
var addLibraryItemForApp = function(filePath){
console.log(filePath);
return this
.waitForElementByCss('.icon-add-epub',asserters.isDisplayed, 10000)
.click()
.waitForElementByCss('#add-epub-dialog', asserters.isDisplayed, 10000)
.elementByCss('#epub-upload')
.sendKeys(filePath)
//.waitForElementByCss('.progress-bar', asserters.isDisplayed, 10000)
.waitForElementByCss('.library-item', asserters.isDisplayed, 20000)
.sleep(500);//wait for the modal dialog backdrop to fade
}
var addLibraryItemForBrowser = function(filePath){
return this.noop();
}
var switchToReaderFrameOnTransition = function(){
return this
.waitFor(asserters.jsCondition('document.querySelectorAll("#reading-area .spinner").length == 0 && document.querySelectorAll("#epubContentIframe").length == 1'), 10000)
.frame('epubContentIframe');
}
var openExtensionUrl = function(){
// this is necessary because it seems that chrome won't load the extension immediately after startup.
return this.get(extensionUrl).sleep(1000).get(extensionUrl);
}
wd.addPromiseChainMethod('addLibraryItem', config.chromeExtension ? addLibraryItemForApp : addLibraryItemForBrowser);
wd.addPromiseChainMethod('openExtensionUrl', openExtensionUrl);
wd.addPromiseChainMethod('switchToReaderFrameOnTransition', switchToReaderFrameOnTransition);
beforeEach(function() {
if (process.env.USE_SAUCE){
var url = "ondemand.saucelabs.com",
port = 80;
if (process.env.TRAVIS_JOB_NUMBER){
config.browser["tunnel-identifier"] = process.env.TRAVIS_JOB_NUMBER;
url = 'localhost';
port = 4445;
}
browser = wd.promiseChainRemote(url, port, 'readium', 'a36ebc10-e514-4da6-924c-307aec513550');
}
else{
browser = wd.promiseChainRemote();
}
console.log(config.browser.browserName);
var retVal = browser.init(config.browser).setAsyncScriptTimeout(30000);
browser.on('status', function(info) {
//console.log('STATUS >', info);
});
browser.on('command', function(meth, path, data) {
//console.log('COMMAND >', meth, path, (data || ''));
});
browser.on('http', function(meth, path, data) {
//console.log('HTTP >', meth, path, (data || ''));
});
//console.log(retVal);
if (process.env.TRAVIS_JOB_NUMBER){
return retVal.sauceJobUpdate({name: process.env.TRAVIS_JOB_NUMBER});
}
else{
return retVal;
}
});
afterEach(function() {
return browser
//.log('browser')
//.then(function(logs) { console.log(logs);})
.quit();
});
if (config.chromeExtension){
it('confirm install and find url', function(){
var extensionsHome = 'chrome://inspect/#extensions'
return browser.get(extensionsHome).sleep(500).get(extensionsHome)
.elementByXPath("//div[starts-with(text(), 'Readium')]/following-sibling::*")
.text().then(function(url){
var pathStart = url.lastIndexOf('/');
extensionUrl = url.substring(0, pathStart) + '/index.html'
});
})
}
else{
extensionUrl = config.url;
console.log(extensionUrl);
}
it('should display library navbar', function(){
return browser.openExtensionUrl()
.waitForElementByCss('.navbar', asserters.isDisplayed , 10000)
.waitForElementByCss('.icon-add-epub', asserters.isDisplayed , 10000)
.should.eventually.be.ok;
});
it('add epub from zip', function(){
var testFile = process.cwd() + '/tests/epubs/accessible_epub_3.epub';
return browser.openExtensionUrl()
.addLibraryItem(testFile)
.elementByCss('.library-item .title')
.text()
.should.become('Accessible EPUB 3')
.elementByCss('.library-item .author')
.text()
.should.become('Matt Garrish');
});
describe ('common library tests', function(){
it('view details', function(){
var testFile = process.cwd() + '/tests/epubs/accessible_epub_3.epub';
return browser.openExtensionUrl()
.addLibraryItem(testFile)
.elementByCss('button.details').isVisible()
.should.eventually.be.false // verify details button is hidden at this point
.elementByCss('.icon-list-view')//change to list view
.click()
.elementByCss('button.details').isVisible()
.should.eventually.be.true
.elementByCss('button.details')
.click()
.waitForElementByCss('.details-dialog', asserters.isDisplayed , 10000)
.waitForElementByCss('.modal-book-info .modal-detail', asserters.isDisplayed , 10000)// the book info is loaded dynamically after the dialog opens
.elementByCss('.modal-book-info .modal-detail:nth-of-type(1)').text()
.should.become('Author: Matt Garrish')
.elementByCss('.modal-book-info .modal-detail:nth-of-type(2)').text()
.should.become('Publisher: O’Reilly Media, Inc.')
.elementByCss('.modal-book-info .modal-detail:nth-of-type(3)').text()
.should.become('Pub Date: 2012-02-20')
.elementByCss('.modal-book-info .modal-detail:nth-of-type(4)').text()
.should.become('Modified Date: 2012-10-24T15:30:00Z')
.elementByCss('.modal-book-info .modal-detail:nth-of-type(5)').text()
.should.become('ID: urn:isbn:9781449328030')
.elementByCss('.modal-book-info .modal-detail:nth-of-type(6)').text()
.should.become('EPUB version: 3.0');
});
it('read book from details dialog', function(){
var testFile = process.cwd() + '/tests/epubs/accessible_epub_3.epub';
return browser.openExtensionUrl()
.addLibraryItem(testFile)
.elementByCss('.icon-list-view')//change to list view
.click()
.elementByCss('button.details')
.click()
.waitForElementByCss('.details-dialog button.read', asserters.isDisplayed , 10000)
.click()
.switchToReaderFrameOnTransition()
.waitForElementByCss('h1.title', asserters.isDisplayed , 10000)
.text()
.should.become('Accessible EPUB 3');
});
});
describe('common reader tests', function(){
var openSettingsDialog = function(){
return this.elementByCss('.icon-settings')
.click()
.waitForElementByCss('#settings-dialog', asserters.isDisplayed , 10000)
.sleep(500);
//.sleep(500);
}
wd.addPromiseChainMethod('openSettingsDialog', openSettingsDialog);
beforeEach(function() {
var testFile = process.cwd() + '/tests/epubs/accessible_epub_3.epub';
return browser.openExtensionUrl()
.addLibraryItem(testFile)
.elementByCss('.library-item button.read')
.click()
.switchToReaderFrameOnTransition()
.waitForElementByCss('h1.title', asserters.isDisplayed , 10000)
.frame()
});
it('turn page', function(){
return browser
.elementByCss('#right-page-btn')
.click()
.switchToReaderFrameOnTransition()
.waitForElementByCss('h2.title', asserters.isDisplayed , 10000)
.text()
.should.become('Preface');
});
it ('table of contents', function(){
return browser
.elementByCss('.icon-toc')
.click()
.waitForElementByCss('#readium-toc-body', asserters.isDisplayed , 10000)
.elementByCss('a[href="ch01.xhtml"]')
.text()
.should.become('1. Introduction')
.elementByCss('a[href="ch01.xhtml"]')
.click()
.switchToReaderFrameOnTransition()
.waitForElementByCss('#introduction h2.title')
.text()
.should.become('Chapter 1. Introduction');
});
it ('test font size', function(){
return browser
.openSettingsDialog()
.elementByCss('#font-size-input')
.getValue()
.should.become('100')
.execute('$("#font-size-input").val(160).change();')
.elementByCss('#font-size-input')
.getValue()
.should.become('160')
.execute('return $(".preview-text")[0].style.fontSize')
.should.become('1.6em')
.elementByCss('#settings-dialog .btn-primary')
.click()
.sleep(500)
.frame('epubContentIframe')
.execute('return document.querySelector("html").style.fontSize')
.should.become('160%');
});
it('test layout options', function(){
return browser
.openSettingsDialog()
.execute('return $("#spread-default-option input").prop("checked")')
.should.eventually.be.true
.execute('return $("#two-up-option input").prop("checked")')
.should.eventually.be.false
.execute('return $("#one-up-option input").prop("checked")')
.should.eventually.be.false
.execute('$("#one-up-option input").prop("checked", true)')
.elementByCss('#settings-dialog .btn-primary')
.click()
.sleep(500)
.execute('return $("iframe").css("width")').then(function(width){
return browser
.frame('epubContentIframe')
.execute('return document.querySelector("html").style.width')
.should.become(width)
.frame()
.openSettingsDialog()
.execute('$("#two-up-option input").prop("checked", true)')
.elementByCss('#settings-dialog .btn-primary')
.click()
.sleep(500)
.frame('epubContentIframe')
.execute('return document.querySelector("html").style.width')
.should.not.become(width);
})
});
// it('test margins', function(){
// return browser
// .openSettingsDialog()
// .elementByCss('#tab-butt-layout')
// .click()
// .elementByCss('#margin-size-input')
// .isDisplayed()
// .should.eventually.be.true
// .elementByCss('#margin-size-input')
// .getValue()
// .should.become('60');
// });
it('test page width', function(){
return browser
.openSettingsDialog()
.elementByCss('#tab-butt-layout')
.click()
.elementByCss('#column-max-width-input')
.isDisplayed()
.should.eventually.be.true
.elementByCss('#column-max-width-input')
.getValue()
.should.become('550');
});
it('READIUM HTTP EXIT...', function(){
var url = "http://127.0.0.1:8080/exit-request_READIUMHTTPEXIT_.html";
console.log(url);
return browser.get(url, function() {
browser.done();
});
});
});
});