fix: 收窄颜色方向识别范围 (#264)
This commit is contained in:
@@ -60,10 +60,12 @@ class ScrollColorDevice:
|
||||
direction: str,
|
||||
target: str = "目标白色",
|
||||
include_target: bool = True,
|
||||
polluted: bool = False,
|
||||
) -> None:
|
||||
self.direction = direction
|
||||
self.target = target
|
||||
self.include_target = include_target
|
||||
self.polluted = polluted
|
||||
self.page = 0
|
||||
self.selected = False
|
||||
self.clicks = []
|
||||
@@ -104,14 +106,23 @@ class ScrollColorDevice:
|
||||
container = ''.join(options)
|
||||
|
||||
summary = f"已选:{self.target}" if self.selected else "请选择:颜色 尺码"
|
||||
return f'''<hierarchy>
|
||||
<node bounds="[0,0][1080,2340]">
|
||||
<node class="android.widget.ScrollView" scrollable="true"
|
||||
panel = f'''<node class="android.widget.ScrollView" scrollable="true"
|
||||
bounds="[0,945][1080,2079]">
|
||||
<node text="{summary}" bounds="[36,950][800,1000]" />
|
||||
<node text="颜色 (14)" bounds="[36,971][216,1024]" />
|
||||
{container}
|
||||
</node>'''
|
||||
if self.polluted:
|
||||
panel = f'''<node clickable="true" bounds="[0,120][1080,2328]">
|
||||
<node clickable="true" bounds="[0,366][1080,2328]">
|
||||
{panel}
|
||||
</node>
|
||||
</node>
|
||||
<node text="悬浮操作" clickable="true"
|
||||
bounds="[936,980][1080,1124]" />'''
|
||||
return f'''<hierarchy>
|
||||
<node bounds="[0,0][1080,2340]">
|
||||
{panel}
|
||||
</node>
|
||||
</hierarchy>'''
|
||||
|
||||
@@ -332,6 +343,26 @@ class StaticColorSelectionTest(unittest.TestCase):
|
||||
)
|
||||
)
|
||||
|
||||
def test_external_clickables_do_not_pollute_vertical_direction(self):
|
||||
device = ScrollColorDevice("vertical", polluted=True)
|
||||
|
||||
selected = select_color(
|
||||
device,
|
||||
device.dump_hierarchy(),
|
||||
device.target,
|
||||
action_delay=0.001,
|
||||
)
|
||||
|
||||
self.assertTrue(selected)
|
||||
self.assertEqual(len(device.clicks), 1)
|
||||
self.assertTrue(device.swipes)
|
||||
self.assertTrue(
|
||||
all(
|
||||
abs(y2 - y1) > abs(x2 - x1)
|
||||
for x1, y1, x2, y2, _duration in device.swipes
|
||||
)
|
||||
)
|
||||
|
||||
def test_horizontal_color_list_keeps_horizontal_scan(self):
|
||||
device = ScrollColorDevice("horizontal")
|
||||
|
||||
|
||||
Reference in New Issue
Block a user