• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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.Assert;
41 import org.junit.Before;
42 import org.junit.Test;
43 
44 import javax.swing.JFrame;
45 import java.awt.AWTException;
46 import java.util.ArrayList;
47 import java.util.List;
48 import java.util.Objects;
49 import java.util.concurrent.TimeUnit;
50 
51 /**
52  * Switch button between heap dump and chart
53  *
54  *  @since 2021/2/1 9:31
55  */
56 public class SwitchButtonFixtureTest {
57     private FrameFixture frameFixture;
58     private final String PROCESS_NAME = "agenttest";
59 
60     /**
61      * init
62      *
63      * @tc.name: init
64      * @tc.number: OHOS_JAVA_init_0001
65      * @tc.desc: init
66      * @tc.type: functional testing
67      * @tc.require: AR000FK5UI
68      * @throws AWTException AWTException
69      */
70     @Before
init()71     public void init() throws AWTException {
72         // Initialization data
73         ProcessManager.getInstance().setIsRequest(false);
74         SessionManager.getInstance().settingPermissions();
75         ProfilerLogManager.getSingleton().updateLogLevel(Level.ERROR);
76         PlugManager.getInstance().unzipStdDevelopTools();
77         DataBaseApi.getInstance().initDataSourceManager();
78         MultiDeviceManager.getInstance().start();
79         List<Class<? extends IPluginConfig>> plugConfigList = new ArrayList();
80         plugConfigList.add(ProcessConfig.class);
81         plugConfigList.add(AgentConfig.class);
82         plugConfigList.add(BytraceConfig.class);
83         plugConfigList.add(FtraceConfig.class);
84         plugConfigList.add(CpuConfig.class);
85         plugConfigList.add(HilogConfig.class);
86         if (Objects.nonNull(UserManager.getInstance().getSdkImpl())) {
87             plugConfigList.add(UserConfig.class);
88         }
89         plugConfigList.add(DiskIoConfig.class);
90         plugConfigList.add(MemoryConfig.class);
91         PlugManager.getInstance().loadingPlugs(plugConfigList);
92         while (true) {
93             if (MultiDeviceManager.getInstance().getOnlineDeviceInfoList().size() > 0) {
94                 break;
95             }
96         }
97         JFrame frame = new JFrame();
98         frame.add(new HomePanel());
99         frameFixture = new FrameFixture(frame);
100         // Display the frame
101         frameFixture.show();
102     }
103 
104     /**
105      * test Window
106      *
107      * @tc.name: testWindow
108      * @tc.number: OHOS_JAVA_testWindow_0001
109      * @tc.desc: test Window
110      * @tc.type: test Window
111      * @tc.require: AR000FK5UI
112      * @throws InterruptedException InterruptedException
113      */
114     @Test
testWindow()115     public void testWindow() throws InterruptedException {
116         frameFixture.label(UtConstant.UT_WELCOME_PANEL_NEW_TASK_BTN).click();
117         frameFixture.label(UtConstant.UT_TASK_PANEL_APPLICATION).click();
118         frameFixture.button(UtConstant.UT_TASK_PANEL_CHOOSE).requireText(UtConstant.UT_TASK_PANEL_CHOOSE);
119         frameFixture.button(UtConstant.UT_TASK_PANEL_CHOOSE).click();
120         TimeUnit.SECONDS.sleep(5);
121         // Monitoring process display
122         frameFixture.comboBox(UtConstant.UT_DEVICE_PROCESS_PANEL_DEVICE_NAME).click();
123         frameFixture.textBox(UtConstant.UT_DEVICE_PROCESS_PANEL_PROCESS_NAME + "1").click();
124         TimeUnit.SECONDS.sleep(5);
125         frameFixture.textBox(UtConstant.UT_DEVICE_PROCESS_PANEL_SEARCH_FIELD).setText(PROCESS_NAME);
126         frameFixture.list(UtConstant.UT_DEVICE_PROCESS_PANEL_TABLE + "1").selectItem(0);
127         String processName = frameFixture.textBox(UtConstant.UT_DEVICE_PROCESS_PANEL_PROCESS_NAME + "1").text();
128         Assert.assertTrue(processName.contains("agenttest"));
129         frameFixture.button(UtConstant.UT_TASK_SCENE_PANE_START).click();
130         TimeUnit.SECONDS.sleep(15);
131         // Graphic display Category display
132         frameFixture.label(UtConstant.UT_MEMORY_ITEM_VIEW_FOLD).click();
133         // heap dump
134         frameFixture.label(UtConstant.UT_MEMORY_ITEM_VIEW_HEAP_DUMP).click();
135         TimeUnit.SECONDS.sleep(30);
136         frameFixture.label(UtConstant.UT_TASK_SCENE_PANEL_CHART_SESSION_MANAGE).click();
137         TimeUnit.SECONDS.sleep(2);
138         // Close the main interface
139         frameFixture.panel(UtConstant.UT_TASK_PANEL_CLOSE).click();
140         SessionManager.getInstance().stopAllSession();
141     }
142 
143     /**
144      * tear Down
145      *
146      * @tc.name: tearDown
147      * @tc.number: OHOS_JAVA_tearDown_0001
148      * @tc.desc: tear Down
149      * @tc.type: test Window
150      * @tc.require: AR000FK5UI
151      */
152     @After
tearDown()153     public void tearDown() {
154         frameFixture.close();
155         frameFixture.cleanUp();
156     }
157 }
158