mirror of
https://github.com/ionic-team/ionic-framework.git
synced 2025-08-15 17:42:15 +08:00

* feat(e2e-tests) simplify e2e test structure * test(badge) add basic e2e test * test(button) update e2e test to new structure * test(card) add basic e2e test * test(checkbox) add basic e2e test * chore(e2e-test) update path to e2e module in run-e2e * fix(button) update toolbar e2e deps * fix(e2e-test) update path in snapshot script * feat(e2e-test) move e2e scripts into scripts/e2e * test(chip) add basic e2e test * test(content) add basic e2e test * test(datetime) add basic e2e test * style(e2e-test) use consistent title/header in e2e test pages * test(fab) add basic e2e test * fix(e2e-test) don't run e2e script when required * test(grid) add basic e2e test * test(icon) add basic e2e test * test(input) add basic e2e test * style(e2e-test) use consistent e2e test header titles * test(list) add basic e2e test * test(menu) add basic e2e test * test(modal) add basic e2e test * feat(e2e-test) add navigate export to e2e module * feat(e2e-test) add present method to Page class * test(popover) add basic e2e test * test(menu) add present left menu e2e test * test(radio) add basic e2e test * test(range) add basic e2e test * test(searchbar) add basic e2e test * test(segment) add basic e2e test * test(select) add basic e2e test * test(modal) add shows modal e2e test * test(slides) add basic e2e test * test(spinner) add basic/color e2e tests * test(tabs) add basic e2e test * test(toast) add basic e2e test * test(toggle) add basic e2e test * test(toolbar) add basic e2e test * docs(e2e-test) update e2e readme to reflect simplest test * test(card) update basic e2e test * chore(e2e-test) remove run-e2e script * test(components): move remaining component tests to index files * chore(package): add mocha to devDependencies * test(infinite-scroll) add basic e2e test * test(item-sliding) add basic e2e test * test(item) add basic/buttons e2e tests * test(nav) add basic e2e test * test(reorder) add basic e2e test * test(split-pane) add basic e2e test * chore() update declarations file * refactor(toast): reduce border-radius * chore(components): update components.d.ts
122 lines
4.0 KiB
JavaScript
122 lines
4.0 KiB
JavaScript
'use strict';
|
|
|
|
const request = require('request');
|
|
|
|
class Snapshot {
|
|
constructor(options) {
|
|
this.appId = (options && options.appId) || 'test_app';
|
|
this.domain = (options && options.domain) || 'localhost:8080';
|
|
this.groupId = (options && options.groupId) || 'test_group';
|
|
this.sleepTime = (options && options.sleepBetweenSpecs) || 500;
|
|
this.totalSpecs = options && options.totalSpecs;
|
|
this.accessKey = options && options.accessKey;
|
|
this.platformId =
|
|
options && options.platformDefaults && options.platformDefaults.params && options.platformDefaults.params.platform_id;
|
|
this.platformIndex =
|
|
options && options.platformDefaults && options.platformDefaults.params && options.platformDefaults.params.platform_index;
|
|
this.platformCount =
|
|
options && options.platformDefaults && options.platformDefaults.params && options.platformDefaults.params.platform_count;
|
|
this.width =
|
|
(options && options.platformDefaults && options.platformDefaults.params && options.platformDefaults.params.width) || -1;
|
|
this.height =
|
|
(options && options.platformDefaults && options.platformDefaults.params && options.platformDefaults.params.height) || -1;
|
|
|
|
this.start(options && options.testId);
|
|
}
|
|
|
|
async finish() {
|
|
console.log('waiting for uploads to complete');
|
|
await Promise.all(this.queue);
|
|
console.log(`done processing ${this.queue.length} screenshots`);
|
|
console.log(`${this.mismatches.length} snapshots had significant mismatches`);
|
|
console.log(`Test Id: ${this.testId}`);
|
|
}
|
|
|
|
start(testId) {
|
|
this.testId = testId;
|
|
this.queue = [];
|
|
this.highestMismatch = 0;
|
|
this.mismatches = [];
|
|
this.results = {};
|
|
}
|
|
|
|
async takeScreenshot(driver, options) {
|
|
this._resizeWindow(driver);
|
|
await this._allowForAnnimation();
|
|
const screenshot = await this._takeScreenshot(driver, options);
|
|
return this._post(screenshot);
|
|
}
|
|
|
|
_allowForAnnimation() {
|
|
return new Promise((resolve, reject) => {
|
|
setTimeout(function() {
|
|
resolve();
|
|
}, this.sleepTime);
|
|
});
|
|
}
|
|
|
|
_post(screenshot) {
|
|
const p = new Promise((resolve, reject) => {
|
|
request.post(`http://${this.domain}/screenshot`, { form: screenshot }, (error, res, body) => {
|
|
if (error) {
|
|
console.error(error);
|
|
} else if (res.statusCode > 400) {
|
|
console.log('error posting screenshot:', response.statusCode, body);
|
|
} else {
|
|
const data = JSON.parse(body);
|
|
this.highestMismatch = Math.max(this.highestMismatch, data.Mismatch);
|
|
const resultKey = (data.Mismatch * 1000 + 1000000 + '').split('.')[0] + '-' + screenshot.spec_index;
|
|
this.results[resultKey] = {
|
|
index: screenshot.spec_index,
|
|
name: screenshot.description,
|
|
mismatch: Math.round(data.Mismatch * 100) / 100,
|
|
compareUrl: data.CompareUrl,
|
|
screenshotUrl: data.ScreenshotUrl
|
|
};
|
|
if (data.IsMismatch) {
|
|
this.mismatches.push(resultKey);
|
|
}
|
|
}
|
|
resolve(res);
|
|
});
|
|
});
|
|
this.queue.push(p);
|
|
return Promise.resolve(true);
|
|
}
|
|
|
|
_resizeWindow(driver) {
|
|
return driver
|
|
.manage()
|
|
.window()
|
|
.setSize(this.width, this.height);
|
|
}
|
|
|
|
async _takeScreenshot(driver, options) {
|
|
const capabilities = await driver.getCapabilities();
|
|
const png = await driver.takeScreenshot();
|
|
const url = await driver.getCurrentUrl();
|
|
|
|
return Promise.resolve({
|
|
app_id: this.appId,
|
|
group_id: this.groupId,
|
|
description: options.name,
|
|
spec_index: options.specIndex,
|
|
total_specs: this.totalSpecs,
|
|
test_id: this.testId,
|
|
url: url,
|
|
png_base64: png,
|
|
height: this.height,
|
|
width: this.width,
|
|
platform_count: this.platformCount,
|
|
platform_id: this.platformId,
|
|
platform_index: this.platformIndex,
|
|
browser: capabilities.get('browserName'),
|
|
platform: capabilities.get('platform'),
|
|
version: capabilities.get('version'),
|
|
access_key: this.accessKey
|
|
});
|
|
}
|
|
}
|
|
|
|
module.exports = Snapshot;
|