【发布时间】:2014-02-26 17:59:23
【问题描述】:
目前我想实现一个只打开我的移动应用程序的关键字,用于在移动平台上自动执行我的测试。我做了如下,
def open_app_from_homescreen(app_name):
""" Opens application from homescreen
@precondition:Be on the homescreen of the device
@param app_name: name of the application to open """
try:
if case =='App1' and app_name is not None:
_Ui.application.openApplication("App1")
elif case == 'App2' and app_name is not None:
_Ui.application.openApplication("App2")
elif case == 'App3' and app_name is not None:
_Ui.application.openApplication("App3")
elif case == 'App4' and app_name is not None:
_Ui.application.openApplication("App4")
else:
StepLogger.post_sub_step("No application name provided")
except Exception as e:
print_error("Failed to open Application" + app_name)
我有数百个移动应用程序要使用此关键字进行检查。这里也需要考虑性能。除了使用 if-elif,我还觉得使用字典可以完成我的工作,但我正在寻找一种更乐观的方法。 基本上我想在我的场景中实现一种 switch-case 类型的功能。
我有一个使用类的想法,不知道如何继续。
【问题讨论】:
标签: python frameworks automation switch-statement