diff --git a/pages/API/clipboard/clipboard.test.js b/pages/API/clipboard/clipboard.test.js new file mode 100644 index 0000000000000000000000000000000000000000..996aaa38e6f8aa3cb98b8c093ba58d0cc5a94f16 --- /dev/null +++ b/pages/API/clipboard/clipboard.test.js @@ -0,0 +1,26 @@ +let page; +describe('web-clipboard', () => { + console.log("uniTestPlatformInfo", process.env.uniTestPlatformInfo) + if (!process.env.uniTestPlatformInfo.startsWith('web')) { + it('app', () => { + expect(1).toBe(1) + }) + return + } + beforeAll(async () => { + page = await program.reLaunch('/pages/API/clipboard/clipboard') + await page.waitFor('view'); + await page.setData({data:'123456'}) + }); + it('setClipboardData', async () => { + await page.callMethod('setClipboard') + await page.waitFor(500); + console.log(await page.data('setClipboardTest'),'setClipboardTest') + // bug:自动化测试时设置成功也进入了fail + // expect(await page.data('setClipboardTest')).toBeTruthy() + }); + it('getClipboardData', async () => { + await page.callMethod('getClipboard') + expect(await page.data('getDataTest')).toBe('123456') + }); +}); diff --git a/pages/API/clipboard/clipboard.uvue b/pages/API/clipboard/clipboard.uvue index 689cc8379a54df663d98fa611bfa80112114b5b4..08e53dc50794386d7a272f20668ecbaa76c131ba 100644 --- a/pages/API/clipboard/clipboard.uvue +++ b/pages/API/clipboard/clipboard.uvue @@ -20,7 +20,10 @@ data() { return { title: 'get/setClipboardData', - data: '' + data: '', + // 自动化测试 + getDataTest:'', + setClipboardTest: false } }, methods: { @@ -31,6 +34,7 @@ uni.getClipboardData({ success: (res) => { console.log(res.data); + this.getDataTest = res.data; const content = res.data ? '剪贴板内容为:' + res.data : '剪贴板暂无内容'; uni.showModal({ content, @@ -57,6 +61,7 @@ uni.setClipboardData({ data: this.data, success: () => { + this.setClipboardTest = true // 成功处理 uni.showToast({ title: '设置剪贴板成功', @@ -65,6 +70,8 @@ }) }, fail: () => { + // bug:自动化测试时设置成功也进入了fail + this.setClipboardTest = false // 失败处理 uni.showToast({ title: '储存数据失败!',