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

refactor: 优化部分示例及测试

上级 cd992c61
......@@ -13,7 +13,7 @@ describe('ExtApi-GetWindowInfo', () => {
beforeAll(async () => {
page = await program.reLaunch(PAGE_PATH)
await page.waitFor(600);
res = await page.callMethod('jest_getWindowInfo')
res = await program.callUniMethod('getWindowInfo');
});
it('Check GetWindowInfo', async () => {
......@@ -23,13 +23,13 @@ describe('ExtApi-GetWindowInfo', () => {
if (numberProperties.indexOf(key) != -1) {
expect(value).toBeGreaterThanOrEqual(0);
}
}
if (process.env.uniTestPlatformInfo.startsWith('android')) {
if (res.safeAreaInsets.bottom > 0) {
expect(res.safeAreaInsets.top + 44 + res.windowHeight).toBe(res.screenHeight);
} else {
expect(res.safeAreaInsets.top + 44 + res.windowHeight).toBe(res.safeArea.bottom);
}
}
if (process.env.uniTestPlatformInfo.startsWith('android')) {
if (res.safeAreaInsets.bottom > 0) {
expect(res.safeAreaInsets.top + 44 + res.windowHeight).toBe(res.screenHeight);
} else {
expect(res.safeAreaInsets.top + 44 + res.windowHeight).toBe(res.safeArea.bottom);
}
}
});
});
});
......@@ -93,10 +93,6 @@
}
});
},
//自动化测试例专用
jest_getWindowInfo() : GetWindowInfoResult {
return uni.getWindowInfo();
},
}
}
</script>
......@@ -105,4 +101,4 @@
.uni-pd {
padding-left: 15px;
}
</style>
</style>
......@@ -6,38 +6,29 @@ const isApp = isAndroid || isIOS || isHarmony
describe('API-toast', () => {
let page;
const screeShotParams = {
deviceShot: true,
fullPage: true
}
beforeAll(async () => {
page = await program.reLaunch('/pages/API/show-toast/show-toast')
await page.waitFor("view");
if (isApp) {
const windowInfo = await program.callUniMethod('getWindowInfo');
// android 端 app-webview 时顶部安全区高度为0,所以统一设置为60
const topSafeArea = isAndroid ? 60 : windowInfo.safeAreaInsets.top;
screeShotParams.area = {
x: 0,
y: topSafeArea + 44
}
}
});
async function toScreenshot(imgName) {
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({
deviceShot: true,
area: {
x: 0,
y: 200,
height: windowHeight - 200,
width:windowWidth
},
});
expect(image).toSaveImageSnapshot({customSnapshotIdentifier() {
return imgName
}})
}else{
const image = await program.screenshot({
deviceShot: true,
fullPage: true
});
expect(image).toSaveImageSnapshot({customSnapshotIdentifier() {
return imgName
}})
}
const image = await program.screenshot(screeShotParams);
expect(image).toSaveImageSnapshot({customSnapshotIdentifier() {
return imgName
}})
await page.waitFor(500);
}
......
const platformInfo = process.env.uniTestPlatformInfo.toLocaleLowerCase()
const isMP = platformInfo.startsWith('mp')
const isAppWebview = !!process.env.UNI_AUTOMATOR_APP_WEBVIEW
describe('component-native-image', () => {
const platformInfo = process.env.uniTestPlatformInfo.toLocaleLowerCase()
const isMP = platformInfo.startsWith('mp')
const screenshotParams = { fullPage: true }
let page;
let start = 0;
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')
}
const screenshotParams = { fullPage: true }
let windowInfo
beforeAll(async () => {
if (!process.env.UNI_AUTOMATOR_APP_WEBVIEW) {
screenshotParams.fullPage = false
windowInfo = await getWindowInfo()
let offsetY = '0'
if (process.env.uniTestPlatformInfo.toLocaleLowerCase().startsWith('android')) {
offsetY = `${windowInfo.statusBarHeight + 44}`
}
if (process.env.uniTestPlatformInfo.toLocaleLowerCase().startsWith('ios')) {
offsetY = `${windowInfo.safeAreaInsets.top + 44}`
}
screenshotParams.offsetY = offsetY
}
page = await program.reLaunch('/pages/component/image/image');
await page.waitFor(600);
});
......@@ -132,14 +115,14 @@ describe('component-native-image', () => {
if (process.env.android_cpu_type === 'x86_64') return
const page = await program.navigateTo('/pages/component/image/image-mode');
await page.waitFor(1000);
const image = await program.screenshot({fullPage: true})
const image = await program.screenshot(screenshotParams)
expect(image).toSaveImageSnapshot()
});
it('long-path-screenshot', async() => {
const page = await program.navigateTo('/pages/component/image/image-long');
await page.waitFor(3000);
const image = await program.screenshot({fullPage: true})
const image = await program.screenshot(screenshotParams)
expect(image).toSaveImageSnapshot()
})
});
const platformInfo = process.env.uniTestPlatformInfo.toLocaleLowerCase()
const isAndroid = platformInfo.startsWith('android')
const isIos = platformInfo.startsWith('ios')
const isApp = isAndroid || isIos
const isWeb = platformInfo.startsWith('web')
const isMP = platformInfo.startsWith('mp')
const isHarmony = platformInfo.startsWith('harmony')
const isApp = isAndroid || isIos || isHarmony
const isAppWebview = !!process.env.UNI_AUTOMATOR_APP_WEBVIEW
let pageIndex = 0
const pages = [
'/pages/component/rich-text/rich-text-tags'
]
describe("rich-text-tags", () => {
it("screenshot", async () => {
const page = await program.reLaunch('/pages/component/rich-text/rich-text-tags');
await page.waitFor('view');
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", () => {
if (platformInfo.indexOf('safari') !== -1) {
it('暂时规避 safari 截图测试', () => {
expect(1).toBe(1)
})
return
}
beforeAll(async () => {
console.log("page screenshot test start");
});
beforeEach(async () => {
const currentPagePath = pages[pageIndex]
page = await program.reLaunch(currentPagePath);
});
afterEach(() => {
pageIndex++;
});
afterAll(() => {
console.log("page screenshot test finish");
});
test.each(pages)("%s", async () => {
const currentPagePath = pages[pageIndex]
console.log("Taking screenshot: ", pageIndex, currentPagePath);
let fullPage = true;
const screenshotParams = {
fullPage
}
if (!fullPage && !isAppWebview) {
if (!windowInfo) {
windowInfo = await getWindowInfo()
page = await program.reLaunch(currentPagePath);
}
let offsetY = '0'
if (isAndroid) {
offsetY = `${windowInfo.statusBarHeight + 44}`
}
if (isIos) {
offsetY = `${windowInfo.safeAreaInsets.top + 44}`
}
screenshotParams.offsetY = offsetY
}
await page.waitFor(2000);
const image = await program.screenshot(screenshotParams);
expect(image).toSaveImageSnapshot({
customSnapshotIdentifier() {
return `__pages_test__/${currentPagePath.replace(/\//g, "-").substring(1)}`
}
})
await page.waitFor(800);
});
const image = await program.screenshot({ fullPage: true });
expect(image).toSaveImageSnapshot();
})
});
......@@ -49,11 +49,11 @@ describe('rich-text-test', () => {
isItemClickTrigger: false
});
await page.waitFor(1000);
const info = await page.callMethod('getWindowInfoForTest');
const windowInfo = await program.callUniMethod('getWindowInfo');
const rect = await page.callMethod('getBoundingClientRectForTest');
await program.tap({
x: (rect.right - rect.left) / 2,
y: info.statusBarHeight + 44 + (rect.bottom - rect.top) / 2
y: windowInfo.statusBarHeight + 44 + (rect.bottom - rect.top) / 2
});
await page.waitFor(1000);
expect(await page.data('isItemClickTrigger')).toBe(true);
......@@ -65,7 +65,7 @@ describe('rich-text-test', () => {
await program.navigateBack();
await program.tap({
x: (rect.right - rect.left) / 2,
y: info.statusBarHeight + 44 + (rect.bottom - rect.top) / 2
y: windowInfo.statusBarHeight + 44 + (rect.bottom - rect.top) / 2
});
await page.waitFor(1000);
expect(await page.data('isItemClickTrigger')).toBe(true);
......
......@@ -2,12 +2,12 @@
<view>
<page-head title="rich-text"></page-head>
<view class="uni-padding-wrap uni-common-mt">
<!-- #ifndef APP-HARMONY -->
<view class="uni-btn-v">
<navigator url="/pages/component/rich-text/rich-text-tags">
<button type="primary">rich-text渲染单个HTML标签示例</button>
</navigator>
</view>
<!-- #ifndef APP-HARMONY -->
<view class="uni-btn-v">
<navigator url="/pages/component/rich-text/rich-text-tags">
<button type="primary">rich-text渲染单个HTML标签示例</button>
</navigator>
</view>
<!-- #endif -->
<view class="uni-btn-v">
<navigator url="/pages/component/rich-text/rich-text-complex">
......@@ -27,10 +27,10 @@
</view>
<view class="uni-title">
<text class="uni-subtitle-text">selectable</text>
</view>
<view class="text-box2">
<rich-text style="height: 80px;" :selectable="true"
:nodes="text"></rich-text>
</view>
<view class="text-box2">
<rich-text style="height: 80px;" :selectable="true"
:nodes="text"></rich-text>
</view>
</view>
</view>
......@@ -72,7 +72,7 @@
if (this.richTextElement != null) {
this.richTextElement!.getBoundingClientRectAsync()!.then((elRect: DOMRect) => {
this.richTextHeight = elRect.height
console.log('richTextHeight:', this.richTextHeight)
console.log('richTextHeight:', this.richTextHeight)
})
}
},
......@@ -83,9 +83,6 @@
getBoundingClientRectForTest() : DOMRect {
return uni.getElementById('test-rich-text')?.getBoundingClientRect()!;
},
getWindowInfoForTest() : GetWindowInfoResult {
return uni.getWindowInfo();
},
richTextParentClick() {
this.richTextStr = true;
}
......@@ -97,11 +94,11 @@
.text-box {
padding: 20px 0;
background-color: white;
}
.text-box2 {
top: 20px;
background-color: white;
}
}
.text-box2 {
top: 20px;
background-color: white;
}
</style>
const platformInfo = process.env.uniTestPlatformInfo.toLocaleLowerCase()
const isMP = platformInfo.startsWith('mp')
const isAndroid = platformInfo.startsWith('android')
const isIos = platformInfo.startsWith('ios')
const isHarmony = platformInfo.startsWith('harmony')
describe('component-native-sticky-header', () => {
......@@ -13,26 +11,12 @@ describe('component-native-sticky-header', () => {
}
let page
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')
}
const screenshotParams = { fullPage: true }
let windowInfo
const screenshotParams = { }
beforeAll(async () => {
if (!process.env.UNI_AUTOMATOR_APP_WEBVIEW) {
screenshotParams.fullPage = false
windowInfo = await getWindowInfo()
let offsetY = '0'
if (isAndroid) {
offsetY = `${windowInfo.statusBarHeight + 44}`
}
if (isIos) {
offsetY = `${windowInfo.safeAreaInsets.top + 44}`
}
screenshotParams.offsetY = offsetY
const windowInfo = await program.callUniMethod('getWindowInfo');
screenshotParams.offsetY = `${windowInfo.safeAreaInsets.top + 44}`
}
page = await program.reLaunch('/pages/component/sticky-header/sticky-header')
await page.waitFor('sticky-header')
......
......@@ -63,10 +63,10 @@ describe('text-props', () => {
}
const rect = await page.callMethod("getBoundingClientRectForTest")
const info = await page.callMethod("getWindowInfoForTest")
const windowInfo = await program.callUniMethod('getWindowInfo');
let x = Math.ceil(rect.left + rect.width / 2)
let y = Math.ceil(info.statusBarHeight + 44 + rect.top + rect.height / 2)
let y = Math.ceil(windowInfo.statusBarHeight + 44 + rect.top + rect.height / 2)
await program.tap({
x: x,
......
......@@ -207,9 +207,6 @@
getBoundingClientRectForTest() : DOMRect | null {
return uni.getElementById('nested-text2')?.getBoundingClientRect();
},
getWindowInfoForTest() : GetWindowInfoResult {
return uni.getWindowInfo();
},
nestedText1TapForTest() {
this.isNestedText1TapTriggered = true;
},
......
......@@ -276,18 +276,18 @@ describe('component-native-video', () => {
autoTest: false,
src: oldSrc
});
});
});
if (isAndroid) {
it('test sub component', async () => {
await page.setData({
subCompEnable: true,
subCompShow: true
});
await page.waitFor(100);
expect(await page.callMethod('hasSubComponent')).toBe(true);
});
}
if (isAndroid) {
it('test sub component', async () => {
await page.setData({
subCompEnable: true,
subCompShow: true
});
await page.waitFor(100);
expect(await page.callMethod('hasSubComponent')).toBe(true);
});
}
it('test enable-danmu', async () => {
await page.callMethod('play');
......@@ -295,12 +295,12 @@ describe('component-native-video', () => {
await page.setData({
enableDanmu: false
});
const info = await page.callMethod('getWindowInfo');
const windowInfo = await program.callUniMethod('getWindowInfo');
const image = await program.screenshot({
deviceShot: true,
area: {
x: 0,
y: info.statusBarHeight + 44
y: windowInfo.statusBarHeight + 44
}
});
expect(image).toSaveImageSnapshot();
......
......@@ -57,10 +57,10 @@ describe('component-native-web-view', () => {
});
if (!isHarmony) {
it('test touch event', async () => {
const info = await page.callMethod('getWindowInfo');
const windowInfo = await program.callUniMethod('getWindowInfo');
await program.tap({
x: 1,
y: info.statusBarHeight + 44 + 1
y: windowInfo.statusBarHeight + 44 + 1
});
await page.waitFor(500);
if (!isIOS) {
......@@ -74,7 +74,7 @@ describe('component-native-web-view', () => {
await page.waitFor(100);
await program.tap({
x: 10,
y: info.statusBarHeight + 44 + 10
y: windowInfo.statusBarHeight + 44 + 10
});
await page.waitFor(500);
if (!isIOS) {
......
......@@ -58,10 +58,10 @@
</view>
<!-- #endif -->
</view>
<!-- #endif -->
<!-- #ifdef APP-ANDROID || APP-IOS -->
<view class="safe-area-inset-bottom"></view>
<!-- #endif -->
<!-- #endif -->
<!-- #ifdef APP-ANDROID || APP-IOS -->
<view class="safe-area-inset-bottom"></view>
<!-- #endif -->
</view>
</template>
......@@ -92,25 +92,25 @@
eventLoad: null as UTSJSONObject | null,
eventError: null as UTSJSONObject | null,
pointerEvents: 'auto',
isTouchEnable: false,
updateTitle: true,
isTouchEnable: false,
updateTitle: true,
showController: true
}
},
onLoad(options: OnLoadOptions) {
if (typeof options['url'] === 'string' && options['url']!.length > 0) {
const src = decodeURIComponent(options['url'] as string)
if (src != null) {
this.src = src
this.showController = false
}
}
if (typeof options['title'] === 'string' && options['title']!.length > 0) {
this.updateTitle = false;
uni.setNavigationBarTitle({
title: options['title']!
});
}
},
onLoad(options: OnLoadOptions) {
if (typeof options['url'] === 'string' && options['url']!.length > 0) {
const src = decodeURIComponent(options['url'] as string)
if (src != null) {
this.src = src
this.showController = false
}
}
if (typeof options['title'] === 'string' && options['title']!.length > 0) {
this.updateTitle = false;
uni.setNavigationBarTitle({
title: options['title']!
});
}
},
onReady() {
// #ifdef APP
......@@ -230,9 +230,6 @@
this.isTouchEnable = event.clientX > 0 && event.clientY > 0;
}
},
getWindowInfo() : GetWindowInfoResult {
return uni.getWindowInfo();
},
//自动化测试专用
checkNativeWebView() : boolean {
// #ifdef APP
......@@ -253,9 +250,9 @@
.align-items-center {
align-items: center;
}
.safe-area-inset-bottom {
height: var(--uni-safe-area-inset-bottom);
}
.safe-area-inset-bottom {
height: var(--uni-safe-area-inset-bottom);
}
</style>
......@@ -361,12 +361,6 @@ if (isWeb) {
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')
}
function getWaitForTagName(pagePath) {
if (pagePath === '/pages/component/list-view/list-view-multiplex-input') {
return 'input'
......@@ -406,6 +400,7 @@ describe("page screenshot test", () => {
beforeAll(async () => {
console.log("page screenshot test start");
windowInfo = await program.callUniMethod('getWindowInfo');
});
beforeEach(async () => {
const currentPagePath = pages[pageIndex]
......@@ -427,19 +422,7 @@ describe("page screenshot test", () => {
fullPage
}
if (!fullPage && !isAppWebview) {
if (!windowInfo) {
windowInfo = await getWindowInfo()
page = await program.reLaunch(currentPagePath);
await page.waitFor(getWaitForTagName(currentPagePath));
}
let offsetY = '0'
if (isAndroid) {
offsetY = `${windowInfo.statusBarHeight + 44}`
}
if (isIos || isHarmony) {
offsetY = `${windowInfo.safeAreaInsets.top + 44}`
}
screenshotParams.offsetY = offsetY
screenshotParams.offsetY = isApp ? `${windowInfo.safeAreaInsets.top + 44}` : '0'
}
const image = await program.screenshot(screenshotParams);
......
// uni-app自动化测试教程: https://uniapp.dcloud.net.cn/worktile/auto/hbuilderx-extension/
const platformInfo = process.env.uniTestPlatformInfo.toLocaleLowerCase()
const isAppWebview = !!process.env.UNI_AUTOMATOR_APP_WEBVIEW
describe('template-list-news', () => {
let page;
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')
}
const screenshotParams = { fullPage: true }
let windowInfo
const screenshotParams = { }
beforeAll(async () => {
if (!process.env.UNI_AUTOMATOR_APP_WEBVIEW) {
screenshotParams.fullPage = false
windowInfo = await getWindowInfo()
let offsetY = '0'
if (process.env.uniTestPlatformInfo.toLocaleLowerCase().startsWith('android')) {
offsetY = `${windowInfo.statusBarHeight + 44}`
}
if (process.env.uniTestPlatformInfo.toLocaleLowerCase().startsWith('ios')) {
offsetY = `${windowInfo.safeAreaInsets.top + 44}`
}
screenshotParams.offsetY = offsetY
if (!isAppWebview) {
const windowInfo = await program.callUniMethod('getWindowInfo');
screenshotParams.offsetY = `${windowInfo.safeAreaInsets.top + 44}`
}
page = await program.reLaunch('/pages/template/list-news/list-news');
await page.waitFor(3000);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册