app ui 自动化,知识碎片


获取APP页面源码并写入一个XML文件
  page_source=driver.page_source
  with open("data.xml","w") as f:
    f.writelines(page_source)

将UTC时间转换为指定格式时间 localtime()
  timeStruct = time.localtime(os.path.getmtime(oldname))
  print timeStruct
  print time.strftime('%Y-%m-%d %H:%M:%S',timeStruct)
输出python日志
  stdout_backup = sys.stdout
  log_file = open("message.log", "w")
  sys.stdout = log_file
  print u'输出这一段的print内容到message.log里'
  print u'这里就是日志的内容!'
  log_file.close()
  sys.stdout = stdout_backup

开关WiFi 和 移动数据网络

  ***参数需要修改
  Turn on wifi - adb shell am start -n io.appium.settings/.Settings -e wifi on
  Turn off WiFi - adb shell am start -n io.appium.settings/.Settings -e wifi off
  Turn on mobile data - adb shell am start -n io.appium.settings/.Settings -e data on
  Turn off mobile data - adb shell am start -n io.appium.settings/.Settings -e data off

adb命令手机屏幕截图

  os.popen('adb -s %s shell am start -n io.appium.settings/.Settings -e wifi off'%self.conName)
  os.popen('adb -s %s shell screencap -p /sdcard/app_%s.png'%(self.conname,time))
  path=task_path+'\\app_%s.png'%time
  os.popen("adb -s %s pull /sdcard/app_%s.png %s"%(self.conname,time,path))
  os.popen('adb -s %s shell rm /sdcard/app_%s.png'%(self.conname,time))
  // 广播,告知其他应用有图片更新

  os.popen('adb -s %s shell am broadcast -a android.intent.action.MEDIA_SCANNER_SCAN_FILE -d file:///storage/emulated/0/app_%s.png'%(self.conname,time))

 

NULL ...

 

posted @ 2019-01-25 18:32  天际流云  阅读(285)  评论(0编辑  收藏  举报