mirror of
https://github.com/niklasvh/html2canvas.git
synced 2023-08-10 21:13:10 +03:00
Add screenshot collecting server
This commit is contained in:
@ -1,5 +0,0 @@
|
||||
/tests/reftests/background/radial-gradient.html
|
||||
/tests/reftests/text/chinese.html
|
||||
[Edge]/tests/reftests/acid2.html
|
||||
[Edge]/tests/reftests/pseudoelements.html
|
||||
[Edge]/tests/reftests/text/multiple.html
|
||||
|
@ -4,7 +4,12 @@ sauceConnectLauncher(
|
||||
{
|
||||
username: process.env.SAUCE_USERNAME,
|
||||
accessKey: process.env.SAUCE_ACCESS_KEY,
|
||||
logger: console.log
|
||||
logger: console.log,
|
||||
// Log output from the `sc` process to stdout?
|
||||
verbose: true,
|
||||
|
||||
// Enable verbose debugging (optional)
|
||||
verboseDebugging: true
|
||||
},
|
||||
err => {
|
||||
if (err) {
|
||||
|
@ -2,6 +2,8 @@ import {expect} from 'chai';
|
||||
import parseRefTest from '../scripts/parse-reftest';
|
||||
import reftests from './reftests';
|
||||
import querystring from 'querystring';
|
||||
import platform from 'platform';
|
||||
import Promise from 'promise-polyfill';
|
||||
|
||||
const DOWNLOAD_REFTESTS = false;
|
||||
const query = querystring.parse(location.search.replace(/^\?/, ''));
|
||||
@ -78,7 +80,7 @@ const assertPath = (result, expected, desc) => {
|
||||
})
|
||||
.forEach(url => {
|
||||
describe(url, function() {
|
||||
this.timeout(30000);
|
||||
this.timeout(60000);
|
||||
const windowWidth = 800;
|
||||
const windowHeight = 600;
|
||||
const testContainer = document.createElement('iframe');
|
||||
@ -113,7 +115,8 @@ const assertPath = (result, expected, desc) => {
|
||||
it('Should render untainted canvas', () => {
|
||||
return testContainer.contentWindow
|
||||
.html2canvas(testContainer.contentWindow.document.documentElement, {
|
||||
removeContainer: true
|
||||
removeContainer: true,
|
||||
backgroundColor: '#ffffff'
|
||||
})
|
||||
.then(canvas => {
|
||||
try {
|
||||
@ -330,6 +333,80 @@ const assertPath = (result, expected, desc) => {
|
||||
result
|
||||
);
|
||||
}
|
||||
|
||||
// window.__karma__
|
||||
if (false) {
|
||||
const MAX_CHUNK_SIZE = 75000;
|
||||
|
||||
const sendScreenshot = (tries, body, url) => {
|
||||
return new Promise((resolve, reject) => {
|
||||
const xhr = new XMLHttpRequest();
|
||||
|
||||
xhr.onload = () => {
|
||||
if (
|
||||
typeof xhr.status !== 'number' ||
|
||||
xhr.status === 200
|
||||
) {
|
||||
resolve();
|
||||
} else {
|
||||
reject(
|
||||
`Failed to send screenshot with status ${xhr.status}`
|
||||
);
|
||||
}
|
||||
};
|
||||
// xhr.onerror = reject;
|
||||
|
||||
xhr.open('POST', url, true);
|
||||
xhr.send(body);
|
||||
}).catch(e => {
|
||||
if (tries > 0) {
|
||||
// Older edge browsers and some safari browsers have issues sending large xhr through saucetunnel
|
||||
const data = canvas.toDataURL();
|
||||
const totalCount = Math.ceil(
|
||||
data.length / MAX_CHUNK_SIZE
|
||||
);
|
||||
return Promise.all(
|
||||
Array.apply(
|
||||
null,
|
||||
Array(totalCount)
|
||||
).map((x, part) =>
|
||||
sendScreenshot(
|
||||
0,
|
||||
JSON.stringify({
|
||||
screenshot: data.substr(
|
||||
part * MAX_CHUNK_SIZE,
|
||||
MAX_CHUNK_SIZE
|
||||
),
|
||||
part,
|
||||
totalCount,
|
||||
test: url,
|
||||
platform: {
|
||||
name: platform.name,
|
||||
version: platform.version
|
||||
}
|
||||
}),
|
||||
'/screenshot/chunk'
|
||||
)
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
return Promise.reject(e);
|
||||
});
|
||||
};
|
||||
return sendScreenshot(
|
||||
1,
|
||||
JSON.stringify({
|
||||
screenshot: canvas.toDataURL(),
|
||||
test: url,
|
||||
platform: {
|
||||
name: platform.name,
|
||||
version: platform.version
|
||||
}
|
||||
}),
|
||||
'/screenshot'
|
||||
);
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
|
Reference in New Issue
Block a user