diag-page-state.js 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. /**
  2. * diag-page-state.js — 诊断:为什么 pageState() 判不出当前页面
  3. *
  4. * 用 `node tools/run.js --eval tools/diag-page-state.js` 跑。
  5. * 它只读不写,不会改变设备状态。
  6. */
  7. var l = TikTokAuto.layout;
  8. var t = TikTokAuto.tiktok;
  9. console.log('rootIsNull=' + (l.root() === null));
  10. console.log('fg=' + l.foregroundPackage());
  11. console.log('screen=' + JSON.stringify(l.screen()));
  12. console.log('state=' + t.pageState());
  13. console.log('onPlayerPage=' + t.onPlayerPage());
  14. console.log('tabStrip=' + t.resultTabStripPresent());
  15. console.log('bottomNav=' + t.bottomNavPresent());
  16. console.log('homeNode=' + (l.findOnce(desc('Home')) !== null));
  17. console.log('profileNode=' + (l.findOnce(desc('Profile')) !== null));
  18. console.log('searchEntryNull=' + (t.searchEntry() === null));
  19. var imgs = className('android.widget.ImageView').find();
  20. console.log('imageViewCount=' + imgs.size());
  21. for (var i = 0; i < imgs.size(); i += 1) {
  22. var node = imgs.get(i);
  23. if (l.desc(node) === 'Search') {
  24. console.log(' SearchImage visible=' + l.isVisible(node) +
  25. ' center=' + JSON.stringify(l.center(node)) +
  26. ' bounds=' + JSON.stringify(node.bounds()));
  27. }
  28. }
  29. var texts = className('android.widget.TextView').find();
  30. var bottomNavCandidates = [];
  31. for (var j = 0; j < texts.size(); j += 1) {
  32. var label = l.text(texts.get(j));
  33. if (label === 'Home' || label === 'Profile' || label === 'Inbox' || label === 'Friends') {
  34. bottomNavCandidates.push(label + '@' + JSON.stringify(texts.get(j).bounds()));
  35. }
  36. }
  37. console.log('bottomNavTextNodes=' + JSON.stringify(bottomNavCandidates));