fix: 识别失效商品链接返回首页 (#111)
This commit is contained in:
@@ -35,6 +35,7 @@ class FakeCollectDevice:
|
||||
self.swipes = []
|
||||
self.swipe_panel_states = []
|
||||
self.app_wait_calls = 0
|
||||
self.opened_url = None
|
||||
|
||||
def app_current(self):
|
||||
return {"package": "com.xunmeng.pinduoduo"}
|
||||
@@ -50,6 +51,8 @@ class FakeCollectDevice:
|
||||
self.opened_url = url
|
||||
|
||||
def dump_hierarchy(self):
|
||||
if self.opened_url is None:
|
||||
return '<hierarchy><node package="com.xunmeng.pinduoduo" /></hierarchy>'
|
||||
return self.spec_xml if self.panel_open else self.home_xml
|
||||
|
||||
def click(self, x, y):
|
||||
@@ -71,6 +74,8 @@ class GoodsMetadataScrollDevice(FakeCollectDevice):
|
||||
self.page_index = 0
|
||||
|
||||
def dump_hierarchy(self):
|
||||
if self.opened_url is None and not self.panel_open:
|
||||
return super().dump_hierarchy()
|
||||
if self.panel_open:
|
||||
return self.spec_xml
|
||||
return self.pages[self.page_index]
|
||||
@@ -133,6 +138,8 @@ class SnakeColorDevice(FakeCollectDevice):
|
||||
self.clicked_colors = []
|
||||
|
||||
def dump_hierarchy(self):
|
||||
if self.opened_url is None and not self.panel_open:
|
||||
return super().dump_hierarchy()
|
||||
if not self.panel_open:
|
||||
return self.home_xml
|
||||
return self._spec_xml()
|
||||
@@ -794,6 +801,28 @@ class PddCollectParserTest(unittest.TestCase):
|
||||
)
|
||||
self.assertEqual(raised.exception.code, "PDD_PAGE_TIMEOUT")
|
||||
|
||||
def test_stable_home_reopens_once_then_stops_before_spec_click(self):
|
||||
home = (FIXTURES / "pdd_home_page.xml").read_text(encoding="utf-8")
|
||||
device = FakeCollectDevice(home, self.spec_xml)
|
||||
clock = FakeClock()
|
||||
service = PddCollectService(
|
||||
PddDeviceService(lambda _serial: device),
|
||||
"USB-001",
|
||||
"client-001",
|
||||
sleeper=clock.sleep,
|
||||
monotonic=clock.monotonic,
|
||||
page_timeout=10.0,
|
||||
)
|
||||
|
||||
with self.assertRaises(PddCollectError) as raised:
|
||||
service.collect(
|
||||
FakeTask("https://mobile.yangkeduo.com/goods.html?goods_id=123")
|
||||
)
|
||||
|
||||
self.assertEqual("PDD_GOODS_UNAVAILABLE", raised.exception.code)
|
||||
self.assertEqual(2, raised.exception.diagnostics["open_attempts"])
|
||||
self.assertEqual([], device.clicks)
|
||||
|
||||
def test_non_pdd_tree_with_purchase_words_is_not_ready(self):
|
||||
device = FocusMismatchDevice(
|
||||
'<hierarchy><node package="com.android.settings" text="免拼购买" '
|
||||
@@ -819,13 +848,13 @@ class PddCollectParserTest(unittest.TestCase):
|
||||
def test_page_timeout_saves_last_xml_diagnostic(self):
|
||||
with tempfile.TemporaryDirectory() as directory:
|
||||
device = LoadingDevice(self.home_xml, self.spec_xml)
|
||||
ticks = iter((0.0, 0.0, 0.0, 0.0, 0.0, 2.0))
|
||||
clock = FakeClock()
|
||||
service = PddCollectService(
|
||||
PddDeviceService(lambda _serial: device),
|
||||
"USB-001",
|
||||
"client-001",
|
||||
sleeper=lambda _seconds: None,
|
||||
monotonic=lambda: next(ticks),
|
||||
sleeper=clock.sleep,
|
||||
monotonic=clock.monotonic,
|
||||
page_timeout=1.0,
|
||||
artifact_directory=Path(directory),
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user