在使用appium过程中遇到了执行一个用例时有多个不同的acitivity的情况,以下为app内部切换acitivity的方法:

 

如果仅需要切换一次activity,可以通过设置desired_caps['appWaitActivity'] = 'xxxxxx'来实现。

 

如果需要多次切换activity,则通过webdriver中的wait_activity()方法来实现。

 

wait_activity():

 1 def wait_activity(self, activity, timeout, interval=1):
 2         """Wait for an activity: block until target activity presents
 3         or time out.
 4 
 5         This is an Android-only method.
 6 
 7         :Agrs:
 8          - activity - target activity
 9          - timeout - max wait time, in seconds
10          - interval - sleep interval between retries, in seconds
11         """
12         try:
13             WebDriverWait(self, timeout, interval).until(
14                 lambda d: d.current_activity == activity)
15             return True
16         except TimeoutException:
17             return False

 

相关文章:

  • 2022-12-23
  • 2021-05-13
  • 2021-10-24
  • 2022-01-01
  • 2022-12-23
  • 2021-08-27
  • 2021-09-15
  • 2022-12-23
猜你喜欢
  • 2021-12-01
  • 2021-12-14
  • 2021-06-09
  • 2021-07-30
  • 2021-11-26
相关资源
相似解决方案