1/* 2 * Copyright (c) 2023 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16import { describe, beforeEach, it, beforeAll, expect } from '@ohos/hypium'; 17import { Driver, ON, } from '@ohos.UiTest'; 18import abilityDelegatorRegistry from '@ohos.app.ability.abilityDelegatorRegistry'; 19import hilog from '@ohos.hilog'; 20 21const TAG = '[Sample_Share_Test]'; 22const DOMAIN = 0xF811; 23const BUNDLE = 'Share_'; 24let delegator = abilityDelegatorRegistry.getAbilityDelegator(); 25let resourceManager = delegator.getAppContext().resourceManager; 26let driver = Driver.create(); 27let buttonId = 'shareLinkResource'; 28 29export default function shareTest() { 30 describe('ActsShareTest', () => { 31 beforeAll(async () => { 32 await driver.delayMs(500); 33 await driver.pressBack(); 34 await driver.delayMs(1000); 35 try { 36 await delegator.startAbility({ 37 bundleName: 'ohos.samples.customshare', 38 abilityName: 'MainAbility' 39 }); 40 } catch (expection) { 41 expect(0).assertEqual(expection.code); 42 hilog.info(DOMAIN, TAG, 'StartAbility end err:' + JSON.stringify(expection)); 43 } 44 await driver.delayMs(1500); 45 let btnAccept = await driver.findComponent(ON.text(await resourceManager.getStringValue($r('app.string.accept')))); 46 while (btnAccept !== null) { 47 await btnAccept.click(); 48 await driver.delayMs(500); 49 btnAccept = await driver.findComponent(ON.text(await resourceManager.getStringValue($r('app.string.accept')))); 50 hilog.info(DOMAIN, TAG, BUNDLE + 'Acts_ShareTemplate accept click success'); 51 } 52 }) 53 54 /* 55 * @tc.number: Acts_ShareTemplate_0100 56 * @tc.name: Test the ability to provide shared templates 57 * @tc.desc: Click the share button to jump to the interface, and then click the cancel button 58 */ 59 it('Acts_ShareTemplate_0100', 0, async (done: () => void) => { 60 hilog.info(DOMAIN, TAG, BUNDLE + 'Acts_ShareTemplate_0100 start'); 61 await driver.delayMs(500); 62 let button = await driver.findComponent(ON.id(buttonId)); 63 await button.click(); 64 await driver.delayMs(500); 65 let buttons = await driver.findComponent(ON.id('cancellation')); 66 await buttons.click(); 67 await driver.delayMs(500); 68 hilog.info(DOMAIN, TAG, BUNDLE + 'Acts_ShareTemplate_0100 assert button exist by id: ' + buttonId); 69 await driver.assertComponentExist(ON.id(buttonId)); 70 hilog.info(DOMAIN, TAG, BUNDLE + 'Acts_ShareTemplate_0100 end'); 71 done(); 72 }) 73 74 /* 75 * @tc.number: Acts_ShareTemplate_0200 76 * @tc.name: Test the ability to provide shared templates 77 * @tc.desc: Click on the share button to jump to the interface, then click on the share demo to jump to the 78 * interface, and then click on the return to share button 79 */ 80 it('Acts_ShareTemplate_0200', 0, async (done: () => void) => { 81 hilog.info(DOMAIN, TAG, BUNDLE + 'Acts_ShareTemplate_0200 start'); 82 await driver.delayMs(1000); 83 let button = await driver.findComponent(ON.id(buttonId)); 84 await button.click(); 85 await driver.delayMs(1000); 86 87 let textShare = await driver.findComponent(ON.text(await resourceManager.getStringValue($r('app.string.text')))); 88 let rect = await textShare.getBounds(); 89 let height =rect.bottom - rect.top; 90 let point = await textShare.getBoundsCenter(); 91 await driver.click(point.x, point.y - height); 92 await driver.delayMs(1000); 93 94 let turnBack = await driver.findComponent(ON.id('return')); 95 await turnBack.click(); 96 await driver.delayMs(1000); 97 hilog.info(DOMAIN, TAG, BUNDLE + 'Acts_ShareTemplate_0100 assert button exist by id: ' + buttonId); 98 await driver.assertComponentExist(ON.id(buttonId)); 99 hilog.info(DOMAIN, TAG, BUNDLE + 'Acts_ShareTemplate_0200 end'); 100 done(); 101 }) 102 103 /* 104 * @tc.number: Acts_ShareTemplate_0300 105 * @tc.name: Test the ability to provide shared templates 106 * @tc.desc: Click the share button to jump to the interface, then click the share demonstration to jump to 107 * the interface, and then click to stay in the shared text 108 */ 109 it('Acts_ShareTemplate_0300', 0, async (done: () => void) => { 110 hilog.info(DOMAIN, TAG, BUNDLE + 'Acts_ShareTemplate_0300 start'); 111 await driver.delayMs(1000); 112 let button = await driver.findComponent(ON.id(buttonId)); 113 await button.click(); 114 await driver.delayMs(1000); 115 116 let textShare = await driver.findComponent(ON.text(await resourceManager.getStringValue($r('app.string.text')))); 117 let rect = await textShare.getBounds(); 118 let height =rect.bottom - rect.top; 119 let point = await textShare.getBoundsCenter(); 120 await driver.click(point.x, point.y - height); 121 await driver.delayMs(1000); 122 123 let stay = await driver.findComponent(ON.id('stay')); 124 await stay.click(); 125 await driver.delayMs(1000); 126 hilog.info(DOMAIN, TAG, BUNDLE + 'Acts_ShareTemplate_0300 assert message exist: It is a shared message'); 127 await driver.assertComponentExist(ON.id('messages')); 128 await driver.pressBack(); 129 await driver.delayMs(1000); 130 hilog.info(DOMAIN, TAG, BUNDLE + 'Acts_ShareTemplate_0300 end'); 131 done(); 132 }) 133 134 it('Acts_ShareTemplate_0400', 0, async (done: () => void) => { 135 hilog.info(DOMAIN, TAG, BUNDLE + 'Acts_ShareTemplate_0400 start'); 136 await driver.delayMs(1000); 137 let button = await driver.findComponent(ON.id(buttonId)); 138 await button.click(); 139 await driver.delayMs(1000); 140 // 点击文本编辑 141 let textShare = await driver.findComponent(ON.text(await resourceManager.getStringValue($r('app.string.edit')))); 142 let rect = await textShare.getBounds(); 143 let height = rect.bottom - rect.top; 144 let point = await textShare.getBoundsCenter(); 145 await driver.click(point.x, point.y - height); 146 await driver.delayMs(3000); 147 // 点击返回 148 let turnBack = await driver.findComponent(ON.id('returnShare')); 149 await turnBack.click(); 150 await driver.delayMs(1000); 151 hilog.info(DOMAIN, TAG, BUNDLE + 'Acts_ShareTemplate_0400 assert button exist by id: ' + buttonId); 152 await driver.assertComponentExist(ON.id(buttonId)); 153 hilog.info(DOMAIN, TAG, BUNDLE + 'Acts_ShareTemplate_0400 end'); 154 done(); 155 }) 156 157 /* 158 * @tc.number: Acts_ShareTemplate_0400 159 * @tc.name: Test the ability to provide shared templates 160 * @tc.desc: Click the share button to jump to the interface, then click the share demonstration to jump to 161 * the interface, and then click to stay in the share editing mode 162 */ 163 it('Acts_ShareTemplate_0500', 0, async (done: () => void) => { 164 hilog.info(DOMAIN, TAG, BUNDLE + 'Acts_ShareTemplate_0500 start'); 165 await driver.delayMs(1000); 166 let button = await driver.findComponent(ON.id(buttonId)); 167 await button.click(); 168 await driver.delayMs(1000); 169 170 let textShare = await driver.findComponent(ON.text(await resourceManager.getStringValue($r('app.string.edit')))); 171 let rect = await textShare.getBounds(); 172 let height =rect.bottom - rect.top; 173 let point = await textShare.getBoundsCenter(); 174 await driver.click(point.x, point.y - height); 175 await driver.delayMs(1000); 176 177 let stay = await driver.findComponent(ON.id('stay')); 178 await stay.click(); 179 await driver.delayMs(1000); 180 hilog.info(DOMAIN, TAG, BUNDLE + 'Acts_ShareTemplate_0500 assert messagesTextArea exist by id: messagesTextArea'); 181 await driver.assertComponentExist(ON.id('messagesTextArea')); 182 hilog.info(DOMAIN, TAG, BUNDLE + 'Acts_ShareTemplate_0500 end'); 183 done(); 184 }) 185 }) 186}