DevEco Testing Hypium是HarmonyOS平台的UI自动化测试框架,支持开发者使用Python语言为应用编写UI自动化测试脚本,主要包含以下特性:
参考窗口旋转说明,窗口旋转形态有以下四种,分别为顺时针方向旋转0度(竖屏),旋转90度(反向横屏),旋转270度(横屏),旋转180度(反向竖屏)。

# -*- coding: utf-8 -*- from devicetest.core.test_case import TestCase, Step from hypium import UiDriver class TC_001(TestCase): def __init__(self, configs): self.TAG = self.__class__.__name__ super().__init__(self.TAG, configs) self.driver = UiDriver(self.device1) self.driver_width, self.driver_height = self.driver.get_display_size() def setup(self): Step("预制条件") def process(self): Step("方法一:使用driver.get_display_size()方法获取当前屏幕的宽和高,当宽>高时,即为横屏,反之为竖屏。") # 获取当前屏幕尺寸 display = self.driver.get_display_size() # 屏幕宽度(像素) width = display[0] # 屏幕高度(像素) height = display[1] # 当屏幕宽度>屏幕高度,表示当前为横屏观看,否则为竖屏 if width > height: current_orientation = "landscape" else: current_orientation = "portrait" print(f"当前屏幕方向: {current_orientation}") Step("方法二:使用driver.get_display_rotation()方法获取当前手机方向") # 获取当前屏幕方向,正常横屏值为:DisplayRotation.ROTATION_270、DisplayRotation.ROTATION_90,竖屏为:DisplayRotation.ROTATION_0 current_orientation = self.driver.get_display_rotation() print(f"当前屏幕方向: {current_orientation}") def teardown(self): Step("收尾工作xxxx")