提交 9e0f3292 编写于 作者: DCloud-WZF's avatar DCloud-WZF 💬

test: 支持 ios 端 webview & app 截图对比

上级 36a23a84
...@@ -18,7 +18,7 @@ describe('API-loading', () => { ...@@ -18,7 +18,7 @@ describe('API-loading', () => {
const windowHeight = res.windowHeight * res.pixelRatio; const windowHeight = res.windowHeight * res.pixelRatio;
const windowWidth = res.windowWidth * res.pixelRatio; const windowWidth = res.windowWidth * res.pixelRatio;
const image = await program.screenshot({ const image = await program.screenshot({
adb: true, deviceShot: true,
area: { area: {
x: 0, x: 0,
y: 200, y: 200,
...@@ -30,7 +30,7 @@ describe('API-loading', () => { ...@@ -30,7 +30,7 @@ describe('API-loading', () => {
expect(image).toMatchImageSnapshot(); expect(image).toMatchImageSnapshot();
}else{ }else{
const image = await program.screenshot({ const image = await program.screenshot({
adb: true, deviceShot: true,
fullPage: true fullPage: true
}); });
expect(image).toMatchImageSnapshot() expect(image).toMatchImageSnapshot()
...@@ -59,7 +59,7 @@ describe('API-loading', () => { ...@@ -59,7 +59,7 @@ describe('API-loading', () => {
if (isAndroid) { if (isAndroid) {
const image = await program.screenshot({ const image = await program.screenshot({
adb: true, deviceShot: true,
area: { area: {
x: 0, x: 0,
y: 200, y: 200,
...@@ -70,7 +70,7 @@ describe('API-loading', () => { ...@@ -70,7 +70,7 @@ describe('API-loading', () => {
expect(image).toMatchImageSnapshot(); expect(image).toMatchImageSnapshot();
}else{ }else{
const image = await program.screenshot({ const image = await program.screenshot({
adb: true, deviceShot: true,
fullPage: true fullPage: true
}); });
expect(image).toMatchImageSnapshot() expect(image).toMatchImageSnapshot()
...@@ -101,7 +101,7 @@ describe('API-loading', () => { ...@@ -101,7 +101,7 @@ describe('API-loading', () => {
if (isAndroid) { if (isAndroid) {
const image = await program.screenshot({ const image = await program.screenshot({
adb: true, deviceShot: true,
area: { area: {
x: 0, x: 0,
y: 200, y: 200,
...@@ -112,7 +112,7 @@ describe('API-loading', () => { ...@@ -112,7 +112,7 @@ describe('API-loading', () => {
expect(image).toMatchImageSnapshot(); expect(image).toMatchImageSnapshot();
}else{ }else{
const image = await program.screenshot({ const image = await program.screenshot({
adb: true, deviceShot: true,
fullPage: true fullPage: true
}); });
expect(image).toMatchImageSnapshot() expect(image).toMatchImageSnapshot()
...@@ -142,7 +142,7 @@ describe('API-loading', () => { ...@@ -142,7 +142,7 @@ describe('API-loading', () => {
if (isAndroid) { if (isAndroid) {
const image = await program.screenshot({ const image = await program.screenshot({
adb: true, deviceShot: true,
area: { area: {
x: 0, x: 0,
y: 200, y: 200,
...@@ -153,7 +153,7 @@ describe('API-loading', () => { ...@@ -153,7 +153,7 @@ describe('API-loading', () => {
expect(image).toMatchImageSnapshot(); expect(image).toMatchImageSnapshot();
}else{ }else{
const image = await program.screenshot({ const image = await program.screenshot({
adb: true, deviceShot: true,
fullPage: true fullPage: true
}); });
expect(image).toMatchImageSnapshot() expect(image).toMatchImageSnapshot()
...@@ -183,7 +183,7 @@ describe('API-loading', () => { ...@@ -183,7 +183,7 @@ describe('API-loading', () => {
if (isAndroid) { if (isAndroid) {
const image = await program.screenshot({ const image = await program.screenshot({
adb: true, deviceShot: true,
area: { area: {
x: 0, x: 0,
y: 200, y: 200,
...@@ -194,7 +194,7 @@ describe('API-loading', () => { ...@@ -194,7 +194,7 @@ describe('API-loading', () => {
expect(image).toMatchImageSnapshot(); expect(image).toMatchImageSnapshot();
}else{ }else{
const image = await program.screenshot({ const image = await program.screenshot({
adb: true, deviceShot: true,
fullPage: true fullPage: true
}); });
expect(image).toMatchImageSnapshot() expect(image).toMatchImageSnapshot()
...@@ -224,7 +224,7 @@ describe('API-loading', () => { ...@@ -224,7 +224,7 @@ describe('API-loading', () => {
if (isAndroid) { if (isAndroid) {
const image = await program.screenshot({ const image = await program.screenshot({
adb: true, deviceShot: true,
area: { area: {
x: 0, x: 0,
y: 200, y: 200,
...@@ -235,7 +235,7 @@ describe('API-loading', () => { ...@@ -235,7 +235,7 @@ describe('API-loading', () => {
expect(image).toMatchImageSnapshot(); expect(image).toMatchImageSnapshot();
}else{ }else{
const image = await program.screenshot({ const image = await program.screenshot({
adb: true, deviceShot: true,
fullPage: true fullPage: true
}); });
expect(image).toMatchImageSnapshot() expect(image).toMatchImageSnapshot()
...@@ -268,7 +268,7 @@ describe('API-loading', () => { ...@@ -268,7 +268,7 @@ describe('API-loading', () => {
if (isAndroid) { if (isAndroid) {
const image = await program.screenshot({ const image = await program.screenshot({
adb: true, deviceShot: true,
area: { area: {
x: 0, x: 0,
y: 200, y: 200,
...@@ -279,7 +279,7 @@ describe('API-loading', () => { ...@@ -279,7 +279,7 @@ describe('API-loading', () => {
expect(image).toMatchImageSnapshot(); expect(image).toMatchImageSnapshot();
}else{ }else{
const image = await program.screenshot({ const image = await program.screenshot({
adb: true, deviceShot: true,
fullPage: true fullPage: true
}); });
expect(image).toMatchImageSnapshot() expect(image).toMatchImageSnapshot()
...@@ -309,7 +309,7 @@ describe('API-loading', () => { ...@@ -309,7 +309,7 @@ describe('API-loading', () => {
if (isAndroid) { if (isAndroid) {
const image = await program.screenshot({ const image = await program.screenshot({
adb: true, deviceShot: true,
area: { area: {
x: 0, x: 0,
y: 200, y: 200,
...@@ -320,7 +320,7 @@ describe('API-loading', () => { ...@@ -320,7 +320,7 @@ describe('API-loading', () => {
expect(image).toMatchImageSnapshot(); expect(image).toMatchImageSnapshot();
}else{ }else{
const image = await program.screenshot({ const image = await program.screenshot({
adb: true, deviceShot: true,
fullPage: true fullPage: true
}); });
expect(image).toMatchImageSnapshot() expect(image).toMatchImageSnapshot()
...@@ -350,7 +350,7 @@ describe('API-loading', () => { ...@@ -350,7 +350,7 @@ describe('API-loading', () => {
if (isAndroid) { if (isAndroid) {
const image = await program.screenshot({ const image = await program.screenshot({
adb: true, deviceShot: true,
area: { area: {
x: 0, x: 0,
y: 200, y: 200,
...@@ -361,7 +361,7 @@ describe('API-loading', () => { ...@@ -361,7 +361,7 @@ describe('API-loading', () => {
expect(image).toMatchImageSnapshot(); expect(image).toMatchImageSnapshot();
}else{ }else{
const image = await program.screenshot({ const image = await program.screenshot({
adb: true, deviceShot: true,
fullPage: true fullPage: true
}); });
expect(image).toMatchImageSnapshot() expect(image).toMatchImageSnapshot()
...@@ -391,7 +391,7 @@ describe('API-loading', () => { ...@@ -391,7 +391,7 @@ describe('API-loading', () => {
if (isAndroid) { if (isAndroid) {
const image = await program.screenshot({ const image = await program.screenshot({
adb: true, deviceShot: true,
area: { area: {
x: 0, x: 0,
y: 200, y: 200,
...@@ -402,7 +402,7 @@ describe('API-loading', () => { ...@@ -402,7 +402,7 @@ describe('API-loading', () => {
expect(image).toMatchImageSnapshot(); expect(image).toMatchImageSnapshot();
}else{ }else{
const image = await program.screenshot({ const image = await program.screenshot({
adb: true, deviceShot: true,
fullPage: true fullPage: true
}); });
expect(image).toMatchImageSnapshot() expect(image).toMatchImageSnapshot()
...@@ -433,7 +433,7 @@ describe('API-loading', () => { ...@@ -433,7 +433,7 @@ describe('API-loading', () => {
if (isAndroid) { if (isAndroid) {
const image = await program.screenshot({ const image = await program.screenshot({
adb: true, deviceShot: true,
area: { area: {
x: 0, x: 0,
y: 200, y: 200,
...@@ -444,7 +444,7 @@ describe('API-loading', () => { ...@@ -444,7 +444,7 @@ describe('API-loading', () => {
expect(image).toMatchImageSnapshot(); expect(image).toMatchImageSnapshot();
}else{ }else{
const image = await program.screenshot({ const image = await program.screenshot({
adb: true, deviceShot: true,
fullPage: true fullPage: true
}); });
expect(image).toMatchImageSnapshot() expect(image).toMatchImageSnapshot()
...@@ -474,7 +474,7 @@ describe('API-loading', () => { ...@@ -474,7 +474,7 @@ describe('API-loading', () => {
if (isAndroid) { if (isAndroid) {
const image = await program.screenshot({ const image = await program.screenshot({
adb: true, deviceShot: true,
area: { area: {
x: 0, x: 0,
y: 200, y: 200,
...@@ -485,7 +485,7 @@ describe('API-loading', () => { ...@@ -485,7 +485,7 @@ describe('API-loading', () => {
expect(image).toMatchImageSnapshot(); expect(image).toMatchImageSnapshot();
}else{ }else{
const image = await program.screenshot({ const image = await program.screenshot({
adb: true, deviceShot: true,
fullPage: true fullPage: true
}); });
expect(image).toMatchImageSnapshot() expect(image).toMatchImageSnapshot()
...@@ -515,7 +515,7 @@ describe('API-loading', () => { ...@@ -515,7 +515,7 @@ describe('API-loading', () => {
if (isAndroid) { if (isAndroid) {
const image = await program.screenshot({ const image = await program.screenshot({
adb: true, deviceShot: true,
area: { area: {
x: 0, x: 0,
y: 200, y: 200,
...@@ -526,7 +526,7 @@ describe('API-loading', () => { ...@@ -526,7 +526,7 @@ describe('API-loading', () => {
expect(image).toMatchImageSnapshot(); expect(image).toMatchImageSnapshot();
}else{ }else{
const image = await program.screenshot({ const image = await program.screenshot({
adb: true, deviceShot: true,
fullPage: true fullPage: true
}); });
expect(image).toMatchImageSnapshot() expect(image).toMatchImageSnapshot()
......
...@@ -19,7 +19,8 @@ ...@@ -19,7 +19,8 @@
</view> </view>
</template> </template>
<script> <script>
import { setStatusBarHeight } from '@/store/index.uts' import { setStatusBarHeight, setSafeArea } from '@/store/index.uts'
import type { SafeArea } from '@/store/index.uts'
type Item = { type Item = {
label : string, label : string,
...@@ -33,33 +34,42 @@ ...@@ -33,33 +34,42 @@
} }
}, },
onUnload: function () { onUnload: function () {
}, },
onReady() { onReady() {
this.getWindowInfo() this.getWindowInfo()
}, },
methods: { methods: {
getWindowInfo: function () { getWindowInfo: function () {
const res = uni.getWindowInfo(); const res = uni.getWindowInfo();
// 获取状态栏+导航栏高度, 供截图对比使用 // 获取状态栏高度, 供截图对比使用
setStatusBarHeight(res.statusBarHeight); setStatusBarHeight(res.statusBarHeight);
this.items = [] as Item[]; // 获取安全区信息,供截图使用
setSafeArea({
const res_str = JSON.stringify(res); top: res.safeArea.top,
const res_obj = JSON.parseObject(res_str); left: res.safeArea.left,
const res_map = res_obj!.toMap(); right: res.safeArea.right,
let keys = [] as string[] bottom: res.safeArea.bottom,
res_map.forEach((_, key) => { width: res.safeArea.width,
keys.push(key); height: res.safeArea.height,
}); } as SafeArea);
keys.sort().forEach( key => { this.items = [] as Item[];
const value = res[key];
if(value != null){ const res_str = JSON.stringify(res);
const item = { const res_obj = JSON.parseObject(res_str);
label: key, const res_map = res_obj!.toMap();
value: "" + ((typeof value == "object")? JSON.stringify(value) : value) let keys = [] as string[]
} as Item; res_map.forEach((_, key) => {
this.items.push(item); keys.push(key);
} });
keys.sort().forEach(key => {
const value = res[key];
if (value != null) {
const item = {
label: key,
value: "" + ((typeof value == "object") ? JSON.stringify(value) : value)
} as Item;
this.items.push(item);
}
}); });
}, },
//自动化测试例专用 //自动化测试例专用
......
...@@ -20,7 +20,7 @@ describe('API-loading', () => { ...@@ -20,7 +20,7 @@ describe('API-loading', () => {
const windowWidth = res.windowWidth * res.pixelRatio; const windowWidth = res.windowWidth * res.pixelRatio;
const image = await program.screenshot({ const image = await program.screenshot({
adb: true, deviceShot: true,
area: { area: {
x: 0, x: 0,
y: 200, y: 200,
...@@ -31,7 +31,7 @@ describe('API-loading', () => { ...@@ -31,7 +31,7 @@ describe('API-loading', () => {
expect(image).toMatchImageSnapshot(); expect(image).toMatchImageSnapshot();
}else{ }else{
const image = await program.screenshot({ const image = await program.screenshot({
adb: true, deviceShot: true,
fullPage: true fullPage: true
}); });
expect(image).toMatchImageSnapshot() expect(image).toMatchImageSnapshot()
...@@ -60,7 +60,7 @@ describe('API-loading', () => { ...@@ -60,7 +60,7 @@ describe('API-loading', () => {
const windowWidth = res.windowWidth * res.pixelRatio; const windowWidth = res.windowWidth * res.pixelRatio;
const image = await program.screenshot({ const image = await program.screenshot({
adb: true, deviceShot: true,
area: { area: {
x: 0, x: 0,
y: 200, y: 200,
...@@ -71,7 +71,7 @@ describe('API-loading', () => { ...@@ -71,7 +71,7 @@ describe('API-loading', () => {
expect(image).toMatchImageSnapshot(); expect(image).toMatchImageSnapshot();
}else{ }else{
const image = await program.screenshot({ const image = await program.screenshot({
adb: true, deviceShot: true,
fullPage: true fullPage: true
}); });
expect(image).toMatchImageSnapshot() expect(image).toMatchImageSnapshot()
...@@ -101,7 +101,7 @@ describe('API-loading', () => { ...@@ -101,7 +101,7 @@ describe('API-loading', () => {
const windowWidth = res.windowWidth * res.pixelRatio; const windowWidth = res.windowWidth * res.pixelRatio;
const image = await program.screenshot({ const image = await program.screenshot({
adb: true, deviceShot: true,
area: { area: {
x: 0, x: 0,
y: 200, y: 200,
...@@ -112,7 +112,7 @@ describe('API-loading', () => { ...@@ -112,7 +112,7 @@ describe('API-loading', () => {
expect(image).toMatchImageSnapshot(); expect(image).toMatchImageSnapshot();
}else{ }else{
const image = await program.screenshot({ const image = await program.screenshot({
adb: true, deviceShot: true,
fullPage: true fullPage: true
}); });
expect(image).toMatchImageSnapshot() expect(image).toMatchImageSnapshot()
...@@ -142,7 +142,7 @@ describe('API-loading', () => { ...@@ -142,7 +142,7 @@ describe('API-loading', () => {
const windowWidth = res.windowWidth * res.pixelRatio; const windowWidth = res.windowWidth * res.pixelRatio;
const image = await program.screenshot({ const image = await program.screenshot({
adb: true, deviceShot: true,
area: { area: {
x: 0, x: 0,
y: 200, y: 200,
...@@ -153,7 +153,7 @@ describe('API-loading', () => { ...@@ -153,7 +153,7 @@ describe('API-loading', () => {
expect(image).toMatchImageSnapshot(); expect(image).toMatchImageSnapshot();
}else{ }else{
const image = await program.screenshot({ const image = await program.screenshot({
adb: true, deviceShot: true,
fullPage: true fullPage: true
}); });
expect(image).toMatchImageSnapshot() expect(image).toMatchImageSnapshot()
...@@ -183,7 +183,7 @@ describe('API-loading', () => { ...@@ -183,7 +183,7 @@ describe('API-loading', () => {
const windowWidth = res.windowWidth * res.pixelRatio; const windowWidth = res.windowWidth * res.pixelRatio;
const image = await program.screenshot({ const image = await program.screenshot({
adb: true, deviceShot: true,
area: { area: {
x: 0, x: 0,
y: 200, y: 200,
...@@ -194,7 +194,7 @@ describe('API-loading', () => { ...@@ -194,7 +194,7 @@ describe('API-loading', () => {
expect(image).toMatchImageSnapshot(); expect(image).toMatchImageSnapshot();
}else{ }else{
const image = await program.screenshot({ const image = await program.screenshot({
adb: true, deviceShot: true,
fullPage: true fullPage: true
}); });
expect(image).toMatchImageSnapshot() expect(image).toMatchImageSnapshot()
...@@ -223,7 +223,7 @@ describe('API-loading', () => { ...@@ -223,7 +223,7 @@ describe('API-loading', () => {
const windowHeight = res.windowHeight * res.pixelRatio; const windowHeight = res.windowHeight * res.pixelRatio;
const windowWidth = res.windowWidth * res.pixelRatio; const windowWidth = res.windowWidth * res.pixelRatio;
const image = await program.screenshot({ const image = await program.screenshot({
adb: true, deviceShot: true,
area: { area: {
x: 0, x: 0,
y: 200, y: 200,
...@@ -234,7 +234,7 @@ describe('API-loading', () => { ...@@ -234,7 +234,7 @@ describe('API-loading', () => {
expect(image).toMatchImageSnapshot(); expect(image).toMatchImageSnapshot();
}else{ }else{
const image = await program.screenshot({ const image = await program.screenshot({
adb: true, deviceShot: true,
fullPage: true fullPage: true
}); });
expect(image).toMatchImageSnapshot() expect(image).toMatchImageSnapshot()
...@@ -263,7 +263,7 @@ describe('API-loading', () => { ...@@ -263,7 +263,7 @@ describe('API-loading', () => {
const windowHeight = res.windowHeight * res.pixelRatio; const windowHeight = res.windowHeight * res.pixelRatio;
const windowWidth = res.windowWidth * res.pixelRatio; const windowWidth = res.windowWidth * res.pixelRatio;
const image = await program.screenshot({ const image = await program.screenshot({
adb: true, deviceShot: true,
area: { area: {
x: 0, x: 0,
y: 200, y: 200,
...@@ -274,7 +274,7 @@ describe('API-loading', () => { ...@@ -274,7 +274,7 @@ describe('API-loading', () => {
expect(image).toMatchImageSnapshot(); expect(image).toMatchImageSnapshot();
}else{ }else{
const image = await program.screenshot({ const image = await program.screenshot({
adb: true, deviceShot: true,
fullPage: true fullPage: true
}); });
expect(image).toMatchImageSnapshot() expect(image).toMatchImageSnapshot()
...@@ -303,7 +303,7 @@ describe('API-loading', () => { ...@@ -303,7 +303,7 @@ describe('API-loading', () => {
const windowHeight = res.windowHeight * res.pixelRatio; const windowHeight = res.windowHeight * res.pixelRatio;
const windowWidth = res.windowWidth * res.pixelRatio; const windowWidth = res.windowWidth * res.pixelRatio;
const image = await program.screenshot({ const image = await program.screenshot({
adb: true, deviceShot: true,
area: { area: {
x: 0, x: 0,
y: 200, y: 200,
...@@ -314,7 +314,7 @@ describe('API-loading', () => { ...@@ -314,7 +314,7 @@ describe('API-loading', () => {
expect(image).toMatchImageSnapshot(); expect(image).toMatchImageSnapshot();
}else{ }else{
const image = await program.screenshot({ const image = await program.screenshot({
adb: true, deviceShot: true,
fullPage: true fullPage: true
}); });
expect(image).toMatchImageSnapshot() expect(image).toMatchImageSnapshot()
...@@ -343,7 +343,7 @@ describe('API-loading', () => { ...@@ -343,7 +343,7 @@ describe('API-loading', () => {
const windowHeight = res.windowHeight * res.pixelRatio; const windowHeight = res.windowHeight * res.pixelRatio;
const windowWidth = res.windowWidth * res.pixelRatio; const windowWidth = res.windowWidth * res.pixelRatio;
const image = await program.screenshot({ const image = await program.screenshot({
adb: true, deviceShot: true,
area: { area: {
x: 0, x: 0,
y: 200, y: 200,
...@@ -354,7 +354,7 @@ describe('API-loading', () => { ...@@ -354,7 +354,7 @@ describe('API-loading', () => {
expect(image).toMatchImageSnapshot(); expect(image).toMatchImageSnapshot();
}else{ }else{
const image = await program.screenshot({ const image = await program.screenshot({
adb: true, deviceShot: true,
fullPage: true fullPage: true
}); });
expect(image).toMatchImageSnapshot() expect(image).toMatchImageSnapshot()
...@@ -384,7 +384,7 @@ describe('API-loading', () => { ...@@ -384,7 +384,7 @@ describe('API-loading', () => {
const windowWidth = res.windowWidth * res.pixelRatio; const windowWidth = res.windowWidth * res.pixelRatio;
const image = await program.screenshot({ const image = await program.screenshot({
adb: true, deviceShot: true,
area: { area: {
x: 0, x: 0,
y: 200, y: 200,
...@@ -395,7 +395,7 @@ describe('API-loading', () => { ...@@ -395,7 +395,7 @@ describe('API-loading', () => {
expect(image).toMatchImageSnapshot(); expect(image).toMatchImageSnapshot();
}else{ }else{
const image = await program.screenshot({ const image = await program.screenshot({
adb: true, deviceShot: true,
fullPage: true fullPage: true
}); });
expect(image).toMatchImageSnapshot() expect(image).toMatchImageSnapshot()
...@@ -425,7 +425,7 @@ describe('API-loading', () => { ...@@ -425,7 +425,7 @@ describe('API-loading', () => {
const windowWidth = res.windowWidth * res.pixelRatio; const windowWidth = res.windowWidth * res.pixelRatio;
const image = await program.screenshot({ const image = await program.screenshot({
adb: true, deviceShot: true,
area: { area: {
x: 0, x: 0,
y: 200, y: 200,
...@@ -436,7 +436,7 @@ describe('API-loading', () => { ...@@ -436,7 +436,7 @@ describe('API-loading', () => {
expect(image).toMatchImageSnapshot(); expect(image).toMatchImageSnapshot();
}else{ }else{
const image = await program.screenshot({ const image = await program.screenshot({
adb: true, deviceShot: true,
fullPage: true fullPage: true
}); });
expect(image).toMatchImageSnapshot() expect(image).toMatchImageSnapshot()
...@@ -466,7 +466,7 @@ describe('API-loading', () => { ...@@ -466,7 +466,7 @@ describe('API-loading', () => {
const windowWidth = res.windowWidth * res.pixelRatio; const windowWidth = res.windowWidth * res.pixelRatio;
const image = await program.screenshot({ const image = await program.screenshot({
adb: true, deviceShot: true,
area: { area: {
x: 0, x: 0,
y: 200, y: 200,
...@@ -477,7 +477,7 @@ describe('API-loading', () => { ...@@ -477,7 +477,7 @@ describe('API-loading', () => {
expect(image).toMatchImageSnapshot(); expect(image).toMatchImageSnapshot();
}else{ }else{
const image = await program.screenshot({ const image = await program.screenshot({
adb: true, deviceShot: true,
fullPage: true fullPage: true
}); });
expect(image).toMatchImageSnapshot() expect(image).toMatchImageSnapshot()
...@@ -507,7 +507,7 @@ describe('API-loading', () => { ...@@ -507,7 +507,7 @@ describe('API-loading', () => {
const windowWidth = res.windowWidth * res.pixelRatio; const windowWidth = res.windowWidth * res.pixelRatio;
const image = await program.screenshot({ const image = await program.screenshot({
adb: true, deviceShot: true,
area: { area: {
x: 0, x: 0,
y: 200, y: 200,
...@@ -518,7 +518,7 @@ describe('API-loading', () => { ...@@ -518,7 +518,7 @@ describe('API-loading', () => {
expect(image).toMatchImageSnapshot(); expect(image).toMatchImageSnapshot();
}else{ }else{
const image = await program.screenshot({ const image = await program.screenshot({
adb: true, deviceShot: true,
fullPage: true fullPage: true
}); });
expect(image).toMatchImageSnapshot() expect(image).toMatchImageSnapshot()
...@@ -548,7 +548,7 @@ describe('API-loading', () => { ...@@ -548,7 +548,7 @@ describe('API-loading', () => {
const windowWidth = res.windowWidth * res.pixelRatio; const windowWidth = res.windowWidth * res.pixelRatio;
const image = await program.screenshot({ const image = await program.screenshot({
adb: true, deviceShot: true,
area: { area: {
x: 0, x: 0,
y: 200, y: 200,
...@@ -559,7 +559,7 @@ describe('API-loading', () => { ...@@ -559,7 +559,7 @@ describe('API-loading', () => {
expect(image).toMatchImageSnapshot(); expect(image).toMatchImageSnapshot();
}else{ }else{
const image = await program.screenshot({ const image = await program.screenshot({
adb: true, deviceShot: true,
fullPage: true fullPage: true
}); });
expect(image).toMatchImageSnapshot() expect(image).toMatchImageSnapshot()
...@@ -589,7 +589,7 @@ describe('API-loading', () => { ...@@ -589,7 +589,7 @@ describe('API-loading', () => {
const windowWidth = res.windowWidth * res.pixelRatio; const windowWidth = res.windowWidth * res.pixelRatio;
const image = await program.screenshot({ const image = await program.screenshot({
adb: true, deviceShot: true,
area: { area: {
x: 0, x: 0,
y: 200, y: 200,
...@@ -600,7 +600,7 @@ describe('API-loading', () => { ...@@ -600,7 +600,7 @@ describe('API-loading', () => {
expect(image).toMatchImageSnapshot(); expect(image).toMatchImageSnapshot();
}else{ }else{
const image = await program.screenshot({ const image = await program.screenshot({
adb: true, deviceShot: true,
fullPage: true fullPage: true
}); });
expect(image).toMatchImageSnapshot() expect(image).toMatchImageSnapshot()
...@@ -630,7 +630,7 @@ describe('API-loading', () => { ...@@ -630,7 +630,7 @@ describe('API-loading', () => {
const windowHeight = res.windowHeight * res.pixelRatio; const windowHeight = res.windowHeight * res.pixelRatio;
const windowWidth = res.windowWidth * res.pixelRatio; const windowWidth = res.windowWidth * res.pixelRatio;
const image = await program.screenshot({ const image = await program.screenshot({
adb: true, deviceShot: true,
area: { area: {
x: 0, x: 0,
y: 200, y: 200,
...@@ -641,7 +641,7 @@ describe('API-loading', () => { ...@@ -641,7 +641,7 @@ describe('API-loading', () => {
expect(image).toMatchImageSnapshot(); expect(image).toMatchImageSnapshot();
}else{ }else{
const image = await program.screenshot({ const image = await program.screenshot({
adb: true, deviceShot: true,
fullPage: true fullPage: true
}); });
expect(image).toMatchImageSnapshot() expect(image).toMatchImageSnapshot()
...@@ -671,7 +671,7 @@ describe('API-loading', () => { ...@@ -671,7 +671,7 @@ describe('API-loading', () => {
const windowWidth = res.windowWidth * res.pixelRatio; const windowWidth = res.windowWidth * res.pixelRatio;
const image = await program.screenshot({ const image = await program.screenshot({
adb: true, deviceShot: true,
area: { area: {
x: 0, x: 0,
y: 200, y: 200,
...@@ -682,7 +682,7 @@ describe('API-loading', () => { ...@@ -682,7 +682,7 @@ describe('API-loading', () => {
expect(image).toMatchImageSnapshot(); expect(image).toMatchImageSnapshot();
}else{ }else{
const image = await program.screenshot({ const image = await program.screenshot({
adb: true, deviceShot: true,
fullPage: true fullPage: true
}); });
expect(image).toMatchImageSnapshot() expect(image).toMatchImageSnapshot()
...@@ -711,7 +711,7 @@ describe('API-loading', () => { ...@@ -711,7 +711,7 @@ describe('API-loading', () => {
const windowHeight = res.windowHeight * res.pixelRatio; const windowHeight = res.windowHeight * res.pixelRatio;
const windowWidth = res.windowWidth * res.pixelRatio; const windowWidth = res.windowWidth * res.pixelRatio;
const image = await program.screenshot({ const image = await program.screenshot({
adb: true, deviceShot: true,
area: { area: {
x: 0, x: 0,
y: 200, y: 200,
...@@ -722,7 +722,7 @@ describe('API-loading', () => { ...@@ -722,7 +722,7 @@ describe('API-loading', () => {
expect(image).toMatchImageSnapshot(); expect(image).toMatchImageSnapshot();
}else{ }else{
const image = await program.screenshot({ const image = await program.screenshot({
adb: true, deviceShot: true,
fullPage: true fullPage: true
}); });
expect(image).toMatchImageSnapshot() expect(image).toMatchImageSnapshot()
......
...@@ -61,7 +61,7 @@ describe("onLoad", () => { ...@@ -61,7 +61,7 @@ describe("onLoad", () => {
await page.callMethod("navigateToOnLoadWithType", "showToast"); await page.callMethod("navigateToOnLoadWithType", "showToast");
await page.waitFor(1000); await page.waitFor(1000);
const image = await program.screenshot({ const image = await program.screenshot({
adb: true, deviceShot: true,
area: { area: {
x: 0, x: 0,
y: 200, y: 200,
...@@ -79,7 +79,7 @@ describe("onLoad", () => { ...@@ -79,7 +79,7 @@ describe("onLoad", () => {
await page.callMethod("navigateToOnLoadWithType", "showLoading"); await page.callMethod("navigateToOnLoadWithType", "showLoading");
await page.waitFor(1000); await page.waitFor(1000);
const image = await program.screenshot({ const image = await program.screenshot({
adb: true, deviceShot: true,
area: { area: {
x: 0, x: 0,
y: 200, y: 200,
...@@ -97,7 +97,7 @@ describe("onLoad", () => { ...@@ -97,7 +97,7 @@ describe("onLoad", () => {
await page.callMethod("navigateToOnLoadWithType", "showModal"); await page.callMethod("navigateToOnLoadWithType", "showModal");
await page.waitFor(1000); await page.waitFor(1000);
const image = await program.screenshot({ const image = await program.screenshot({
adb: true, deviceShot: true,
area: { area: {
x: 0, x: 0,
y: 200, y: 200,
...@@ -115,7 +115,7 @@ describe("onLoad", () => { ...@@ -115,7 +115,7 @@ describe("onLoad", () => {
await page.callMethod("navigateToOnLoadWithType", "showActionSheet"); await page.callMethod("navigateToOnLoadWithType", "showActionSheet");
await page.waitFor(1000); await page.waitFor(1000);
const image = await program.screenshot({ const image = await program.screenshot({
adb: true, deviceShot: true,
area: { area: {
x: 0, x: 0,
y: 200, y: 200,
......
...@@ -23,7 +23,7 @@ describe('API-toast', () => { ...@@ -23,7 +23,7 @@ describe('API-toast', () => {
const windowWidth = res.windowWidth * res.pixelRatio; const windowWidth = res.windowWidth * res.pixelRatio;
const image = await program.screenshot({ const image = await program.screenshot({
adb: true, deviceShot: true,
area: { area: {
x: 0, x: 0,
y: 200, y: 200,
...@@ -34,7 +34,7 @@ describe('API-toast', () => { ...@@ -34,7 +34,7 @@ describe('API-toast', () => {
expect(image).toMatchImageSnapshot(); expect(image).toMatchImageSnapshot();
}else{ }else{
const image = await program.screenshot({ const image = await program.screenshot({
adb: true, deviceShot: true,
fullPage: true fullPage: true
}); });
expect(image).toMatchImageSnapshot() expect(image).toMatchImageSnapshot()
...@@ -54,7 +54,7 @@ describe('API-toast', () => { ...@@ -54,7 +54,7 @@ describe('API-toast', () => {
const windowWidth = res.windowWidth * res.pixelRatio; const windowWidth = res.windowWidth * res.pixelRatio;
const image = await program.screenshot({ const image = await program.screenshot({
adb: true, deviceShot: true,
area: { area: {
x: 0, x: 0,
y: 200, y: 200,
...@@ -65,7 +65,7 @@ describe('API-toast', () => { ...@@ -65,7 +65,7 @@ describe('API-toast', () => {
expect(image).toMatchImageSnapshot(); expect(image).toMatchImageSnapshot();
}else{ }else{
const image = await program.screenshot({ const image = await program.screenshot({
adb: true, deviceShot: true,
fullPage: true fullPage: true
}); });
expect(image).toMatchImageSnapshot() expect(image).toMatchImageSnapshot()
...@@ -83,7 +83,7 @@ describe('API-toast', () => { ...@@ -83,7 +83,7 @@ describe('API-toast', () => {
const windowHeight = res.windowHeight * res.pixelRatio; const windowHeight = res.windowHeight * res.pixelRatio;
const windowWidth = res.windowWidth * res.pixelRatio; const windowWidth = res.windowWidth * res.pixelRatio;
const image = await program.screenshot({ const image = await program.screenshot({
adb: true, deviceShot: true,
area: { area: {
x: 0, x: 0,
y: 200, y: 200,
...@@ -94,7 +94,7 @@ describe('API-toast', () => { ...@@ -94,7 +94,7 @@ describe('API-toast', () => {
expect(image).toMatchImageSnapshot(); expect(image).toMatchImageSnapshot();
}else{ }else{
const image = await program.screenshot({ const image = await program.screenshot({
adb: true, deviceShot: true,
fullPage: true fullPage: true
}); });
expect(image).toMatchImageSnapshot() expect(image).toMatchImageSnapshot()
...@@ -110,7 +110,7 @@ describe('API-toast', () => { ...@@ -110,7 +110,7 @@ describe('API-toast', () => {
const windowHeight = res.windowHeight * res.pixelRatio; const windowHeight = res.windowHeight * res.pixelRatio;
const windowWidth = res.windowWidth * res.pixelRatio; const windowWidth = res.windowWidth * res.pixelRatio;
const image = await program.screenshot({ const image = await program.screenshot({
adb: true, deviceShot: true,
area: { area: {
x: 0, x: 0,
y: 200, y: 200,
...@@ -121,7 +121,7 @@ describe('API-toast', () => { ...@@ -121,7 +121,7 @@ describe('API-toast', () => {
expect(image).toMatchImageSnapshot(); expect(image).toMatchImageSnapshot();
}else{ }else{
const image = await program.screenshot({ const image = await program.screenshot({
adb: true, deviceShot: true,
fullPage: true fullPage: true
}); });
expect(image).toMatchImageSnapshot() expect(image).toMatchImageSnapshot()
...@@ -143,7 +143,7 @@ describe('API-toast', () => { ...@@ -143,7 +143,7 @@ describe('API-toast', () => {
const windowHeight = res.windowHeight * res.pixelRatio; const windowHeight = res.windowHeight * res.pixelRatio;
const windowWidth = res.windowWidth * res.pixelRatio; const windowWidth = res.windowWidth * res.pixelRatio;
const image = await program.screenshot({ const image = await program.screenshot({
adb: true, deviceShot: true,
area: { area: {
x: 0, x: 0,
y: 200, y: 200,
...@@ -154,7 +154,7 @@ describe('API-toast', () => { ...@@ -154,7 +154,7 @@ describe('API-toast', () => {
expect(image).toMatchImageSnapshot(); expect(image).toMatchImageSnapshot();
}else{ }else{
const image = await program.screenshot({ const image = await program.screenshot({
adb: true, deviceShot: true,
fullPage: true fullPage: true
}); });
expect(image).toMatchImageSnapshot() expect(image).toMatchImageSnapshot()
...@@ -170,7 +170,7 @@ describe('API-toast', () => { ...@@ -170,7 +170,7 @@ describe('API-toast', () => {
// const windowHeight = uni.getWindowInfo().windowHeight; // const windowHeight = uni.getWindowInfo().windowHeight;
// const windowWidth = uni.getWindowInfo().windowWidth; // const windowWidth = uni.getWindowInfo().windowWidth;
// const image = await program.screenshot({ // const image = await program.screenshot({
// adb: true, // deviceShot: true,
// area: { // area: {
// x: 0, // x: 0,
// y: 200, // y: 200,
...@@ -181,7 +181,7 @@ describe('API-toast', () => { ...@@ -181,7 +181,7 @@ describe('API-toast', () => {
// expect(image).toMatchImageSnapshot(); // expect(image).toMatchImageSnapshot();
// }else{ // }else{
// const image = await program.screenshot({ // const image = await program.screenshot({
// adb: true, // deviceShot: true,
// fullPage: true // fullPage: true
// }); // });
// expect(image).toMatchImageSnapshot() // expect(image).toMatchImageSnapshot()
......
...@@ -37,7 +37,7 @@ describe("setCustomNavigationBarColor", () => { ...@@ -37,7 +37,7 @@ describe("setCustomNavigationBarColor", () => {
await page.waitFor(1000); await page.waitFor(1000);
if (isAndroid) { if (isAndroid) {
const image = await program.screenshot({ const image = await program.screenshot({
adb: true, deviceShot: true,
area: adbScreenShotArea, area: adbScreenShotArea,
}); });
expect(image).toMatchImageSnapshot(); expect(image).toMatchImageSnapshot();
...@@ -51,7 +51,7 @@ describe("setCustomNavigationBarColor", () => { ...@@ -51,7 +51,7 @@ describe("setCustomNavigationBarColor", () => {
await page.waitFor(1000); await page.waitFor(1000);
if (isAndroid) { if (isAndroid) {
const image = await program.screenshot({ const image = await program.screenshot({
adb: true, deviceShot: true,
area: adbScreenShotArea, area: adbScreenShotArea,
}); });
expect(image).toMatchImageSnapshot(); expect(image).toMatchImageSnapshot();
...@@ -59,4 +59,4 @@ describe("setCustomNavigationBarColor", () => { ...@@ -59,4 +59,4 @@ describe("setCustomNavigationBarColor", () => {
const lifeCycleNum = await page.callMethod("getLifeCycleNum"); const lifeCycleNum = await page.callMethod("getLifeCycleNum");
expect(lifeCycleNum - originLifeCycleNum).toBe(4); expect(lifeCycleNum - originLifeCycleNum).toBe(4);
}); });
}); });
...@@ -289,12 +289,13 @@ describe("shot-compare", () => { ...@@ -289,12 +289,13 @@ describe("shot-compare", () => {
const isCustomNavigationBar = customNavigationPages.includes(pages[pageIndex]); const isCustomNavigationBar = customNavigationPages.includes(pages[pageIndex]);
const { const {
statusBarHeight, statusBarHeight,
safeArea,
devicePixelRatio devicePixelRatio
} = await page.data(); } = await page.data();
const screenshotParams = { const screenshotParams = {
fullPage: true, fullPage: true,
adb: isNeedAdbScreenshot, deviceShot: isNeedAdbScreenshot,
// adb 截图时跳过状态栏 // deviceShot 截图时跳过状态栏
area: { area: {
x: 0, x: 0,
y: statusBarHeight * devicePixelRatio, y: statusBarHeight * devicePixelRatio,
...@@ -331,11 +332,11 @@ describe("shot-compare", () => { ...@@ -331,11 +332,11 @@ describe("shot-compare", () => {
await page.waitFor(3000); await page.waitFor(3000);
} }
// web 端非 adb 截图时设置 offsetY 移除导航栏 // web 端非 deviceShot 截图时设置 offsetY 移除导航栏
const webSnapshot = await program.screenshot({ const webSnapshot = await program.screenshot({
...screenshotParams, ...screenshotParams,
id: 'webview-screenshot-comparison', id: 'webview-screenshot-comparison',
offsetY: `${isCustomNavigationBar ? 0 : 44}` offsetY: `${isCustomNavigationBar ? 0 : 44 + safeArea.top}`
}); });
expect(webSnapshot).toMatchImageSnapshot({ expect(webSnapshot).toMatchImageSnapshot({
customSnapshotIdentifier() { customSnapshotIdentifier() {
......
...@@ -15,7 +15,8 @@ ...@@ -15,7 +15,8 @@
src: '', src: '',
webviewContext: null as WebviewContext | null, webviewContext: null as WebviewContext | null,
isLoaded: false, isLoaded: false,
statusBarHeight: state.statusBarHeight, statusBarHeight: state.statusBarHeight,
safeArea: state.safeArea,
isCustomNavigationBar: false, isCustomNavigationBar: false,
devicePixelRatio: state.devicePixelRatio, devicePixelRatio: state.devicePixelRatio,
webviewStyles: { webviewStyles: {
......
...@@ -284,8 +284,8 @@ describe("shot-compare", () => { ...@@ -284,8 +284,8 @@ describe("shot-compare", () => {
} = await page.data(); } = await page.data();
const screenshotParams = { const screenshotParams = {
fullPage: true, fullPage: true,
adb: isNeedAdbScreenshot, deviceShot: isNeedAdbScreenshot,
// adb 截图时跳过状态栏 // deviceShot 截图时跳过状态栏
area: { area: {
x: 0, x: 0,
y: (headerHeight - 44) * devicePixelRatio, y: (headerHeight - 44) * devicePixelRatio,
...@@ -323,7 +323,7 @@ describe("shot-compare", () => { ...@@ -323,7 +323,7 @@ describe("shot-compare", () => {
await page.waitFor(3000); await page.waitFor(3000);
} }
// web 端非 adb 截图时设置 offsetY 移除导航栏 // web 端非 deviceShot 截图时设置 offsetY 移除导航栏
const webSnapshot = await program.screenshot({ const webSnapshot = await program.screenshot({
...screenshotParams, ...screenshotParams,
offsetY: `${isCustomNavigation ? 0 : headerHeight}` offsetY: `${isCustomNavigation ? 0 : headerHeight}`
......
export type SafeArea = {
top : number,
right : number,
bottom : number,
left : number,
width : number,
height : number,
}
type State = { type State = {
lifeCycleNum : number, lifeCycleNum : number,
// 状态栏高度 // 状态栏高度
statusBarHeight : number, statusBarHeight : number,
safeArea : SafeArea
// 设备像素比 // 设备像素比
devicePixelRatio : number devicePixelRatio : number
} }
export const state = reactive({ lifeCycleNum: 0, statusBarHeight: 0, devicePixelRatio: 1 } as State) export const state = reactive({
lifeCycleNum: 0,
statusBarHeight: 0,
devicePixelRatio: 1,
safeArea: {
top: 0,
right: 0,
bottom: 0,
left: 0,
width: 0,
height: 0,
}
} as State)
export const setLifeCycleNum = (num : number) => { export const setLifeCycleNum = (num : number) => {
state.lifeCycleNum = num state.lifeCycleNum = num
...@@ -14,6 +36,10 @@ export const setLifeCycleNum = (num : number) => { ...@@ -14,6 +36,10 @@ export const setLifeCycleNum = (num : number) => {
export const setStatusBarHeight = (height : number) => { export const setStatusBarHeight = (height : number) => {
state.statusBarHeight = height state.statusBarHeight = height
}
export const setSafeArea = (value : SafeArea) => {
state.safeArea = value
} }
export const setDevicePixelRatio = (devicePixelRatio : number) => { export const setDevicePixelRatio = (devicePixelRatio : number) => {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册