提交 794ef1b6 编写于 作者: dcloud_wdl's avatar dcloud_wdl

合并 alpha分支的test.js

上级 fd58d9f1
// 自动化测试
const path = require('path');
const path = require("path");
const fs = require("fs");
const {
configureToMatchImageSnapshot
configureToMatchImageSnapshot
} = require('jest-image-snapshot');
const hbuilderx_version = process.env.HX_Version
const uniTestPlatformInfo = process.env.uniTestPlatformInfo ? process.env.uniTestPlatformInfo.replace(/\s/g,'_') : ''
const folderName = `__image_snapshots__/${hbuilderx_version}/__${uniTestPlatformInfo}__`
let environment = 'official'
if(hbuilderx_version.includes('dev')){
environment = 'dev'
}else if(hbuilderx_version.includes('alpha')){
environment = 'alpha'
}
const baseFolderName = `__image_snapshots__/base/${environment}/__${uniTestPlatformInfo}__`
let saveImageSnapshotDir = process.env.saveImageSnapshotDir || path.join(__dirname, '__snapshot__');
expect.extend({
toMatchImageSnapshot: configureToMatchImageSnapshot({
customSnapshotIdentifier(args) {
return args.currentTestName.replace(/\//g, '-').replace(' ', '-');
},
customSnapshotsDir: path.join(__dirname, baseFolderName),
customDiffDir: path.join(__dirname, `${folderName}/`, 'diff'),
}),
toMatchImageSnapshot: configureToMatchImageSnapshot({
customSnapshotIdentifier(args) {
return args.currentTestName.replace(/\//g, "-").replace(" ", "-");
},
customSnapshotsDir: process.env.saveImageSnapshotDir,
customDiffDir: path.join(saveImageSnapshotDir, "diff"),
}),
toSaveSnapshot,
toSaveImageSnapshot,
});
const testCaseToSnapshotFilePath =
process.env.testCaseToSnapshotFilePath || "./testCaseToSnapshotFilePath.json";
if (!fs.existsSync(testCaseToSnapshotFilePath)) {
fs.writeFileSync(testCaseToSnapshotFilePath, "{}");
}
function writeTestCaseToSnapshotFile(testCaseName, snapshotFilePath) {
const data = JSON.parse(fs.readFileSync(testCaseToSnapshotFilePath));
if (testCaseName.includes(__dirname)) {
testCaseName = testCaseName.substring(`${__dirname}`.length);
if (testCaseName[0] == '/' || testCaseName[0] == '\\') {
testCaseName = testCaseName.substring(1);
};
};
if (!data[testCaseName]) {
data[testCaseName] = [snapshotFilePath];
} else {
data[testCaseName].push(snapshotFilePath);
}
fs.writeFileSync(testCaseToSnapshotFilePath, JSON.stringify(data, null, 2));
}
function toSaveSnapshot(received, {
customSnapshotsDir,
fileName
} = {}) {
const {
snapshotState: {
_rootDir
},
testPath,
currentTestName,
} = this;
const SNAPSHOTS_DIR = "__file_snapshots__";
const snapshotDir =
process.env.saveSnapshotDir ||
createSnapshotDir({
customSnapshotsDir,
testPath,
SNAPSHOTS_DIR,
});
const _fileName = createFileName({
fileName,
testPath,
currentTestName,
});
const filePath = path.join(snapshotDir, _fileName);
let message = () => `${currentTestName} toSaveSnapshot success`;
let pass = true;
try {
checkSnapshotDir(path.dirname(filePath));
fs.writeFileSync(filePath, received);
writeTestCaseToSnapshotFile(testPath.replace(`${_rootDir}/`, ""), filePath);
} catch (e) {
console.log("toSaveSnapshot fail", e);
message = () => e.message;
pass = false;
}
return {
message,
pass,
};
}
function toSaveImageSnapshot(
received, {
customSnapshotsDir,
customSnapshotIdentifier
} = {}
) {
const {
snapshotState: {
_rootDir
},
testPath,
currentTestName,
} = this;
const SNAPSHOTS_DIR = "__image_snapshots__";
const snapshotDir =
process.env.saveImageSnapshotDir ||
createSnapshotDir({
customSnapshotsDir,
testPath,
SNAPSHOTS_DIR,
});
const _fileName = createFileName({
fileName: customSnapshotIdentifier ? `${customSnapshotIdentifier()}.png` : "",
testPath,
currentTestName,
fileType: "png",
});
const filePath = path.join(snapshotDir, _fileName);
let message = () => `${currentTestName} toSaveImageSnapshot success`;
let pass = true;
try {
checkSnapshotDir(path.dirname(filePath));
fs.writeFileSync(filePath, Buffer.from(received, "base64"));
writeTestCaseToSnapshotFile(testPath.replace(`${_rootDir}/`, ""), filePath);
} catch (e) {
console.log("toSaveImageSnapshot fail", e);
message = () => e.message;
pass = false;
}
return {
message,
pass,
};
}
function createSnapshotDir({
customSnapshotsDir,
testPath,
SNAPSHOTS_DIR
}) {
return customSnapshotsDir || path.join(path.dirname(testPath), SNAPSHOTS_DIR);
}
function createFileName({
fileName,
testPath,
currentTestName,
fileType
}) {
return (
fileName ||
createSnapshotIdentifier({
testPath,
currentTestName,
fileType,
})
);
}
function createSnapshotIdentifier({
testPath,
currentTestName,
fileType = "txt",
}) {
const snapshotIdentifier = kebabCase(
`${path.basename(testPath)}-${currentTestName}`
);
const counter = timesCalled.get(`${snapshotIdentifier}-${fileType}`) || 1;
timesCalled.set(`${snapshotIdentifier}-${fileType}`, counter + 1);
return `${snapshotIdentifier}-${counter}.${fileType}`;
}
function kebabCase(str) {
return str
.replaceAll(/([a-z])([A-Z])/g, "$1-$2")
.replaceAll(/\s+/g, "-")
.replaceAll(/_+/g, "-")
.replaceAll(/\/+/g, "-")
.replaceAll(/\.+/g, "-")
.toLowerCase();
}
function checkSnapshotDir(snapshotDir) {
if (!fs.existsSync(snapshotDir)) {
fs.mkdirSync(snapshotDir, {
recursive: true,
});
}
}
const timesCalled = new Map();
// 自动化测试
// 自动化测试
module.exports = {
testTimeout: 30000,
reporters: ['default'],
......@@ -6,6 +6,12 @@ module.exports = {
moduleFileExtensions: ['js', 'json'],
rootDir: __dirname,
testMatch: ["<rootDir>/pages/**/*test.[jt]s?(x)"],
testPathIgnorePatterns: ['/node_modules/'],
testPathIgnorePatterns: [
'/node_modules/',
'<rootDir>/pages/API/download-file/download-file.test.js',
'<rootDir>/pages/API/upload-file/upload-file.test.js',
'<rootDir>/pages/API/get-battery-info/get-battery-info.test.js',
'<rootDir>/pages/webview-screenshot-comparison/webview-screenshot-comparison.test.js'
],
setupFilesAfterEnv: ['<rootDir>/jest-setup.js'],
}
......@@ -3,7 +3,7 @@
describe('API-loading', () => {
let page;
const isAndroid = process.env.UNI_OS_NAME === "android";
const isApp = process.env.UNI_OS_NAME === "android" || process.env.UNI_OS_NAME === "ios";
beforeAll(async () => {
page = await program.reLaunch('/pages/API/action-sheet/action-sheet')
......@@ -12,13 +12,13 @@ describe('API-loading', () => {
it("onload-action-sheet-test", async () => {
if (isAndroid) {
if (isApp) {
await page.waitFor(500);
const res = await page.callMethod('jest_getWindowInfo')
const windowHeight = res.windowHeight * res.pixelRatio;
const windowWidth = res.windowWidth * res.pixelRatio;
const image = await program.screenshot({
adb: true,
deviceShot: true,
area: {
x: 0,
y: 200,
......@@ -27,13 +27,13 @@ describe('API-loading', () => {
},
});
expect(image).toMatchImageSnapshot();
expect(image).toSaveImageSnapshot();
}else{
const image = await program.screenshot({
adb: true,
deviceShot: true,
fullPage: true
});
expect(image).toMatchImageSnapshot()
expect(image).toSaveImageSnapshot()
}
})
......@@ -57,9 +57,9 @@ describe('API-loading', () => {
await btnToastDurationButton.tap()
await page.waitFor(500);
if (isAndroid) {
if (isApp) {
const image = await program.screenshot({
adb: true,
deviceShot: true,
area: {
x: 0,
y: 200,
......@@ -67,13 +67,13 @@ describe('API-loading', () => {
width:windowWidth
},
});
expect(image).toMatchImageSnapshot();
expect(image).toSaveImageSnapshot();
}else{
const image = await program.screenshot({
adb: true,
deviceShot: true,
fullPage: true
});
expect(image).toMatchImageSnapshot()
expect(image).toSaveImageSnapshot()
}
......@@ -99,9 +99,9 @@ describe('API-loading', () => {
await btnToastDurationButton.tap()
await page.waitFor(500);
if (isAndroid) {
if (isApp) {
const image = await program.screenshot({
adb: true,
deviceShot: true,
area: {
x: 0,
y: 200,
......@@ -109,13 +109,13 @@ describe('API-loading', () => {
width:windowWidth
},
});
expect(image).toMatchImageSnapshot();
expect(image).toSaveImageSnapshot();
}else{
const image = await program.screenshot({
adb: true,
deviceShot: true,
fullPage: true
});
expect(image).toMatchImageSnapshot()
expect(image).toSaveImageSnapshot()
}
......@@ -140,9 +140,9 @@ describe('API-loading', () => {
await btnToastDurationButton.tap()
await page.waitFor(500);
if (isAndroid) {
if (isApp) {
const image = await program.screenshot({
adb: true,
deviceShot: true,
area: {
x: 0,
y: 200,
......@@ -150,13 +150,13 @@ describe('API-loading', () => {
width:windowWidth
},
});
expect(image).toMatchImageSnapshot();
expect(image).toSaveImageSnapshot();
}else{
const image = await program.screenshot({
adb: true,
deviceShot: true,
fullPage: true
});
expect(image).toMatchImageSnapshot()
expect(image).toSaveImageSnapshot()
}
......@@ -181,9 +181,9 @@ describe('API-loading', () => {
await btnToastDurationButton.tap()
await page.waitFor(500);
if (isAndroid) {
if (isApp) {
const image = await program.screenshot({
adb: true,
deviceShot: true,
area: {
x: 0,
y: 200,
......@@ -191,13 +191,13 @@ describe('API-loading', () => {
width:windowWidth
},
});
expect(image).toMatchImageSnapshot();
expect(image).toSaveImageSnapshot();
}else{
const image = await program.screenshot({
adb: true,
deviceShot: true,
fullPage: true
});
expect(image).toMatchImageSnapshot()
expect(image).toSaveImageSnapshot()
}
})
......@@ -222,9 +222,9 @@ describe('API-loading', () => {
await btnToastDurationButton.tap()
await page.waitFor(500);
if (isAndroid) {
if (isApp) {
const image = await program.screenshot({
adb: true,
deviceShot: true,
area: {
x: 0,
y: 200,
......@@ -232,13 +232,13 @@ describe('API-loading', () => {
width:windowWidth
},
});
expect(image).toMatchImageSnapshot();
expect(image).toSaveImageSnapshot();
}else{
const image = await program.screenshot({
adb: true,
deviceShot: true,
fullPage: true
});
expect(image).toMatchImageSnapshot()
expect(image).toSaveImageSnapshot()
}
......@@ -266,9 +266,9 @@ describe('API-loading', () => {
await btnToastDurationButton.tap()
await page.waitFor(500);
if (isAndroid) {
if (isApp) {
const image = await program.screenshot({
adb: true,
deviceShot: true,
area: {
x: 0,
y: 200,
......@@ -276,13 +276,13 @@ describe('API-loading', () => {
width:windowWidth
},
});
expect(image).toMatchImageSnapshot();
expect(image).toSaveImageSnapshot();
}else{
const image = await program.screenshot({
adb: true,
deviceShot: true,
fullPage: true
});
expect(image).toMatchImageSnapshot()
expect(image).toSaveImageSnapshot()
}
......@@ -307,9 +307,9 @@ describe('API-loading', () => {
await btnToastDurationButton.tap()
await page.waitFor(500);
if (isAndroid) {
if (isApp) {
const image = await program.screenshot({
adb: true,
deviceShot: true,
area: {
x: 0,
y: 200,
......@@ -317,13 +317,13 @@ describe('API-loading', () => {
width:windowWidth
},
});
expect(image).toMatchImageSnapshot();
expect(image).toSaveImageSnapshot();
}else{
const image = await program.screenshot({
adb: true,
deviceShot: true,
fullPage: true
});
expect(image).toMatchImageSnapshot()
expect(image).toSaveImageSnapshot()
}
......@@ -348,9 +348,9 @@ describe('API-loading', () => {
await btnToastDurationButton.tap()
await page.waitFor(500);
if (isAndroid) {
if (isApp) {
const image = await program.screenshot({
adb: true,
deviceShot: true,
area: {
x: 0,
y: 200,
......@@ -358,13 +358,13 @@ describe('API-loading', () => {
width:windowWidth
},
});
expect(image).toMatchImageSnapshot();
expect(image).toSaveImageSnapshot();
}else{
const image = await program.screenshot({
adb: true,
deviceShot: true,
fullPage: true
});
expect(image).toMatchImageSnapshot()
expect(image).toSaveImageSnapshot()
}
})
......@@ -389,9 +389,9 @@ describe('API-loading', () => {
await btnToastDurationButton.tap()
await page.waitFor(500);
if (isAndroid) {
if (isApp) {
const image = await program.screenshot({
adb: true,
deviceShot: true,
area: {
x: 0,
y: 200,
......@@ -399,13 +399,13 @@ describe('API-loading', () => {
width:windowWidth
},
});
expect(image).toMatchImageSnapshot();
expect(image).toSaveImageSnapshot();
}else{
const image = await program.screenshot({
adb: true,
deviceShot: true,
fullPage: true
});
expect(image).toMatchImageSnapshot()
expect(image).toSaveImageSnapshot()
}
......@@ -431,9 +431,9 @@ describe('API-loading', () => {
await btnToastDurationButton.tap()
await page.waitFor(500);
if (isAndroid) {
if (isApp) {
const image = await program.screenshot({
adb: true,
deviceShot: true,
area: {
x: 0,
y: 200,
......@@ -441,13 +441,13 @@ describe('API-loading', () => {
width:windowWidth
},
});
expect(image).toMatchImageSnapshot();
expect(image).toSaveImageSnapshot();
}else{
const image = await program.screenshot({
adb: true,
deviceShot: true,
fullPage: true
});
expect(image).toMatchImageSnapshot()
expect(image).toSaveImageSnapshot()
}
......@@ -472,9 +472,9 @@ describe('API-loading', () => {
await btnToastDurationButton.tap()
await page.waitFor(500);
if (isAndroid) {
if (isApp) {
const image = await program.screenshot({
adb: true,
deviceShot: true,
area: {
x: 0,
y: 200,
......@@ -482,13 +482,13 @@ describe('API-loading', () => {
width:windowWidth
},
});
expect(image).toMatchImageSnapshot();
expect(image).toSaveImageSnapshot();
}else{
const image = await program.screenshot({
adb: true,
deviceShot: true,
fullPage: true
});
expect(image).toMatchImageSnapshot()
expect(image).toSaveImageSnapshot()
}
......@@ -513,9 +513,9 @@ describe('API-loading', () => {
await btnToastDurationButton.tap()
await page.waitFor(500);
if (isAndroid) {
if (isApp) {
const image = await program.screenshot({
adb: true,
deviceShot: true,
area: {
x: 0,
y: 200,
......@@ -523,13 +523,13 @@ describe('API-loading', () => {
width:windowWidth
},
});
expect(image).toMatchImageSnapshot();
expect(image).toSaveImageSnapshot();
}else{
const image = await program.screenshot({
adb: true,
deviceShot: true,
fullPage: true
});
expect(image).toMatchImageSnapshot()
expect(image).toSaveImageSnapshot()
}
})
......
......@@ -23,7 +23,7 @@ describe('ExtApi-DownloadFile', () => {
});
let shouldTestCookie = false
if (process.env.uniTestPlatformInfo.startsWith('android')) {
if (process.env.uniTestPlatformInfo.startsWith('android') && !process.env.UNI_AUTOMATOR_APP_WEBVIEW) {
let version = process.env.uniTestPlatformInfo
version = parseInt(version.split(" ")[1])
shouldTestCookie = version > 9
......@@ -47,4 +47,4 @@ describe('ExtApi-DownloadFile', () => {
res = await page.data('jest_result');
expect(res).toBe(true)
});
});
});
......@@ -2,7 +2,7 @@ const PAGE_PATH = "/pages/API/element-takesnapshot/element-takesnapshot";
describe("element-takesnapshot", () => {
if (process.env.uniTestPlatformInfo.indexOf('web') > -1) {
if (process.env.uniTestPlatformInfo.indexOf('web') > -1 || process.env.UNI_AUTOMATOR_APP_WEBVIEW == 'true') {
it('dummyTest', () => {
expect(1).toBe(1)
})
......
const PAGE_PATH = '/pages/API/get-app-authorize-setting/get-app-authorize-setting'
describe('ExtApi-GetAppAuthorizeSetting', () => {
if (process.env.uniTestPlatformInfo.indexOf('web') > -1) {
describe('ExtApi-GetAppAuthorizeSetting', () => {
if (process.env.uniTestPlatformInfo.indexOf('web') > -1 || process.env.UNI_AUTOMATOR_APP_WEBVIEW == 'true') {
it('dummyTest', () => {
expect(1).toBe(1)
})
......
......@@ -6,14 +6,11 @@ describe('ExtApi-GetAppBaseInfo', () => {
let res;
const stringProperties = [
'appId', 'appName', 'appVersion', 'appVersionCode', 'appLanguage',
'language', 'uniCompileVersion', 'uniPlatform', 'uniRuntimeVersion',
'language', 'uniCompilerVersion', 'uniPlatform', 'uniRuntimeVersion',
]
const numberProperties = [
'uniCompileVersionCode', 'uniRuntimeVersionCode'
]
if (process.env.uniTestPlatformInfo.indexOf('web') === -1) {
stringProperties.push('version')
}
'uniCompilerVersionCode', 'uniRuntimeVersionCode'
]
beforeAll(async () => {
page = await program.reLaunch(PAGE_PATH)
await page.waitFor(600);
......
......@@ -2,7 +2,7 @@ const PAGE_PATH =
"/pages/API/get-element-by-id/get-element-by-id-multiple-root-node";
let page;
describe("getElementByIdForMultipleRootNode", () => {
describe("getElementByIdForMultipleRootNode", () => {
beforeAll(async () => {
page = await program.reLaunch(PAGE_PATH);
await page.waitFor('view');
......@@ -16,7 +16,7 @@ describe("getElementByIdForMultipleRootNode", () => {
await page.callMethod("changeTextColor");
await page.callMethod("changeViewStyle");
await page.waitFor(500);
const image = await program.screenshot();
expect(image).toMatchImageSnapshot();
const image = await program.screenshot({fullPage: true});
expect(image).toSaveImageSnapshot();
});
});
});
......@@ -15,7 +15,7 @@ describe("getElementById", () => {
await page.callMethod("changeTextColor");
await page.callMethod("changeViewStyle");
await page.waitFor(500);
const image = await program.screenshot();
expect(image).toMatchImageSnapshot();
const image = await program.screenshot({fullPage: true});
expect(image).toSaveImageSnapshot();
});
});
......@@ -2,7 +2,7 @@ const PAGE_PATH = '/pages/API/get-file-system-manager/get-file-system-manager'
describe('ExtApi-FileManagerTest', () => {
if (process.env.uniTestPlatformInfo.indexOf('web') > -1) {
if (process.env.uniTestPlatformInfo.indexOf('web') > -1 || process.env.UNI_AUTOMATOR_APP_WEBVIEW == 'true') {
it('dummyTest', () => {
expect(1).toBe(1)
})
......@@ -116,9 +116,11 @@ describe('ExtApi-FileManagerTest', () => {
await btnReadDirButton.tap()
await isDone()
fileListComplete = await getData('fileListComplete')
expect(JSON.stringify(fileListComplete)).toEqual("[\"b\",\"1.txt\"]")
fileListComplete.sort()
expect(JSON.stringify(fileListComplete)).toEqual("[\"1.txt\",\"b\"]")
fileListSuccess = await getData('fileListSuccess')
expect(JSON.stringify(fileListSuccess)).toEqual("[\"b\",\"1.txt\"]")
fileListSuccess.sort()
expect(JSON.stringify(fileListSuccess)).toEqual("[\"1.txt\",\"b\"]")
// 获取和对比 文件内容
const btnReadFileButton = await page.$('#btn-read-file')
await btnReadFileButton.tap()
......@@ -176,9 +178,11 @@ describe('ExtApi-FileManagerTest', () => {
// 1.txt 2.txt 两个文件都存在
fileListComplete = await getData('fileListComplete')
expect(JSON.stringify(fileListComplete)).toEqual("[\"b\",\"1.txt\",\"2.txt\"]")
fileListComplete.sort()
expect(JSON.stringify(fileListComplete)).toEqual("[\"1.txt\",\"2.txt\",\"b\"]")
fileListSuccess = await getData('fileListSuccess')
expect(JSON.stringify(fileListSuccess)).toEqual("[\"b\",\"1.txt\",\"2.txt\"]")
fileListSuccess.sort()
expect(JSON.stringify(fileListSuccess)).toEqual("[\"1.txt\",\"2.txt\",\"b\"]")
// 测试 rename
await page.setData({
......@@ -195,10 +199,11 @@ describe('ExtApi-FileManagerTest', () => {
// 1.txt 3.txt 两个文件都存在
fileListComplete = await getData('fileListComplete')
expect(JSON.stringify(fileListComplete)).toEqual("[\"b\",\"1.txt\",\"3.txt\"]")
fileListComplete.sort()
expect(JSON.stringify(fileListComplete)).toEqual("[\"1.txt\",\"3.txt\",\"b\"]")
fileListSuccess = await getData('fileListSuccess')
expect(JSON.stringify(fileListSuccess)).toEqual("[\"b\",\"1.txt\",\"3.txt\"]")
fileListSuccess.sort()
expect(JSON.stringify(fileListSuccess)).toEqual("[\"1.txt\",\"3.txt\",\"b\"]")
});
it('TEMP_PATH test', async () => {
......@@ -281,8 +286,10 @@ describe('ExtApi-FileManagerTest', () => {
// 期望通过 recursive = true的 文件夹删除,得到一个空的 /a 目录
fileListComplete = await getData('fileListComplete')
fileListComplete.sort()
expect(JSON.stringify(fileListComplete)).toEqual("[\"b\",\"" + testDirName + "\"]")
fileListSuccess = await getData('fileListSuccess')
fileListSuccess.sort()
expect(JSON.stringify(fileListSuccess)).toEqual("[\"b\",\"" + testDirName + "\"]")
/**
......@@ -406,13 +413,14 @@ describe('ExtApi-FileManagerTest', () => {
await isDone()
fileListComplete = await getData('fileListComplete')
fileListComplete.sort()
expect(JSON.stringify(fileListComplete)).toEqual("[\"b\",\"" + testDirName + "\",\"提前创建的目录\"]")
fileListSuccess = await getData('fileListSuccess')
fileListSuccess.sort()
expect(JSON.stringify(fileListSuccess)).toEqual("[\"b\",\"" + testDirName + "\",\"提前创建的目录\"]")
await page.setData({
copyFromFile:"a/" + testDirName + "/中文路径/张三/name/中文文件.mock",
copyToFile:"a/提前创建的目录/4.txt"
})
......@@ -735,6 +743,7 @@ describe('ExtApi-FileManagerTest', () => {
recursiveVal: true,
copyToBasePath:globalRootPath,
basePath: globalRootPath,
globalTempPath:globalRootPath,
rmDirFile:'a',
mkdirFile:'a',
unlinkFile:'a/1.txt',
......@@ -800,7 +809,7 @@ describe('ExtApi-FileManagerTest', () => {
// 读取单个文件信息
let statsRet = await getData('statsRet')
expect(statsRet.length).toEqual(1)
expect(statsRet[0].path).toMatch(new RegExp('/storage/\\S+/Android/data/io.dcloud.uniappx/a/1.txt'))
expect(statsRet[0].path).toMatch(new RegExp('.*/a/1.txt$'))
expect(statsRet[0].stats.size).toEqual(69)
/**
......@@ -828,7 +837,7 @@ describe('ExtApi-FileManagerTest', () => {
await page.setData({
// asset 只能正式版测试,这里只能模拟返回路径
basePath:'',
copyFromFile:'file:///android_asset/uni-uts/uni-prompt/toast_error.png',
copyFromFile:'static/test-image/logo.ico',
copyToFile:'a/m/3.txt',
})
const btnCopyFileButton = await page.$('#btn-copy-file')
......@@ -847,16 +856,25 @@ describe('ExtApi-FileManagerTest', () => {
// 读取全部文件信息
statsRet = await getData('statsRet')
statsRet.sort(function(a, b){
if (a.path > b.path){
return 1
} else if (a.path < b.path){
return -1
}
return 0
})
console.log(statsRet)
expect(statsRet.length).toEqual(5)
expect(statsRet[0].path).toMatch(new RegExp('/storage/\\S+/Android/data/io.dcloud.uniappx/a'))
expect(statsRet[0].stats.size).toEqual(0)
expect(statsRet[0].path).toMatch(new RegExp('.*/a$'))
// expect(statsRet[0].stats.size).toEqual(0)
expect(statsRet[2].path).toMatch(new RegExp('/storage/\\S+/Android/data/io.dcloud.uniappx/a/2.txt'))
expect(statsRet[2].path).toMatch(new RegExp('.*/a/2.txt$'))
expect(statsRet[2].stats.size).toEqual(10)
expect(statsRet[4].path).toMatch(new RegExp('/storage/\\S+/Android/data/io.dcloud.uniappx/a/m/3.txt'))
expect(statsRet[4].stats.size).toEqual(5842)
expect(statsRet[4].path).toMatch(new RegExp('.*/a/m/3.txt$'))
expect(statsRet[4].stats.size).toEqual(156406)
// 清理文件,避免影响其他测试用例
......
......@@ -7,20 +7,15 @@ describe('ExtApi-GetSystemInfo', () => {
const stringProperties = [
'appId', 'appLanguage', 'appName', 'appVersion', 'appVersionCode',
'brand', 'deviceId', 'deviceBrand', 'deviceModel', 'deviceType', 'language',
'model', 'osName', 'osVersion', 'osLanguage', 'platform', 'system', 'ua', 'uniCompileVersion',
'model', 'osName', 'osVersion', 'osLanguage', 'platform', 'system', 'ua', 'uniCompilerVersion',
'uniPlatform', 'uniRuntimeVersion', 'romName', 'romVersion',
]
const numberProperties = [
'osAndroidAPILevel', 'devicePixelRatio', 'pixelRatio', 'screenWidth', 'screenHeight', 'statusBarHeight',
'windowWidth',
'windowHeight', 'windowTop', 'windowBottom', 'screenTop',
'uniCompileVersionCode', 'uniRuntimeVersionCode'
]
if (process.env.uniTestPlatformInfo.indexOf('web') === -1) {
stringProperties.push('version')
}
'uniCompilerVersionCode', 'uniRuntimeVersionCode'
]
beforeAll(async () => {
page = await program.reLaunch(PAGE_PATH)
......
const PAGE_PATH = '/pages/API/get-system-setting/get-system-setting'
describe('ExtApi-GetSystemSetting', () => {
if (process.env.uniTestPlatformInfo.indexOf('web') > -1) {
if (process.env.uniTestPlatformInfo.indexOf('web') > -1 || process.env.UNI_AUTOMATOR_APP_WEBVIEW == 'true') {
it('web', () => {
expect(1).toBe(1)
})
......@@ -18,10 +18,10 @@ describe('ExtApi-GetSystemSetting', () => {
it('Check GetSystemSetting', async () => {
for (const key in res) {
const value = res[key];
if (res['bluetoothEnabled'] == undefined) {
expect(res['bluetoothError']).not.toBe("")
} else {
expect(res['bluetoothError'] == undefined).toBe(true)
if (res['bluetoothEnabled'] == undefined || res['bluetoothEnabled'] === false) {
expect(res['bluetoothError']).not.toBe("")
} else {
expect(res['bluetoothError'] == undefined).toBe(true)
}
if (res['wifiEnabled'] == undefined) {
......
......@@ -7,13 +7,13 @@ describe("loadFontFace", () => {
await page.waitFor(4000);
});
it("parent screenshot", async () => {
const image = await program.screenshot();
expect(image).toMatchImageSnapshot();
const image = await program.screenshot({fullPage: true});
expect(image).toSaveImageSnapshot();
});
it("child screenshot", async () => {
const page = await program.navigateTo(CHILD_PAGE_PATH);
await page.waitFor(3000);
const image = await program.screenshot();
expect(image).toMatchImageSnapshot();
const image = await program.screenshot({fullPage: true});
expect(image).toSaveImageSnapshot();
});
});
......@@ -3,7 +3,7 @@
describe('API-loading', () => {
let page;
const isAndroid = process.env.UNI_OS_NAME === "android";
const isApp = process.env.UNI_OS_NAME === "android" || process.env.UNI_OS_NAME === "ios";
beforeAll(async () => {
page = await program.reLaunch('/pages/API/modal/modal')
......@@ -13,13 +13,14 @@ describe('API-loading', () => {
it("onload-modal-test", async () => {
if (isAndroid) {
if (isApp) {
await page.waitFor(500);
const res = await page.callMethod('jest_getWindowInfo')
const windowHeight = res.windowHeight * res.pixelRatio;
const windowWidth = res.windowWidth * res.pixelRatio;
const image = await program.screenshot({
adb: true,
deviceShot: true,
area: {
x: 0,
y: 200,
......@@ -27,13 +28,13 @@ describe('API-loading', () => {
width:windowWidth
},
});
expect(image).toMatchImageSnapshot();
expect(image).toSaveImageSnapshot();
}else{
const image = await program.screenshot({
adb: true,
deviceShot: true,
fullPage: true
});
expect(image).toMatchImageSnapshot()
expect(image).toSaveImageSnapshot()
}
})
......@@ -53,13 +54,13 @@ describe('API-loading', () => {
await btnModalButton.tap()
await page.waitFor(500);
if (isAndroid) {
if (isApp) {
const res = await page.callMethod('jest_getWindowInfo')
const windowHeight = res.windowHeight * res.pixelRatio;
const windowWidth = res.windowWidth * res.pixelRatio;
const image = await program.screenshot({
adb: true,
deviceShot: true,
area: {
x: 0,
y: 200,
......@@ -67,13 +68,13 @@ describe('API-loading', () => {
width:windowWidth
},
});
expect(image).toMatchImageSnapshot();
expect(image).toSaveImageSnapshot();
}else{
const image = await program.screenshot({
adb: true,
deviceShot: true,
fullPage: true
});
expect(image).toMatchImageSnapshot()
expect(image).toSaveImageSnapshot()
}
})
......@@ -94,13 +95,13 @@ describe('API-loading', () => {
await btnModalButton.tap()
await page.waitFor(500);
if (isAndroid) {
if (isApp) {
const res = await page.callMethod('jest_getWindowInfo')
const windowHeight = res.windowHeight * res.pixelRatio;
const windowWidth = res.windowWidth * res.pixelRatio;
const image = await program.screenshot({
adb: true,
deviceShot: true,
area: {
x: 0,
y: 200,
......@@ -108,13 +109,13 @@ describe('API-loading', () => {
width:windowWidth
},
});
expect(image).toMatchImageSnapshot();
expect(image).toSaveImageSnapshot();
}else{
const image = await program.screenshot({
adb: true,
deviceShot: true,
fullPage: true
});
expect(image).toMatchImageSnapshot()
expect(image).toSaveImageSnapshot()
}
})
......@@ -135,13 +136,13 @@ describe('API-loading', () => {
await btnModalButton.tap()
await page.waitFor(500);
if (isAndroid) {
if (isApp) {
const res = await page.callMethod('jest_getWindowInfo')
const windowHeight = res.windowHeight * res.pixelRatio;
const windowWidth = res.windowWidth * res.pixelRatio;
const image = await program.screenshot({
adb: true,
deviceShot: true,
area: {
x: 0,
y: 200,
......@@ -149,13 +150,13 @@ describe('API-loading', () => {
width:windowWidth
},
});
expect(image).toMatchImageSnapshot();
expect(image).toSaveImageSnapshot();
}else{
const image = await program.screenshot({
adb: true,
deviceShot: true,
fullPage: true
});
expect(image).toMatchImageSnapshot()
expect(image).toSaveImageSnapshot()
}
})
......@@ -176,13 +177,13 @@ describe('API-loading', () => {
await btnModalButton.tap()
await page.waitFor(500);
if (isAndroid) {
if (isApp) {
const res = await page.callMethod('jest_getWindowInfo')
const windowHeight = res.windowHeight * res.pixelRatio;
const windowWidth = res.windowWidth * res.pixelRatio;
const image = await program.screenshot({
adb: true,
deviceShot: true,
area: {
x: 0,
y: 200,
......@@ -190,13 +191,13 @@ describe('API-loading', () => {
width:windowWidth
},
});
expect(image).toMatchImageSnapshot();
expect(image).toSaveImageSnapshot();
}else{
const image = await program.screenshot({
adb: true,
deviceShot: true,
fullPage: true
});
expect(image).toMatchImageSnapshot()
expect(image).toSaveImageSnapshot()
}
})
......@@ -217,12 +218,12 @@ describe('API-loading', () => {
await btnModalButton.tap()
await page.waitFor(500);
if (isAndroid) {
if (isApp) {
const res = await page.callMethod('jest_getWindowInfo')
const windowHeight = res.windowHeight * res.pixelRatio;
const windowWidth = res.windowWidth * res.pixelRatio;
const image = await program.screenshot({
adb: true,
deviceShot: true,
area: {
x: 0,
y: 200,
......@@ -230,13 +231,13 @@ describe('API-loading', () => {
width:windowWidth
},
});
expect(image).toMatchImageSnapshot();
expect(image).toSaveImageSnapshot();
}else{
const image = await program.screenshot({
adb: true,
deviceShot: true,
fullPage: true
});
expect(image).toMatchImageSnapshot()
expect(image).toSaveImageSnapshot()
}
})
......@@ -257,12 +258,12 @@ describe('API-loading', () => {
await btnModalButton.tap()
await page.waitFor(500);
if (isAndroid) {
if (isApp) {
const res = await page.callMethod('jest_getWindowInfo')
const windowHeight = res.windowHeight * res.pixelRatio;
const windowWidth = res.windowWidth * res.pixelRatio;
const image = await program.screenshot({
adb: true,
deviceShot: true,
area: {
x: 0,
y: 200,
......@@ -270,13 +271,13 @@ describe('API-loading', () => {
width:windowWidth
},
});
expect(image).toMatchImageSnapshot();
expect(image).toSaveImageSnapshot();
}else{
const image = await program.screenshot({
adb: true,
deviceShot: true,
fullPage: true
});
expect(image).toMatchImageSnapshot()
expect(image).toSaveImageSnapshot()
}
})
......@@ -297,12 +298,12 @@ describe('API-loading', () => {
await btnModalButton.tap()
await page.waitFor(500);
if (isAndroid) {
if (isApp) {
const res = await page.callMethod('jest_getWindowInfo')
const windowHeight = res.windowHeight * res.pixelRatio;
const windowWidth = res.windowWidth * res.pixelRatio;
const image = await program.screenshot({
adb: true,
deviceShot: true,
area: {
x: 0,
y: 200,
......@@ -310,13 +311,13 @@ describe('API-loading', () => {
width:windowWidth
},
});
expect(image).toMatchImageSnapshot();
expect(image).toSaveImageSnapshot();
}else{
const image = await program.screenshot({
adb: true,
deviceShot: true,
fullPage: true
});
expect(image).toMatchImageSnapshot()
expect(image).toSaveImageSnapshot()
}
})
......@@ -337,12 +338,12 @@ describe('API-loading', () => {
await btnModalButton.tap()
await page.waitFor(500);
if (isAndroid) {
if (isApp) {
const res = await page.callMethod('jest_getWindowInfo')
const windowHeight = res.windowHeight * res.pixelRatio;
const windowWidth = res.windowWidth * res.pixelRatio;
const image = await program.screenshot({
adb: true,
deviceShot: true,
area: {
x: 0,
y: 200,
......@@ -350,13 +351,13 @@ describe('API-loading', () => {
width:windowWidth
},
});
expect(image).toMatchImageSnapshot();
expect(image).toSaveImageSnapshot();
}else{
const image = await program.screenshot({
adb: true,
deviceShot: true,
fullPage: true
});
expect(image).toMatchImageSnapshot()
expect(image).toSaveImageSnapshot()
}
})
......@@ -377,13 +378,13 @@ describe('API-loading', () => {
await btnModalButton.tap()
await page.waitFor(500);
if (isAndroid) {
if (isApp) {
const res = await page.callMethod('jest_getWindowInfo')
const windowHeight = res.windowHeight * res.pixelRatio;
const windowWidth = res.windowWidth * res.pixelRatio;
const image = await program.screenshot({
adb: true,
deviceShot: true,
area: {
x: 0,
y: 200,
......@@ -391,13 +392,13 @@ describe('API-loading', () => {
width:windowWidth
},
});
expect(image).toMatchImageSnapshot();
expect(image).toSaveImageSnapshot();
}else{
const image = await program.screenshot({
adb: true,
deviceShot: true,
fullPage: true
});
expect(image).toMatchImageSnapshot()
expect(image).toSaveImageSnapshot()
}
})
......@@ -418,13 +419,13 @@ describe('API-loading', () => {
await btnModalButton.tap()
await page.waitFor(500);
if (isAndroid) {
if (isApp) {
const res = await page.callMethod('jest_getWindowInfo')
const windowHeight = res.windowHeight * res.pixelRatio;
const windowWidth = res.windowWidth * res.pixelRatio;
const image = await program.screenshot({
adb: true,
deviceShot: true,
area: {
x: 0,
y: 200,
......@@ -432,13 +433,13 @@ describe('API-loading', () => {
width:windowWidth
},
});
expect(image).toMatchImageSnapshot();
expect(image).toSaveImageSnapshot();
}else{
const image = await program.screenshot({
adb: true,
deviceShot: true,
fullPage: true
});
expect(image).toMatchImageSnapshot()
expect(image).toSaveImageSnapshot()
}
})
......@@ -459,13 +460,13 @@ describe('API-loading', () => {
await btnModalButton.tap()
await page.waitFor(500);
if (isAndroid) {
if (isApp) {
const res = await page.callMethod('jest_getWindowInfo')
const windowHeight = res.windowHeight * res.pixelRatio;
const windowWidth = res.windowWidth * res.pixelRatio;
const image = await program.screenshot({
adb: true,
deviceShot: true,
area: {
x: 0,
y: 200,
......@@ -473,13 +474,13 @@ describe('API-loading', () => {
width:windowWidth
},
});
expect(image).toMatchImageSnapshot();
expect(image).toSaveImageSnapshot();
}else{
const image = await program.screenshot({
adb: true,
deviceShot: true,
fullPage: true
});
expect(image).toMatchImageSnapshot()
expect(image).toSaveImageSnapshot()
}
})
......@@ -500,13 +501,13 @@ describe('API-loading', () => {
await btnModalButton.tap()
await page.waitFor(500);
if (isAndroid) {
if (isApp) {
const res = await page.callMethod('jest_getWindowInfo')
const windowHeight = res.windowHeight * res.pixelRatio;
const windowWidth = res.windowWidth * res.pixelRatio;
const image = await program.screenshot({
adb: true,
deviceShot: true,
area: {
x: 0,
y: 200,
......@@ -514,13 +515,13 @@ describe('API-loading', () => {
width:windowWidth
},
});
expect(image).toMatchImageSnapshot();
expect(image).toSaveImageSnapshot();
}else{
const image = await program.screenshot({
adb: true,
deviceShot: true,
fullPage: true
});
expect(image).toMatchImageSnapshot()
expect(image).toSaveImageSnapshot()
}
})
......@@ -541,13 +542,13 @@ describe('API-loading', () => {
await btnModalButton.tap()
await page.waitFor(500);
if (isAndroid) {
if (isApp) {
const res = await page.callMethod('jest_getWindowInfo')
const windowHeight = res.windowHeight * res.pixelRatio;
const windowWidth = res.windowWidth * res.pixelRatio;
const image = await program.screenshot({
adb: true,
deviceShot: true,
area: {
x: 0,
y: 200,
......@@ -555,13 +556,13 @@ describe('API-loading', () => {
width:windowWidth
},
});
expect(image).toMatchImageSnapshot();
expect(image).toSaveImageSnapshot();
}else{
const image = await program.screenshot({
adb: true,
deviceShot: true,
fullPage: true
});
expect(image).toMatchImageSnapshot()
expect(image).toSaveImageSnapshot()
}
})
......@@ -582,13 +583,13 @@ describe('API-loading', () => {
await btnModalButton.tap()
await page.waitFor(500);
if (isAndroid) {
if (isApp) {
const res = await page.callMethod('jest_getWindowInfo')
const windowHeight = res.windowHeight * res.pixelRatio;
const windowWidth = res.windowWidth * res.pixelRatio;
const image = await program.screenshot({
adb: true,
deviceShot: true,
area: {
x: 0,
y: 200,
......@@ -596,13 +597,13 @@ describe('API-loading', () => {
width:windowWidth
},
});
expect(image).toMatchImageSnapshot();
expect(image).toSaveImageSnapshot();
}else{
const image = await program.screenshot({
adb: true,
deviceShot: true,
fullPage: true
});
expect(image).toMatchImageSnapshot()
expect(image).toSaveImageSnapshot()
}
})
......@@ -624,12 +625,12 @@ describe('API-loading', () => {
await btnModalButton.tap()
await page.waitFor(500);
if (isAndroid) {
if (isApp) {
const res = await page.callMethod('jest_getWindowInfo')
const windowHeight = res.windowHeight * res.pixelRatio;
const windowWidth = res.windowWidth * res.pixelRatio;
const image = await program.screenshot({
adb: true,
deviceShot: true,
area: {
x: 0,
y: 200,
......@@ -637,13 +638,13 @@ describe('API-loading', () => {
width:windowWidth
},
});
expect(image).toMatchImageSnapshot();
expect(image).toSaveImageSnapshot();
}else{
const image = await program.screenshot({
adb: true,
deviceShot: true,
fullPage: true
});
expect(image).toMatchImageSnapshot()
expect(image).toSaveImageSnapshot()
}
})
......@@ -664,13 +665,13 @@ describe('API-loading', () => {
await btnModalButton.tap()
await page.waitFor(500);
if (isAndroid) {
if (isApp) {
const res = await page.callMethod('jest_getWindowInfo')
const windowHeight = res.windowHeight * res.pixelRatio;
const windowWidth = res.windowWidth * res.pixelRatio;
const image = await program.screenshot({
adb: true,
deviceShot: true,
area: {
x: 0,
y: 200,
......@@ -678,13 +679,13 @@ describe('API-loading', () => {
width:windowWidth
},
});
expect(image).toMatchImageSnapshot();
expect(image).toSaveImageSnapshot();
}else{
const image = await program.screenshot({
adb: true,
deviceShot: true,
fullPage: true
});
expect(image).toMatchImageSnapshot()
expect(image).toSaveImageSnapshot()
}
})
......@@ -705,12 +706,12 @@ describe('API-loading', () => {
await btnModalButton.tap()
await page.waitFor(500);
if (isAndroid) {
if (isApp) {
const res = await page.callMethod('jest_getWindowInfo')
const windowHeight = res.windowHeight * res.pixelRatio;
const windowWidth = res.windowWidth * res.pixelRatio;
const image = await program.screenshot({
adb: true,
deviceShot: true,
area: {
x: 0,
y: 200,
......@@ -718,13 +719,13 @@ describe('API-loading', () => {
width:windowWidth
},
});
expect(image).toMatchImageSnapshot();
expect(image).toSaveImageSnapshot();
}else{
const image = await program.screenshot({
adb: true,
deviceShot: true,
fullPage: true
});
expect(image).toMatchImageSnapshot()
expect(image).toSaveImageSnapshot()
}
})
......
......@@ -10,8 +10,8 @@ describe("onLoad", () => {
await page.waitFor('view');
await page.callMethod("navigateToOnLoadWithType", "adjustData");
await page.waitFor(1000);
const image = await program.screenshot();
expect(image).toMatchImageSnapshot();
const image = await program.screenshot({fullPage: true});
expect(image).toSaveImageSnapshot();
});
it("navigateTo", async () => {
page = await program.reLaunch(INTERMEDIATE_PAGE_PATH);
......@@ -22,7 +22,7 @@ describe("onLoad", () => {
expect(page.path).toBe(TARGET_PAGE_PATH.substring(1));
});
it("navigateBack", async () => {
if (process.env.uniTestPlatformInfo.startsWith('android')) {
if (process.env.uniTestPlatformInfo.startsWith('android') && !process.env.UNI_AUTOMATOR_APP_WEBVIEW) {
page = await program.reLaunch(INTERMEDIATE_PAGE_PATH);
await page.waitFor('view');
await page.callMethod("navigateToOnLoadWithType", "navigateBack");
......@@ -61,14 +61,14 @@ describe("onLoad", () => {
await page.callMethod("navigateToOnLoadWithType", "showToast");
await page.waitFor(1000);
const image = await program.screenshot({
adb: true,
deviceShot: true,
area: {
x: 0,
y: 200,
height: 2140,
},
});
expect(image).toMatchImageSnapshot({
expect(image).toSaveImageSnapshot({
failureThreshold: 0.05,
failureThresholdType: "percent",
});
......@@ -79,17 +79,17 @@ describe("onLoad", () => {
await page.callMethod("navigateToOnLoadWithType", "showLoading");
await page.waitFor(1000);
const image = await program.screenshot({
adb: true,
deviceShot: true,
area: {
x: 0,
y: 200,
height: 2140,
},
});
expect(image).toMatchImageSnapshot({
expect(image).toSaveImageSnapshot({
failureThreshold: 0.05,
failureThresholdType: "percent",
});
});
});
it("showModal", async () => {
page = await program.reLaunch(INTERMEDIATE_PAGE_PATH);
......@@ -97,14 +97,14 @@ describe("onLoad", () => {
await page.callMethod("navigateToOnLoadWithType", "showModal");
await page.waitFor(1000);
const image = await program.screenshot({
adb: true,
deviceShot: true,
area: {
x: 0,
y: 200,
height: 2140,
},
});
expect(image).toMatchImageSnapshot({
expect(image).toSaveImageSnapshot({
failureThreshold: 0.05,
failureThresholdType: "percent",
});
......@@ -115,16 +115,16 @@ describe("onLoad", () => {
await page.callMethod("navigateToOnLoadWithType", "showActionSheet");
await page.waitFor(1000);
const image = await program.screenshot({
adb: true,
deviceShot: true,
area: {
x: 0,
y: 200,
height: 2140,
},
});
expect(image).toMatchImageSnapshot({
expect(image).toSaveImageSnapshot({
failureThreshold: 0.05,
failureThresholdType: "percent",
});
});
});
});
......@@ -53,6 +53,11 @@ describe('nodes-info', () => {
expect(nodeInfo2.top > 220).toBe(true)
expect(Math.round(nodeInfo2.width)).toBe(RECT_WIDTH)
expect(Math.round(nodeInfo2.height)).toBe(RECT_HEIGHT)
})
it('get-node-info-child', async () => {
const child = await page.$('.node-child')
const childData = await child.data()
expect(childData.top > 100).toBe(true)
})
// #ifdef APP
......
......@@ -2,11 +2,17 @@ const PAGE_PATH =
"/pages/API/request-payment/request-payment";
describe("payment", () => {
if (process.env.uniTestPlatformInfo.indexOf('web') > -1) {
if (process.env.uniTestPlatformInfo.indexOf('web') > -1 || process.env.UNI_AUTOMATOR_APP_WEBVIEW === 'true') {
it('web', () => {
expect(1).toBe(1)
})
return
}
if (process.env.uniTestPlatformInfo.toLocaleLowerCase().startsWith('ios')) {
it('ios', () => {
expect(1).toBe(1)
})
return
}
beforeAll(async () => {
page = await program.reLaunch(PAGE_PATH)
......
......@@ -86,7 +86,7 @@ describe('ExtApi-Request', () => {
});
let shouldTestCookie = false
if (process.env.uniTestPlatformInfo.startsWith('android')) {
if (process.env.uniTestPlatformInfo.startsWith('android') && !process.env.UNI_AUTOMATOR_APP_WEBVIEW) {
let version = process.env.uniTestPlatformInfo
version = parseInt(version.split(" ")[1])
shouldTestCookie = version > 9
......@@ -108,4 +108,10 @@ describe('ExtApi-Request', () => {
res = await page.data('jest_result');
expect(res).toBe(true)
});
});
it('Check Get With Data', async () => {
res = await page.callMethod('jest_get_with_data')
await page.waitFor(2000);
res = await page.data('jest_result');
expect(res).toBe(true)
})
});
......@@ -19,14 +19,14 @@ describe('setNavigationBarColor', () => {
it("setNavigationBarColor1", async () => {
await page.callMethod("setNavigationBarColor1");
const image = await program.screenshot();
expect(image).toMatchImageSnapshot();
expect(image).toSaveImageSnapshot();
const lifeCycleNum = await page.callMethod("getLifeCycleNum");
expect(lifeCycleNum - originLifeCycleNum).toBe(2);
});
it("setNavigationBarColor2", async () => {
await page.callMethod("setNavigationBarColor2");
const image = await program.screenshot();
expect(image).toMatchImageSnapshot();
expect(image).toSaveImageSnapshot();
const lifeCycleNum = await page.callMethod("getLifeCycleNum");
expect(lifeCycleNum - originLifeCycleNum).toBe(4);
});
......
......@@ -19,13 +19,13 @@ describe("setNavigationBarColor", () => {
it("setNavigationBarNewTitle", async () => {
await page.callMethod("setNavigationBarNewTitle");
const image = await program.screenshot();
expect(image).toMatchImageSnapshot();
expect(image).toSaveImageSnapshot();
const lifeCycleNum = await page.callMethod("getLifeCycleNum");
expect(lifeCycleNum - originLifeCycleNum).toBe(2);
});
it("setNavigationBarLongTitle", async () => {
await page.callMethod("setNavigationBarLongTitle");
const image = await program.screenshot();
expect(image).toMatchImageSnapshot();
expect(image).toSaveImageSnapshot();
});
});
......@@ -3,7 +3,7 @@
describe('API-toast', () => {
let page;
const isAndroid = process.env.UNI_OS_NAME === "android";
const isApp = process.env.UNI_OS_NAME === "android" || process.env.UNI_OS_NAME === "ios";
beforeAll(async () => {
......@@ -16,14 +16,14 @@ describe('API-toast', () => {
it("onload-toast-test", async () => {
if (isAndroid) {
if (isApp) {
await page.waitFor(500);
const res = await page.callMethod('jest_getWindowInfo')
const windowHeight = res.windowHeight * res.pixelRatio;
const windowWidth = res.windowWidth * res.pixelRatio;
const image = await program.screenshot({
adb: true,
deviceShot: true,
area: {
x: 0,
y: 200,
......@@ -31,13 +31,13 @@ describe('API-toast', () => {
width:windowWidth
},
});
expect(image).toMatchImageSnapshot();
expect(image).toSaveImageSnapshot();
}else{
const image = await program.screenshot({
adb: true,
deviceShot: true,
fullPage: true
});
expect(image).toMatchImageSnapshot()
expect(image).toSaveImageSnapshot()
}
})
......@@ -47,14 +47,14 @@ describe('API-toast', () => {
const btnToastDefaultButton = await page.$('#btn-toast-default')
await btnToastDefaultButton.tap()
await page.waitFor(200)
if (isAndroid) {
if (isApp) {
const res = await page.callMethod('jest_getWindowInfo')
const windowHeight = res.windowHeight * res.pixelRatio;
const windowWidth = res.windowWidth * res.pixelRatio;
const image = await program.screenshot({
adb: true,
deviceShot: true,
area: {
x: 0,
y: 200,
......@@ -62,13 +62,13 @@ describe('API-toast', () => {
width:windowWidth
},
});
expect(image).toMatchImageSnapshot();
expect(image).toSaveImageSnapshot();
}else{
const image = await program.screenshot({
adb: true,
deviceShot: true,
fullPage: true
});
expect(image).toMatchImageSnapshot()
expect(image).toSaveImageSnapshot()
}
})
......@@ -78,12 +78,12 @@ describe('API-toast', () => {
const btnToastDurationButton = await page.$('#btn-toast-duration')
await btnToastDurationButton.tap()
await page.waitFor(2000)
if (isAndroid) {
if (isApp) {
const res = await page.callMethod('jest_getWindowInfo')
const windowHeight = res.windowHeight * res.pixelRatio;
const windowWidth = res.windowWidth * res.pixelRatio;
const image = await program.screenshot({
adb: true,
deviceShot: true,
area: {
x: 0,
y: 200,
......@@ -91,13 +91,13 @@ describe('API-toast', () => {
width:windowWidth
},
});
expect(image).toMatchImageSnapshot();
expect(image).toSaveImageSnapshot();
}else{
const image = await program.screenshot({
adb: true,
deviceShot: true,
fullPage: true
});
expect(image).toMatchImageSnapshot()
expect(image).toSaveImageSnapshot()
}
})
......@@ -105,12 +105,12 @@ describe('API-toast', () => {
const btnToastErrorIconButton = await page.$('#btn-toast-errorIcon')
await btnToastErrorIconButton.tap()
await page.waitFor(200)
if (isAndroid) {
if (isApp) {
const res = await page.callMethod('jest_getWindowInfo')
const windowHeight = res.windowHeight * res.pixelRatio;
const windowWidth = res.windowWidth * res.pixelRatio;
const image = await program.screenshot({
adb: true,
deviceShot: true,
area: {
x: 0,
y: 200,
......@@ -118,13 +118,13 @@ describe('API-toast', () => {
width:windowWidth
},
});
expect(image).toMatchImageSnapshot();
expect(image).toSaveImageSnapshot();
}else{
const image = await program.screenshot({
adb: true,
deviceShot: true,
fullPage: true
});
expect(image).toMatchImageSnapshot()
expect(image).toSaveImageSnapshot()
}
})
......@@ -138,12 +138,12 @@ describe('API-toast', () => {
await btnToastHideButton.tap()
await page.waitFor(1000)
if (isAndroid) {
if (isApp) {
const res = await page.callMethod('jest_getWindowInfo')
const windowHeight = res.windowHeight * res.pixelRatio;
const windowWidth = res.windowWidth * res.pixelRatio;
const image = await program.screenshot({
adb: true,
deviceShot: true,
area: {
x: 0,
y: 200,
......@@ -151,13 +151,13 @@ describe('API-toast', () => {
width:windowWidth
},
});
expect(image).toMatchImageSnapshot();
expect(image).toSaveImageSnapshot();
}else{
const image = await program.screenshot({
adb: true,
deviceShot: true,
fullPage: true
});
expect(image).toMatchImageSnapshot()
expect(image).toSaveImageSnapshot()
}
})
......@@ -166,11 +166,11 @@ describe('API-toast', () => {
// const btnToastButton = await page.$('#btn-toast-postion-bottom')
// await btnToastButton.tap()
// await page.waitFor(200)
// if (isAndroid) {
// if (isApp) {
// const windowHeight = uni.getWindowInfo().windowHeight;
// const windowWidth = uni.getWindowInfo().windowWidth;
// const image = await program.screenshot({
// adb: true,
// deviceShot: true,
// area: {
// x: 0,
// y: 200,
......@@ -178,13 +178,13 @@ describe('API-toast', () => {
// width:windowWidth
// },
// });
// expect(image).toMatchImageSnapshot();
// expect(image).toSaveImageSnapshot();
// }else{
// const image = await program.screenshot({
// adb: true,
// deviceShot: true,
// fullPage: true
// });
// expect(image).toMatchImageSnapshot()
// expect(image).toSaveImageSnapshot()
// }
// })
......
......@@ -27,17 +27,17 @@ describe('ExtApi-UploadFile', () => {
it('Check ', async () => {
expect(res).toBe(true);
});
it('Check files upload', async () => {
res = await page.callMethod('jest_files_upload')
await page.waitFor(2000);
res = await page.data('jest_result');
expect(res).toBe(true)
});
it('Check files upload', async () => {
res = await page.callMethod('jest_files_upload')
await page.waitFor(2000);
res = await page.data('jest_result');
expect(res).toBe(true)
});
let shouldTestCookie = false
if (process.env.uniTestPlatformInfo.startsWith('android')) {
if (process.env.uniTestPlatformInfo.startsWith('android') && !process.env.UNI_AUTOMATOR_APP_WEBVIEW) {
let version = process.env.uniTestPlatformInfo
version = parseInt(version.split(" ")[1])
shouldTestCookie = version > 9
......@@ -59,4 +59,4 @@ describe('ExtApi-UploadFile', () => {
res = await page.data('jest_result');
expect(res).toBe(true)
});
});
});
describe('background-image-test', () => {
let page;
beforeAll(async () => {
page = await program.reLaunch('/pages/CSS/background/background-image');
await page.waitFor(600);
});
it('background-image-screenshot', async () => {
await page.waitFor(300);
const image = await program.screenshot({fullPage: true});
expect(image).toSaveImageSnapshot();
});
it('background-image-select', async () => {
await page.callMethod('updateBackgroundSelect')
await page.waitFor(300);
const image = await program.screenshot({fullPage: true});
expect(image).toSaveImageSnapshot();
});
});
describe('component-native-overflow', () => {
let page
describe('component-native-overflow', () => {
let page
beforeAll(async () => {
//打开list-view测试页
page = await program.reLaunch('/pages/CSS/overflow/overflow')
await page.waitFor("image")
//打开list-view测试页
page = await program.reLaunch('/pages/CSS/overflow/overflow')
await page.waitFor("image")
})
//检测overflow设置hidden,visible
it('check_view_overflow', async () => {
if (process.env.uniTestPlatformInfo.startsWith('android')) {
if (process.env.uniTestPlatformInfo.startsWith('android') && !process.env.UNI_AUTOMATOR_APP_WEBVIEW) {
let version = process.env.uniTestPlatformInfo
version = parseInt(version.split(" ")[1])
//安卓7模拟器不截图 导致闪退
......@@ -20,6 +20,6 @@ describe('component-native-overflow', () => {
const image = await program.screenshot({
fullPage: true,
});
expect(image).toMatchImageSnapshot();
})
expect(image).toSaveImageSnapshot();
})
})
......@@ -11,6 +11,6 @@ describe('css-font-family', () => {
const image = await program.screenshot({
fullPage: true
})
expect(image).toMatchImageSnapshot()
expect(image).toSaveImageSnapshot()
});
});
describe('css-font-size', () => {
let page;
beforeAll(async () => {
page = await program.reLaunch('/pages/CSS/text/font-size');
});
it('screenshot', async () => {
await page.callMethod("setFontSize");
await page.waitFor(100);
const image = await program.screenshot({ fullPage: true });
expect(image).toSaveImageSnapshot();
});
});
......@@ -9,6 +9,6 @@ describe('css-variable', () => {
const image = await program.screenshot({
fullPage: true
})
expect(image).toMatchImageSnapshot()
expect(image).toSaveImageSnapshot()
});
});
......@@ -8,8 +8,8 @@ describe('general attribute', () => {
await page.waitFor('view')
})
it("class & style", async () => {
const image = await program.screenshot();
expect(image).toMatchImageSnapshot();
const image = await program.screenshot({fullPage: true});
expect(image).toSaveImageSnapshot();
});
it('validateGeneralAttributes', async () => {
const button = await page.$(".btn-style");
......@@ -21,7 +21,7 @@ describe('general attribute', () => {
const button = await page.$(".btn-ref");
await button.tap();
await page.waitFor(500);
const image = await program.screenshot();
expect(image).toMatchImageSnapshot();
const image = await program.screenshot({fullPage: true});
expect(image).toSaveImageSnapshot();
});
})
......@@ -10,7 +10,7 @@ describe('event trigger sequence', () => {
})
it('touch', async () => {
if (process.env.uniTestPlatformInfo.startsWith('android')) {
if (process.env.uniTestPlatformInfo.startsWith('android') && !process.env.UNI_AUTOMATOR_APP_WEBVIEW) {
await el.touchstart({
touches: [{
identifier: 1,
......@@ -56,10 +56,10 @@ describe('event trigger sequence', () => {
})
it('longPress', async () => {
if (process.env.uniTestPlatformInfo.startsWith('android')) {
if (process.env.uniTestPlatformInfo.startsWith('android') && !process.env.UNI_AUTOMATOR_APP_WEBVIEW) {
await el.longpress()
const data = await page.data()
expect(data.onLongPressTime).toBeGreaterThan(0)
}
})
})
})
......@@ -30,7 +30,7 @@ describe('component-native-image', () => {
expect(await page.data('loadError')).toBe(true)
})
if (process.env.uniTestPlatformInfo.startsWith('android')) {
if (process.env.uniTestPlatformInfo.startsWith('android') && !process.env.UNI_AUTOMATOR_APP_WEBVIEW) {
it('check-cookie', async () => {
await page.setData({
autoTest: true,
......@@ -55,7 +55,7 @@ describe('component-native-image', () => {
const image = await program.screenshot({
fullPage: true
})
expect(image).toMatchImageSnapshot()
expect(image).toSaveImageSnapshot()
});
it('mode-screenshot', async () => {
......@@ -65,6 +65,6 @@ describe('component-native-image', () => {
const image = await program.screenshot({
fullPage: true
})
expect(image).toMatchImageSnapshot()
expect(image).toSaveImageSnapshot()
});
});
......@@ -12,7 +12,7 @@ describe('component-native-input', () => {
// const image = await program.screenshot({
// fullPage: true
// })
// expect(image).toMatchImageSnapshot()
// expect(image).toSaveImageSnapshot()
// })
// 测试焦点及键盘弹起
it('focus', async () => {
......@@ -147,10 +147,35 @@ describe('component-native-input', () => {
expect(await (await page.$('#uni-input-cursor-color')).attribute("cursor-color")).toBe("red")
})
it("maxlength", async () => {
const input = await page.$('#uni-input-maxlength');
let str = "";
for(let i = 0;i < 200;i++){
str += `${i}`
}
await page.setData({
inputMaxLengthValue: str
})
let length = (await input.value()).length
expect(length).toBe(10)
await page.setData({
inputMaxLengthValue: ""
})
})
it("password and value order", async () => {
const input = await page.$('#uni-input-password');
let length = (await input.value()).length
expect(length).toBe(6)
await page.setData({
inputPasswordValue: ""
})
})
it("afterAllTestScreenshot", async () => {
const image = await program.screenshot({
fullPage: true
})
expect(image).toMatchImageSnapshot()
expect(image).toSaveImageSnapshot()
})
});
......@@ -22,6 +22,7 @@ describe('list-view-children-in-slot', () => {
const addBtn = await page.$('#add-btn')
await addBtn.tap()
await page.waitFor(500)
listItems = await page.$$('list-item')
expect(listItems.length).toBe(11)
......@@ -33,12 +34,12 @@ describe('list-view-children-in-slot', () => {
const emptyBtn = await page.$('#empty-btn')
await emptyBtn.tap()
await page.waitFor(500)
listItems = await page.$$('list-item')
expect(listItems.length).toBe(3)
await addBtn.tap()
await page.waitFor(500)
listItems = await page.$$('list-item')
expect(listItems.length).toBe(5)
......
describe('component-native-list-view', () => {
let page
beforeAll(async () => {
//打开list-view-multiplex测试页
page = await program.reLaunch('/pages/component/list-view/list-view-multiplex')
await page.waitFor('list-view')
})
//滚动list-view到底部 加载更多 如果异常则直接闪退
it('check_list_item_multiplex', async () => {
await page.callMethod('listViewScrollByY', 5000)
await page.waitFor(400)
await page.callMethod('listViewScrollByY', 100)
describe('component-native-list-view', () => {
let page
beforeAll(async () => {
//打开list-view-multiplex测试页
page = await program.reLaunch('/pages/component/list-view/list-view-multiplex')
await page.waitFor('list-view')
})
//滚动list-view到底部 加载更多 如果异常则直接闪退
it('check_list_item_multiplex', async () => {
await page.callMethod('listViewScrollByY', 5000)
await page.waitFor(400)
await page.callMethod('listViewScrollByY', 100)
})
//检测延迟显示listv-view后list-item是否正常显示
......@@ -20,8 +20,8 @@ describe('component-native-list-view', () => {
return await page.data('list_show') === true;
});
await page.waitFor(200)
const image = await program.screenshot();
expect(image).toMatchImageSnapshot();
const image = await program.screenshot({fullPage: true});
expect(image).toSaveImageSnapshot();
})
//检测修改item子元素后,item是否正常调整高度
......@@ -31,7 +31,7 @@ describe('component-native-list-view', () => {
return await page.data('displayArrow') === true;
});
await page.waitFor(600)
const image = await program.screenshot();
expect(image).toMatchImageSnapshot();
})
const image = await program.screenshot({fullPage: true});
expect(image).toSaveImageSnapshot();
})
})
describe('component-native-list-view-refresh', () => {
if (process.env.uniTestPlatformInfo.startsWith('web')) {
it('dummyTest', async () => {
expect(1).toBe(1)
it('dummyTest', async () => {
expect(1).toBe(1)
})
return
}
let page
}
let page
beforeAll(async () => {
//打开list-view测试页
page = await program.reLaunch('/pages/component/list-view/list-view-refresh')
await page.waitFor(600)
//打开list-view测试页
page = await program.reLaunch('/pages/component/list-view/list-view-refresh')
await page.waitFor(600)
})
it('check_list_view_refresh', async () => {
......@@ -18,7 +18,7 @@ describe('component-native-list-view-refresh', () => {
});
//等待下拉刷新结束
await page.waitFor(500)
const image = await program.screenshot();
expect(image).toMatchImageSnapshot();
})
const image = await program.screenshot({fullPage: true});
expect(image).toSaveImageSnapshot();
})
})
......@@ -6,15 +6,6 @@ describe('component-native-list-view', () => {
await page.waitFor(600)
})
//检测竖向可滚动区域
it('check_scroll_height', async () => {
await page.callMethod('change_scroll_y_boolean', true)
await page.callMethod('change_scroll_x_boolean', false)
await page.waitFor(600)
const value = await page.callMethod('check_scroll_height')
expect(value).toBe(true)
})
//检测竖向scrolltop属性赋值
it('check_scroll_top', async () => {
await page.callMethod('confirm_scroll_top_input', 600)
......@@ -26,7 +17,7 @@ describe('component-native-list-view', () => {
})
//检测横向scrollLeft属性赋值
//检测横向scrollLeft属性赋值 备注:iOS不支持list-view横向滚动
it('check_scroll_left', async () => {
if(await page.data('scroll_x_boolean') === false) {
await page.callMethod('change_scroll_x_boolean', true)
......@@ -45,7 +36,21 @@ describe('component-native-list-view', () => {
return
}
//检测横向可滚动区域
if(process.env.uniTestPlatformInfo.toLowerCase().startsWith('ios')) {
return
}
//检测竖向可滚动区域
it('check_scroll_height', async () => {
await page.callMethod('change_scroll_y_boolean', true)
await page.callMethod('change_scroll_x_boolean', false)
await page.waitFor(600)
const value = await page.callMethod('check_scroll_height')
expect(value).toBe(true)
})
//检测横向可滚动区域 备注:iOS不支持list-view横向滚动
it('check_scroll_width', async () => {
if(await page.data('scroll_x_boolean') === false) {
await page.callMethod('change_scroll_x_boolean', true)
......@@ -59,7 +64,7 @@ describe('component-native-list-view', () => {
expect(value).toBe(true)
})
//检测下拉刷新
//检测下拉刷新 备注:iOS本地测试结果正确,但是自动化测试结果错误
it('check_refresher', async () => {
if(await page.data('scroll_y_boolean') === false) {
await page.callMethod('change_scroll_y_boolean', true)
......@@ -74,7 +79,7 @@ describe('component-native-list-view', () => {
expect(await page.data('refresherrefresh')).toBe(true)
})
//检测竖向scroll_into_view属性赋值
//检测竖向scroll_into_view属性赋值 备注:iOS本地测试结果正确,但是自动化测试结果错误
it('check_scroll_into_view_top', async () => {
if(await page.data('scroll_y_boolean') === false) {
await page.callMethod('change_scroll_y_boolean', true)
......@@ -90,7 +95,7 @@ describe('component-native-list-view', () => {
expect(scrollTop-690).toBeGreaterThanOrEqual(0)
})
//检测横向scroll_into_view属性赋值
//检测横向scroll_into_view属性赋值 备注:iOS不支持list-view横向滚动
it('check_scroll_into_view_left', async () => {
if(await page.data('scroll_x_boolean') === false) {
await page.callMethod('change_scroll_x_boolean', true)
......
describe('component-native-nested-scroll-body', () => {
if (process.env.uniTestPlatformInfo.indexOf('web') > -1 || process.env.UNI_AUTOMATOR_APP_WEBVIEW == 'true') {
it('dummyTest', () => {
expect(1).toBe(1)
})
return
}
let page
beforeAll(async () => {
//打开lnested-scroll-body测试页
page = await program.reLaunch('/pages/component/nested-scroll-body/nested-scroll-body')
await page.waitFor(600)
})
//检测横向scroll_into_view属性赋值
it('check_scroll_into_view_left', async () => {
await page.callMethod('testBodyScrollBy', 400)
await page.waitFor(300)
const image = await program.screenshot({fullPage: true});
expect(image).toSaveImageSnapshot();
})
})
describe('component-native-nested-scroll-header', () => {
if (process.env.uniTestPlatformInfo.indexOf('web') > -1 || process.env.UNI_AUTOMATOR_APP_WEBVIEW == 'true') {
it('dummyTest', () => {
expect(1).toBe(1)
})
return
}
let page
beforeAll(async () => {
//打开lnested-scroll-header测试页
page = await program.reLaunch('/pages/component/nested-scroll-header/nested-scroll-header')
await page.waitFor(600)
})
it('check_nested-scroll-header', async () => {
const image = await program.screenshot({fullPage: true});
expect(image).toSaveImageSnapshot();
})
})
......@@ -65,7 +65,7 @@ describe('PickerView.uvue', () => {
})
it('reopen-picker-view-page', async () => {
await program.switchTab('/')
page = await program.switchTab('/pages/tabBar/component')
await page.waitFor(500)
page = await program.navigateTo(PAGE_PATH)
await page.waitFor(500)
......
......@@ -89,8 +89,8 @@ describe('component-native-scroll-view-props', () => {
showScrollbar: false
})
await page.waitFor(300);
const image = await program.screenshot();
expect(image).toMatchImageSnapshot();
const image = await program.screenshot({fullPage: true});
expect(image).toSaveImageSnapshot();
})
});
// uni-app自动化测试教程: uni-app自动化测试教程: https://uniapp.dcloud.net.cn/worktile/auto/hbuilderx-extension/
describe('component-native-scroll-view-refresher', () => {
if (process.env.uniTestPlatformInfo.startsWith('android')) {
if (process.env.uniTestPlatformInfo.startsWith('android') && !process.env.UNI_AUTOMATOR_APP_WEBVIEW) {
let page;
beforeAll(async () => {
page = await program.reLaunch('/pages/component/scroll-view/scroll-view-refresher');
await page.waitFor(300);
});
it('scroll-view-refresher-screenshot', async () => {
//禁止滚动条
await page.setData({
showScrollbar: false
})
await page.waitFor(300);
const image = await program.screenshot();
expect(image).toMatchImageSnapshot();
it('scroll-view-refresher-screenshot', async () => {
//禁止滚动条
await page.setData({
showScrollbar: false
})
await page.waitFor(300);
const image = await program.screenshot({fullPage: true});
expect(image).toSaveImageSnapshot();
})
it('check_refresher', async () => {
......@@ -30,4 +30,4 @@ describe('component-native-scroll-view-refresher', () => {
expect(1).toBe(1)
})
}
});
});
describe('component-native-scroll-view', () => {
describe('component-native-scroll-view', () => {
let page;
beforeAll(async () => {
page = await program.reLaunch('/pages/component/scroll-view/scroll-view');
......@@ -12,7 +12,7 @@ describe('component-native-scroll-view', () => {
showScrollbar: false
})
await page.waitFor(300);
const image = await program.screenshot();
expect(image).toMatchImageSnapshot();
});
const image = await program.screenshot({fullPage: true});
expect(image).toSaveImageSnapshot();
});
});
......@@ -8,7 +8,7 @@ describe('component-native-sticky-header', () => {
//检测吸顶效果
it('check_sticky_header', async () => {
await page.callMethod('confirm_scroll_top_input', 600)
const image = await program.screenshot();
expect(image).toMatchImageSnapshot();
const image = await program.screenshot({fullPage: true});
expect(image).toSaveImageSnapshot();
})
})
})
......@@ -8,12 +8,12 @@ describe('component-native-sticky-section', () => {
//检测吸顶上推效果
it('check_sticky_section', async () => {
await page.callMethod('listViewScrollByY', 1000)
const image = await program.screenshot();
expect(image).toMatchImageSnapshot();
})
if (process.env.uniTestPlatformInfo.startsWith('web')) {
return
const image = await program.screenshot({fullPage: true});
expect(image).toSaveImageSnapshot();
})
if (process.env.uniTestPlatformInfo.startsWith('web') || process.env.UNI_AUTOMATOR_APP_WEBVIEW === 'true') {
return
}
it('check_goto_sticky_header', async () => {
......@@ -23,14 +23,14 @@ describe('component-native-sticky-section', () => {
await page.setData({
scrolling: 'true'
})
if (process.env.uniTestPlatformInfo.startsWith('android')) {
if (!process.env.UNI_AUTOMATOR_APP_WEBVIEW) {
//跳转到id为C的StickyHeader位置
await page.callMethod('gotoStickyHeader', 'C')
}
await page.waitFor(async () => {
return await page.data('scrolling') === false;
});
const image = await program.screenshot();
expect(image).toMatchImageSnapshot();
const image = await program.screenshot({fullPage: true});
expect(image).toSaveImageSnapshot();
})
})
})
jest.setTimeout(20000);
jest.setTimeout(20000);
function getData(key = '') {
return new Promise(async (resolve, reject) => {
const data = await page.data()
......@@ -29,39 +29,24 @@ describe('test swiper', () => {
*/
});
it('check autoplay loop', async () => {
await page.setData({
autoplaySelect: true,
currentValChange: 0,
})
await page.waitFor(600)
expect(await getData('currentValChange')).toEqual(0)
await page.waitFor(1600)
expect(await getData('currentValChange')).toEqual(1)
await page.waitFor(2000)
expect(await getData('currentValChange')).toEqual(2)
await page.waitFor(2000)
expect(await getData('currentValChange')).toEqual(0)
await page.setData({
circularSelect: true,
currentValChange: 0,
})
await page.waitFor(600)
expect(await getData('currentValChange')).toEqual(0)
await page.waitFor(1600)
expect(await getData('currentValChange')).toEqual(1)
await page.waitFor(2000)
expect(await getData('currentValChange')).toEqual(2)
await page.waitFor(2000)
expect(await getData('currentValChange')).toEqual(0)
await page.setData({
circularSelect: false,
autoplaySelect: false
})
it('check autoplay loop', async () => {
await page.setData({
currentValChange: 0,
autoplaySelect: true,
})
await page.waitFor(2400)
expect(await getData('currentValChange')).toEqual(1)
await page.waitFor(2000)
expect(await getData('currentValChange')).toEqual(2)
await page.waitFor(2000)
expect(await getData('currentValChange')).toEqual(0)
await page.setData({
autoplaySelect: false
})
await page.waitFor(300)
});
it('check current', async () => {
await page.setData({
currentVal: 2,
......
......@@ -9,7 +9,7 @@ describe('text-props', () => {
it('screenshot', async () => {
const image = await program.screenshot({ fullPage: true })
expect(image).toMatchImageSnapshot()
expect(image).toSaveImageSnapshot()
})
it('empty text', async () => {
......
......@@ -24,6 +24,20 @@ describe('component-native-video', () => {
expect(await page.data('isPause')).toBe(true);
});
it('test local source', async () => {
await page.callMethod('downloadSource');
await page.waitFor(5000);
expect(await page.data('isError')).toBe(false);
await page.setData({
localSrc: '/static/test-video/2minute-demo.m3u8'
});
await page.waitFor(100);
expect(await page.data('isError')).toBe(false);
await page.setData({
autoTest: false
});
});
it('test format', async () => {
page = await program.navigateTo('/pages/component/video/video-format');
await page.waitFor(1000);
......
......@@ -12,14 +12,14 @@ describe('component-native-web-view', () => {
});
it('screenshot', async () => {
if (process.env.uniTestPlatformInfo.startsWith('android')) {
if (process.env.uniTestPlatformInfo.startsWith('android') && !process.env.UNI_AUTOMATOR_APP_WEBVIEW) {
await page.waitFor(async () => {
return await page.data('loadFinish') === true;
});
const image = await program.screenshot({
fullPage: true
});
expect(image).toMatchImageSnapshot();
expect(image).toSaveImageSnapshot();
}
});
});
\ No newline at end of file
// uni-app自动化测试教程: uni-app自动化测试教程: https://uniapp.dcloud.net.cn/worktile/auto/hbuilderx-extension/
describe('component-native-web-view', () => {
if (process.env.uniTestPlatformInfo.startsWith('android')) {
if (process.env.uniTestPlatformInfo.startsWith('android') && !process.env.UNI_AUTOMATOR_APP_WEBVIEW) {
let page;
beforeAll(async () => {
page = await program.reLaunch('/pages/component/web-view/web-view');
......
......@@ -38,7 +38,6 @@ const pages = [
// CSS
'/pages/CSS/background/background-color',
'/pages/CSS/background/background-image',
'/pages/CSS/border/complex-border/complex-border',
'/pages/CSS/border/border-bottom',
'/pages/CSS/border/border-color',
......@@ -121,7 +120,7 @@ const pages = [
// '/pages/API/element-draw/element-draw',
]
if (process.env.uniTestPlatformInfo.startsWith('android')) {
if (process.env.uniTestPlatformInfo.startsWith('android') && !process.env.UNI_AUTOMATOR_APP_WEBVIEW) {
// 规避 web 端不支持页面
pages.push(
"/pages/component/list-view/list-view",
......@@ -133,19 +132,27 @@ if (process.env.uniTestPlatformInfo.startsWith('android')) {
'/pages/template/pull-zoom-image/pull-zoom-image',
'/pages/template/scroll-fold-nav/scroll-fold-nav',
'/pages/template/scroll-sticky/scroll-sticky',
'/pages/template/custom-refresher/custom-refresher',
'/pages/template/custom-tab-bar/custom-tab-bar',
'/pages/template/custom-refresher/custom-refresher',
'/pages/template/custom-tab-bar/custom-tab-bar',
'/pages/template/half-screen/half-screen',
)
}
// 设置position: fixed的页面不能截取完整内容
const notFullPages = [
'/pages/CSS/layout/position',
'/pages/CSS/layout/z-index'
]
}
// 设置position: fixed的页面不能截取完整内容
const notFullPages = [
'/pages/CSS/layout/position',
'/pages/CSS/layout/z-index'
]
let page;
let windowInfo
async function getWindowInfo() {
const windowInfoPage = await program.reLaunch('/pages/API/get-window-info/get-window-info')
await windowInfoPage.waitFor(600);
return await windowInfoPage.callMethod('jest_getWindowInfo')
}
describe("page screenshot test", () => {
beforeAll(async () => {
console.log("page screenshot test start");
......@@ -162,14 +169,36 @@ describe("page screenshot test", () => {
});
test.each(pages)("%s", async () => {
console.log("Taking screenshot: ", pageIndex, pages[pageIndex]);
let fullPage = true;
if (notFullPages.includes(pages[pageIndex])) {
fullPage = false;
let fullPage = true;
if (notFullPages.includes(pages[pageIndex])) {
fullPage = false;
}
const screenshotParams = {
fullPage
}
const image = await program.screenshot({
fullPage: fullPage
});
expect(image).toMatchImageSnapshot();
if (!fullPage && !process.env.UNI_AUTOMATOR_APP_WEBVIEW) {
let offsetY = '0'
if (process.env.uniTestPlatformInfo.toLocaleLowerCase().startsWith('android')) {
offsetY = '44'
}
if (process.env.uniTestPlatformInfo.toLocaleLowerCase().startsWith('ios')) {
if (!windowInfo) {
windowInfo = await getWindowInfo()
page = await program.reLaunch(pages[pageIndex]);
await page.waitFor(1000);
}
offsetY = `${windowInfo.safeAreaInsets.top + 44}`
}
screenshotParams.offsetY = offsetY
}
const image = await program.screenshot(screenshotParams);
expect(image).toSaveImageSnapshot({
customSnapshotIdentifier() {
return `__pages_test__/${pages[pageIndex].replace(/\//g, "-").substring(1)}`
}
})
await page.waitFor(500);
});
});
});
......@@ -11,6 +11,6 @@ describe('template-list-news', () => {
const image = await program.screenshot({
fullPage: true
})
expect(image).toMatchImageSnapshot()
expect(image).toSaveImageSnapshot()
});
});
......@@ -37,10 +37,10 @@ describe("setCustomNavigationBarColor", () => {
await page.waitFor(1000);
if (isAndroid) {
const image = await program.screenshot({
adb: true,
deviceShot: true,
area: adbScreenShotArea,
});
expect(image).toMatchImageSnapshot();
expect(image).toSaveImageSnapshot();
}
const lifeCycleNum = await page.callMethod("getLifeCycleNum");
expect(lifeCycleNum - originLifeCycleNum).toBe(2);
......@@ -51,12 +51,12 @@ describe("setCustomNavigationBarColor", () => {
await page.waitFor(1000);
if (isAndroid) {
const image = await program.screenshot({
adb: true,
deviceShot: true,
area: adbScreenShotArea,
});
expect(image).toMatchImageSnapshot();
expect(image).toSaveImageSnapshot();
}
const lifeCycleNum = await page.callMethod("getLifeCycleNum");
expect(lifeCycleNum - originLifeCycleNum).toBe(4);
});
});
});
......@@ -8,7 +8,7 @@ const pages = [
"pages/component/text/text-props",
"pages/component/progress/progress",
"pages/component/form/form",
"pages/component/button/button",
"pages/component/button/button",
"pages/component/button/buttonstatus",
"pages/component/radio/radio",
"pages/component/rich-text/rich-text",
......@@ -26,6 +26,7 @@ const pages = [
"pages/component/video/video-format",
"pages/component/navigator/navigator",
"pages/component/navigator/navigate",
"pages/component/navigator/redirect",
"pages/component/general-attribute/general-attribute",
"pages/component/general-event/general-event",
......@@ -43,7 +44,6 @@ const pages = [
"pages/API/navigator/navigator",
"pages/API/set-navigation-bar-color/set-navigation-bar-color",
"pages/API/set-navigation-bar-title/set-navigation-bar-title",
"pages/API/set-navigation-bar-color/set-custom-navigation-bar-color",
"pages/API/navigator/new-page/new-page-1",
"pages/API/navigator/new-page/new-page-3",
"pages/API/pull-down-refresh/pull-down-refresh",
......@@ -69,7 +69,6 @@ const pages = [
"pages/API/get-device-info/get-device-info",
"pages/API/get-app-base-info/get-app-base-info",
"pages/API/preview-image/preview-image",
"pages/API/save-image-to-photos-album/save-image-to-photos-album",
"pages/API/choose-image/choose-image",
"pages/API/get-network-type/get-network-type",
"pages/API/page-scroll-to/page-scroll-to",
......@@ -197,6 +196,7 @@ const pages = [
// "pages/API/element-takesnapshot/element-takesnapshot",
// "pages/API/get-system-setting/get-system-setting",
// "pages/API/get-app-authorize-setting/get-app-authorize-setting",
// "pages/API/save-image-to-photos-album/save-image-to-photos-album",
// 仅 web
// pages/template/browser-canvas/browser-canvas
......@@ -237,16 +237,20 @@ const PAGE_PATH =
describe("shot-compare", () => {
let shouldCompareScreenShot = false
if (process.env.uniTestPlatformInfo.startsWith('android')) {
let version = process.env.uniTestPlatformInfo
version = parseInt(version.split(" ")[1])
const uniTestPlatformInfo = process.env.uniTestPlatformInfo.toLocaleLowerCase()
if (uniTestPlatformInfo.startsWith('android') && !process.env.UNI_AUTOMATOR_APP_WEBVIEW) {
version = parseInt(uniTestPlatformInfo.split(" ")[1])
shouldCompareScreenShot = version > 9
}
if(uniTestPlatformInfo.startsWith('ios') && !process.env.UNI_AUTOMATOR_APP_WEBVIEW) {
shouldCompareScreenShot = true
}
if (!shouldCompareScreenShot) {
it("other platform not support", async () => {
expect(1).toBe(1);
});
});
return
}
......@@ -285,20 +289,22 @@ describe("shot-compare", () => {
const isCustomNavigationBar = customNavigationPages.includes(pages[pageIndex]);
const {
statusBarHeight,
safeArea,
devicePixelRatio
} = await page.data();
const screenshotParams = {
fullPage: true,
adb: isNeedAdbScreenshot,
// adb 截图时跳过状态栏
deviceShot: isNeedAdbScreenshot,
// deviceShot 截图时跳过状态栏
area: {
x: 0,
y: statusBarHeight * devicePixelRatio,
},
}
const screenshotPath = `__webview__${pages[pageIndex].replace(/\//g, "-")}`;
const screenshotPath = `__webview_comparison__/${pages[pageIndex].replace(/\//g, "-")}`;
// web in webview screenshot
let startTime = Date.now();
// 加载依赖页面
if (childToParentPagesMap.get(pages[pageIndex])) {
await page.setData({
......@@ -316,8 +322,7 @@ describe("shot-compare", () => {
isLoaded: false,
isCustomNavigationBar,
});
const startTime = Date.now();
startTime = Date.now();
await page.waitFor(async () => {
const isLoaded = await page.data("isLoaded");
return isLoaded || Date.now() - startTime > 3000;
......@@ -327,11 +332,11 @@ describe("shot-compare", () => {
await page.waitFor(3000);
}
// web 端非 adb 截图时设置 offsetY 移除导航栏
// web 端非 deviceShot 截图时设置 offsetY 移除导航栏
const webSnapshot = await program.screenshot({
...screenshotParams,
id: 'webview-screenshot-comparison',
offsetY: `${isCustomNavigationBar ? 0 : 44}`
offsetY: `${isCustomNavigationBar ? 0 : 44 + safeArea.top}`
});
expect(webSnapshot).toMatchImageSnapshot({
customSnapshotIdentifier() {
......@@ -355,4 +360,4 @@ describe("shot-compare", () => {
},
});
});
});
});
......@@ -42,7 +42,6 @@ const pages = [
"pages/API/navigator/navigator",
"pages/API/set-navigation-bar-color/set-navigation-bar-color",
"pages/API/set-navigation-bar-title/set-navigation-bar-title",
"pages/API/set-navigation-bar-color/set-custom-navigation-bar-color",
"pages/API/navigator/new-page/new-page-1",
"pages/API/navigator/new-page/new-page-3",
"pages/API/pull-down-refresh/pull-down-refresh",
......@@ -67,10 +66,7 @@ const pages = [
"pages/API/get-system-info/get-system-info",
"pages/API/get-device-info/get-device-info",
"pages/API/get-app-base-info/get-app-base-info",
"pages/API/get-system-setting/get-system-setting",
"pages/API/get-app-authorize-setting/get-app-authorize-setting",
"pages/API/preview-image/preview-image",
"pages/API/save-image-to-photos-album/save-image-to-photos-album",
"pages/API/choose-image/choose-image",
"pages/API/get-network-type/get-network-type",
"pages/API/page-scroll-to/page-scroll-to",
......@@ -196,6 +192,9 @@ const pages = [
// "pages/template/scroll-sticky/scroll-sticky",
// "pages/API/exit/exit",
// "pages/API/element-takesnapshot/element-takesnapshot",
// "pages/API/get-app-authorize-setting/get-app-authorize-setting",
// "pages/API/get-system-setting/get-system-setting",
// "pages/API/save-image-to-photos-album/save-image-to-photos-album",
// 仅 web
// pages/template/browser-canvas/browser-canvas
......@@ -236,22 +235,33 @@ const PAGE_PATH =
describe("shot-compare", () => {
let shouldCompareScreenShot = false
if (process.env.uniTestPlatformInfo.startsWith('android')) {
let version = process.env.uniTestPlatformInfo
version = parseInt(version.split(" ")[1])
const uniTestPlatformInfo = process.env.uniTestPlatformInfo.toLocaleLowerCase()
if (uniTestPlatformInfo.startsWith('android') && !process.env.UNI_AUTOMATOR_APP_WEBVIEW) {
version = parseInt(uniTestPlatformInfo.split(" ")[1])
shouldCompareScreenShot = version > 9
}
if(uniTestPlatformInfo.startsWith('ios') && !process.env.UNI_AUTOMATOR_APP_WEBVIEW) {
shouldCompareScreenShot = true
}
if (!shouldCompareScreenShot) {
it("other platform not support", async () => {
expect(1).toBe(1);
});
});
return
}
let page = null;
let pageIndex = 0;
let baseSrc = "";
beforeAll(async () => {
// 获取导航栏+状态栏高度
page = await program.reLaunch('/pages/API/get-window-info/get-window-info')
await page.callMethod('getWindowInfo')
// 获取设备像素比
page = await program.reLaunch('/pages/API/get-device-info/get-device-info')
await page.callMethod('getDeviceInfo')
page = await program.reLaunch(PAGE_PATH);
await page.waitFor(500);
......@@ -265,7 +275,6 @@ describe("shot-compare", () => {
});
beforeEach(async () => {
page = await program.reLaunch(PAGE_PATH);
await page.waitFor(500);
});
afterEach(() => {
......@@ -276,21 +285,22 @@ describe("shot-compare", () => {
const isNeedAdbScreenshot = needAdbScreenshot(pages[pageIndex]);
const isCustomNavigation = customNavigationPages.includes(pages[pageIndex]);
const {
headerHeight,
statusBarHeight,
devicePixelRatio
} = await page.data();
const screenshotParams = {
fullPage: true,
adb: isNeedAdbScreenshot,
// adb 截图时跳过状态栏
deviceShot: isNeedAdbScreenshot,
// deviceShot 截图时跳过状态栏
area: {
x: 0,
y: (headerHeight - 44) * devicePixelRatio,
y: (statusBarHeight - 44) * devicePixelRatio,
},
}
const screenshotPath = `webview-shot__${pages[pageIndex].replace(/\//g, "-")}`;
const screenshotPath = `__webview-shot__/${pages[pageIndex].replace(/\//g, "-")}`;
// web in webview screenshot
let startTime = Date.now();
// 加载依赖页面
if (childToParentPagesMap.get(pages[pageIndex])) {
await page.setData({
......@@ -309,7 +319,7 @@ describe("shot-compare", () => {
needRemoveWebHead: !isNeedAdbScreenshot,
});
const startTime = Date.now();
startTime = Date.now();
await page.waitFor(async () => {
const isLoaded = await page.data("isLoaded");
return isLoaded || Date.now() - startTime > 3000;
......@@ -319,15 +329,15 @@ describe("shot-compare", () => {
await page.waitFor(3000);
}
// web 端非 adb 截图时设置 offsetY 移除导航栏
// web 端非 deviceShot 截图时设置 offsetY 移除导航栏
const webSnapshot = await program.screenshot({
...screenshotParams,
offsetY: `${isCustomNavigation ? 0 : headerHeight}`
offsetY: `${isCustomNavigation ? 0 : statusBarHeight + 44}`
});
expect(webSnapshot).toMatchImageSnapshot({
expect(webSnapshot).toSaveImageSnapshot({
customSnapshotIdentifier() {
return screenshotPath;
},
});
});
});
});
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册