- def open_app(self, msName, appName):
- """ open application from device by app name.
- Parameters: msName:AndroidPhone Android phone being tested.
- appName:Text Application name to be opened.
- Return: 1 if successful, else 0 2012-10-18
- """
- #Set phone screen size
- screen = basefuncInstance.screen_size(msName)
- screenX = screen[0]
- screenY = screen[1]
- #Scale
- homeIcon = int(screenY*0.925)
- addIconX = int(screenX*0.95)
- addIconY = int(screenY*0.09)
- leftX = int(screenX*0.1)
- rightX = int(screenX*0.9)
- midY = int(screenY*0.5)
- topY = int(screenY*0.2)
- bottomY = int(screenY*0.8)
- midX = int(screenX*0.5)
- appName = appName.lower()
- #Open app list and move to first page of app list
- if self.open_app_list(msName) == 0:
- return 0
- #Find target app
- Trace.Log(__name__, "-->Looking for %s app"%appName)
- originalStrings = MSAndroid.GetStrings(msName)
- originalStrings = originalStrings.lower()
- print originalStrings
- original = originalStrings.split(';')
- original_len = len(original)
- for i in range(0, original_len-1):
- app = original[i]
- print app
- apps = app.split(',')
- foundText = apps[0]
- print foundText
- if appName == foundText:
- foundText = apps
- print foundText
- break
- '''for app in original:
- apps = app.split(',')
- foundText = apps[0]
- print foundText
- if appName == foundText:
- foundText = apps
- print foundText
- break'''
- if appName != foundText[0]:
- input.click_and_drag(msName, rightX, midY, leftX, midY)
- currentStrings = MSAndroid.GetStrings(msName)
- currentStrings = currentStrings.lower()
- current = currentStrings.split(';')
- for i in range(0, len(current)-1):
- app = current[i]
- apps = app.split(',')
- foundText = apps[0]
- if appName == foundText:
- foundText = apps
- break
- startTime = time.time()
- while appName != foundText[0] and originalStrings.find(currentStrings)==-1 and currentStrings.find(originalStrings)==-1:
- originalStrings = currentStrings
- input.click_and_drag(msName, rightX, midY, leftX, midY)
- currentStrings = MSAndroid.GetStrings(msName)
- currentStrings = currentStrings.lower()
- for i in range(0, len(currentStrings)-1):
- app = currentStrings[i]
- apps = app.split(',')
- foundText = apps[0]
- if appName == foundText:
- foundText = apps
- break
- endTime = time.time()
- if (endTime - startTime) > 1800:
- Trace.Log(__name__, "Can't recognize current UI")
- return 0
- if appName != foundText[0]:
- Trace.Log(__name__, "Can't find application %s"%appName)
- return 0
- #launch app
- Trace.Log(__name__, "-->Launch %s"%appName)
- y = int(foundText[2])
- currentText = foundText[0]
- x = int(foundText[1])
- #make sure x, y is ok
- x += 2
- y += 2
- originalStrings = MSAndroid.GetStrings(msName)
- input.tap(msName, x, y, 100)
- currentStrings = self.wait_ui_change(msName, originalStrings)
- if currentStrings == 0:
- input.tap(msName, x, y, 100)
- currentStrings = self.wait_ui_change(msName, originalStrings)
- if currentStrings == 0:
- Trace.Log(__name__, "Can't find application %s"%appName)
- return 0
- return 1
- #该片段来自于http://www.codesnippet.cn/detail/030920135587.html
来源: http://www.codesnippet.cn/detail/030920135587.html