使用appium做自动化时怎么切换activity
1个回答
2016-12-27 · 知道合伙人数码行家
huanglenzhi
知道合伙人数码行家
向TA提问 私信TA
知道合伙人数码行家
采纳数:117538
获赞数:517201
长期从事计算机组装,维护,网络组建及管理。对计算机硬件、操作系统安装、典型网络设备具有详细认知。
向TA提问 私信TA
关注
展开全部
如果仅需要切换一次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
如果需要多次切换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
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询