1 /* 2 * Copyright (c) 2021 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 16 package ohos.devtools.fixture; 17 18 import ohos.devtools.datasources.databases.databaseapi.DataBaseApi; 19 import ohos.devtools.datasources.utils.device.service.MultiDeviceManager; 20 import ohos.devtools.datasources.utils.plugin.IPluginConfig; 21 import ohos.devtools.datasources.utils.plugin.service.PlugManager; 22 import ohos.devtools.datasources.utils.process.service.ProcessManager; 23 import ohos.devtools.datasources.utils.profilerlog.ProfilerLogManager; 24 import ohos.devtools.datasources.utils.session.service.SessionManager; 25 import ohos.devtools.pluginconfig.AgentConfig; 26 import ohos.devtools.pluginconfig.BytraceConfig; 27 import ohos.devtools.pluginconfig.CpuConfig; 28 import ohos.devtools.pluginconfig.DiskIoConfig; 29 import ohos.devtools.pluginconfig.FtraceConfig; 30 import ohos.devtools.pluginconfig.HilogConfig; 31 import ohos.devtools.pluginconfig.MemoryConfig; 32 import ohos.devtools.pluginconfig.ProcessConfig; 33 import ohos.devtools.pluginconfig.UserConfig; 34 import ohos.devtools.views.common.UtConstant; 35 import ohos.devtools.views.layout.HomePanel; 36 import ohos.devtools.views.user.UserManager; 37 import org.apache.logging.log4j.Level; 38 import org.assertj.swing.fixture.FrameFixture; 39 import org.junit.After; 40 import org.junit.Before; 41 import org.junit.Test; 42 43 import javax.swing.JFrame; 44 import java.awt.AWTException; 45 import java.util.ArrayList; 46 import java.util.List; 47 import java.util.Objects; 48 import java.util.concurrent.TimeUnit; 49 50 /** 51 * stop and restart Button Fixture Test 52 * 53 * @since 2021/2/1 9:31 54 */ 55 public class RestartButtonFixtureTest { 56 private FrameFixture frameFixture; 57 58 /** 59 * init 60 * 61 * @tc.name: init 62 * @tc.number: OHOS_JAVA_init_0001 63 * @tc.desc: init 64 * @tc.type: functional testing 65 * @tc.require: AR000FK5UI 66 * @throws AWTException AWTException 67 */ 68 @Before init()69 public void init() throws AWTException { 70 // Initialization data 71 ProcessManager.getInstance().setIsRequest(false); 72 SessionManager.getInstance().settingPermissions(); 73 ProfilerLogManager.getSingleton().updateLogLevel(Level.ERROR); 74 PlugManager.getInstance().unzipStdDevelopTools(); 75 DataBaseApi.getInstance().initDataSourceManager(); 76 MultiDeviceManager.getInstance().start(); 77 List<Class<? extends IPluginConfig>> plugConfigList = new ArrayList(); 78 plugConfigList.add(ProcessConfig.class); 79 plugConfigList.add(AgentConfig.class); 80 plugConfigList.add(BytraceConfig.class); 81 plugConfigList.add(FtraceConfig.class); 82 plugConfigList.add(CpuConfig.class); 83 plugConfigList.add(HilogConfig.class); 84 if (Objects.nonNull(UserManager.getInstance().getSdkImpl())) { 85 plugConfigList.add(UserConfig.class); 86 } 87 plugConfigList.add(DiskIoConfig.class); 88 plugConfigList.add(MemoryConfig.class); 89 PlugManager.getInstance().loadingPlugs(plugConfigList); 90 while (true) { 91 if (MultiDeviceManager.getInstance().getOnlineDeviceInfoList().size() > 0) { 92 break; 93 } 94 } 95 JFrame frame = new JFrame(); 96 frame.add(new HomePanel()); 97 frameFixture = new FrameFixture(frame); 98 // Display the frame 99 frameFixture.show(); 100 } 101 102 /** 103 * test Window 104 * 105 * @tc.name: testWindow 106 * @tc.number: OHOS_JAVA_testWindow_0001 107 * @tc.desc: test Window 108 * @tc.type: test Window 109 * @tc.require: AR000FK5UI 110 * @throws InterruptedException InterruptedException 111 */ 112 @Test testWindow()113 public void testWindow() throws InterruptedException { 114 frameFixture.label(UtConstant.UT_WELCOME_PANEL_NEW_TASK_BTN).click(); 115 frameFixture.label(UtConstant.UT_TASK_PANEL_APPLICATION).click(); 116 frameFixture.button(UtConstant.UT_TASK_PANEL_CHOOSE).requireText(UtConstant.UT_TASK_PANEL_CHOOSE); 117 frameFixture.button(UtConstant.UT_TASK_PANEL_CHOOSE).click(); 118 TimeUnit.SECONDS.sleep(5); 119 frameFixture.button(UtConstant.UT_TASK_SCENE_PANE_START).click(); 120 TimeUnit.SECONDS.sleep(15); 121 // Session management, stop run 122 frameFixture.button(UtConstant.UT_TASK_SCENE_PANEL_CHART_RUN_BUTTON).click(); 123 TimeUnit.SECONDS.sleep(2); 124 frameFixture.button(UtConstant.UT_TASK_SCENE_PANEL_CHART_RUN_BUTTON).click(); 125 TimeUnit.SECONDS.sleep(5); 126 // Close the main interface 127 frameFixture.panel(UtConstant.UT_TASK_PANEL_CLOSE).click(); 128 SessionManager.getInstance().stopAllSession(); 129 } 130 131 /** 132 * tear Down 133 * 134 * @tc.name: tearDown 135 * @tc.number: OHOS_JAVA_tearDown_0001 136 * @tc.desc: tear Down 137 * @tc.type: test Window 138 * @tc.require: AR000FK5UI 139 */ 140 @After tearDown()141 public void tearDown() { 142 frameFixture.close(); 143 frameFixture.cleanUp(); 144 } 145 } 146