Beispiel #1
0
 def _launchApp(self, action):
     '''
     :param action:
     :return:
     '''
     parms = self._getParms(action, 0)
     DriverBaseApp.launch_app(parms)
Beispiel #2
0
    def _init_config(self):

        self._config = analytical_file(os.path.join(Var.root, 'config.yaml'))
        Var.driver = self._config.driver
        Var.re_start = self._config.reStart
        Var.save_screenshot = self._config.saveScreenshot
        Var.time_out = self._config.timeOut
        Var.test_case = self._config.testcase
        Var.desired_caps = Dict()
        for configK, configV in self._config.desiredCapabilities.items():
            Var.desired_caps[configK] = configV

        if not Var.driver or Var.driver.lower() not in [
                'appium', 'macaca', 'selenium'
        ]:
            raise ValueError(
                'Missing/incomplete configuration file: config.yaml, No driver type specified.'
            )

        if not Var.time_out or not isinstance(Var.time_out, int):
            Var.time_out = 10

        if Var.driver != 'selenium':
            if not Var.desired_caps.platformName:
                raise ValueError(
                    'Missing/incomplete configuration file: config.yaml, No platformName type specified.'
                )
            DriverBaseApp.init()
        else:
            if not Var.desired_caps.browser or Var.desired_caps.browser not in [
                    'chrome', 'safari', 'firefox', 'ie', 'opera', 'phantomjs'
            ]:
                raise ValueError('browser parameter is illegal!')
Beispiel #3
0
 def _adb(self, action):
     '''
     :param action:
     :return:
     '''
     parms = self._getParms(action, 0)
     DriverBaseApp.adb_shell(parms)
Beispiel #4
0
 def _swipe(self, action):
     '''
     :param action:
     :return:
     '''
     parms_fx = self._getParms(action, 0)
     parms_fy = self._getParms(action, 1, ignore=True)
     parms_tx = self._getParms(action, 2, ignore=True)
     parms_ty = self._getParms(action, 3, ignore=True)
     parms_s = self._getParms(action, 4, ignore=True)
     try:
         if len(action.parms) == 1:
             swipe_f = getattr(DriverBaseApp,
                               'swipe_{}'.format(parms_fx.lower()))
             swipe_f()
         elif len(action.parms) == 2:
             swipe_f = getattr(DriverBaseApp,
                               'swipe_{}'.format(parms_fx.lower()))
             swipe_f(parms_fy)
         elif len(action.parms) == 4:
             DriverBaseApp.swipe(parms_fx, parms_fy, parms_tx, parms_ty)
         elif len(action.parms) == 5:
             DriverBaseApp.swipe(parms_fx, parms_fy, parms_tx, parms_ty,
                                 parms_s)
         else:
             raise
     except:
         raise TypeError(
             'swipe takes 1 positional argument but {} were giver'.format(
                 len(action.step)))
Beispiel #5
0
 def _uninstallApp(self, action):
     '''
     :param action:
     :return:
     '''
     parms = self._getParms(action, 0)
     DriverBaseApp.uninstall_app(parms)
Beispiel #6
0
 def setUp(self):
     if self.skip:
         self.skipTest('skip')
     if Var.re_start:
         if Var.driver != 'selenium':
             DriverBaseApp.launch_app(None)
         else:
             DriverBaseWeb.createSession()
Beispiel #7
0
 def _doubleTap(self, action):
     '''
     :param action:
     :return:
     '''
     parms_x = self._getParms(action, 0)
     parms_y = self._getParms(action, 1)
     DriverBaseApp.double_tap(parms_x, parms_y)
Beispiel #8
0
 def _input(self, action):
     '''
     :param action:
     :return:
     '''
     text = self._getParms(action, 1)
     element = self._getElement(action)
     DriverBaseApp.input(element, text)
Beispiel #9
0
 def tearDown(self):
     if Var.re_start:
         try:
             if Var.driver != 'selenium':
                 DriverBaseApp.close_app(None)
             else:
                 DriverBaseWeb.quit()
         except:
             pass
Beispiel #10
0
 def _closeApp(self, action):
     '''
     :param action:
     :return:
     '''
     parms = self._getParms(action, 0, ignore=True)
     if parms:
         DriverBaseApp.close_app(parms)
     else:
         package = Var.desired_caps.package if Var.desired_caps.package else Var.desired_caps.appPackage
         DriverBaseApp.close_app(package)
Beispiel #11
0
 def _press(self, action):
     '''
     :param action:
     :return:
     '''
     parms_x = self._getParms(action, 0)
     parms_y = self._getParms(action, 1)
     parms_s = self._getParms(action, 2, ignore=True)
     if not parms_s:
         DriverBaseApp.press(parms_x, parms_y)
     else:
         DriverBaseApp.press(parms_x, parms_y, parms_s)
Beispiel #12
0
 def _getText(self, action):
     '''
     :param action:
     :return:
     '''
     element = self._getElement(action)
     text = DriverBaseApp.get_text(element)
     return text
Beispiel #13
0
 def _click(self, action):
     '''
     :param action:
     :return:
     '''
     parms = self._getParms(action, 0)
     image_name = '{}.png'.format(action.step)
     img_info = self._ocrAnalysis(image_name, parms)
     if not isinstance(img_info, bool):
         if img_info is not None:
             Var.ocrimg = img_info['ocrimg']
             x = img_info['x']
             y = img_info['y']
             DriverBaseApp.tap(x, y)
         else:
             raise Exception("Can't find element {}".format(parms))
     else:
         element = self._getElement(action)
         DriverBaseApp.click(element)
Beispiel #14
0
 def _getElements(self, action):
     '''
     :param action:
     :return:
     '''
     parms = self._getParms(action, 0)
     elements = DriverBaseApp.find_elements_by_key(key=parms,
                                                   timeout=Var.time_out,
                                                   interval=Var.interval,
                                                   not_processing=True)
     if not elements:
         raise Exception("Can't find element {}".format(parms))
     return elements
Beispiel #15
0
 def _getElement(self, action):
     '''
     :param action:
     :return:
     '''
     parms = self._getParms(action, 0)
     if Var.driver == 'appium':
         from appium.webdriver import WebElement
     if Var.driver == 'macaca':
         from macaca.webdriver import WebElement
     if isinstance(parms, WebElement):
         element = parms
     else:
         element = DriverBaseApp.find_elements_by_key(key=parms,
                                                      timeout=Var.time_out,
                                                      interval=Var.interval)
     if not element:
         raise Exception("Can't find element {}".format(parms))
     return element
Beispiel #16
0
 def _isNotExist(self, action):
     '''
     :param action:
     :return:
     '''
     parms = self._getParms(action, 0)
     image_name = '{}.png'.format(action.step)
     img_info = self._ocrAnalysis(image_name, parms)
     result = False
     if not isinstance(img_info, bool):
         if img_info is not None:
             Var.ocrimg = img_info['ocrimg']
             result = True
     else:
         elements = DriverBaseApp.find_elements_by_key(
             key=parms,
             timeout=0,
             interval=Var.interval,
             not_processing=True)
         result = bool(elements)
     return not result
Beispiel #17
0
 def _goBack(self, action):
     '''
     :param action:
     :return:
     '''
     DriverBaseApp.adb_shell('shell input keyevent 4')