51Testing软件测试论坛

标题: appium中TypeError: Common() takes no arguments [打印本页]

作者: 测试积点老人    时间: 2021-3-9 11:17
标题: appium中TypeError: Common() takes no arguments
这是代码:
  1. from baseView.baseView import BaseView
  2. from common.desired_caps import appium_desired
  3. from selenium.common.exceptions import NoSuchElementException
  4. from appium import webdriver
  5. import logging
  6. from selenium.webdriver.common.by import By
  7. import time, os


  8. class Common(BaseView):
  9.     cancelBtn = (By.ID, 'com.android.packageinstaller:id/permission_allow_button')
  10.     skipBtn = (By.ID, 'com.tal.kaoyan:id/tv_skip')

  11.     def check_cancelBtn(self):
  12.         logging.info('----------check_cancelBtn ------------')
  13.         try:
  14.             cancelBtn = self.driver.find_element(*self.cancelBtn)
  15.         except NoSuchElementException:
  16.             logging.info('no cancelBtn')
  17.         else:
  18.             cancelBtn.click()

  19.     def check_skipBtn(self):
  20.         logging.info('----------check_skipBtn ------------')
  21.         try:
  22.             skipBtn = self.driver.find_element(*self.skipBtn)
  23.         except NoSuchElementException:
  24.             logging.info('no skipBtn')
  25.         else:
  26.             skipBtn.click()

  27.     def get_window_size(self):
  28.         x = self.driver.get_window_size()['width']
  29.         y = self.driver.get_window_size()['height']
  30.         return x, y

  31.     def swipeLeft(self):
  32.         logging.info('swipeleft')
  33.         l = self.get_size()
  34.         x1 = (l[0] * 0.9)
  35.         y1 = (l[0] * 0.5)
  36.         x2 = (l[0] * 0.1)
  37.         self.swipe(x1, y1, x2, y1, 2000)

  38.     def getTime(self):
  39.         self.now = time.strftime('%Y-%m-%d %H-%M-%S')
  40.         return self.now

  41.     def getScreenShot(self, module):
  42.         time = self.getTime()
  43.         image_file = os.path.dirname(os.path.dirname(__file__)) + '/screenshots/%s_%s.png' % (module, time)

  44.         logging.info('get %s screenshot' % module)
  45.         self.driver.get_screenshot_as_file(image_file)


  46. if __name__ == '__main__':
  47.     driver = appium_desired()
  48.     com = Common(driver)
  49.     com.check_cancelBtn()
  50.     com.check_skipBtn()
复制代码
这是报错:
  1. /usr/local/bin/python3.7 /Users/pei/PycharmProjects/kyb_testProject/common/common_fun.py
  2. /Users/pei/PycharmProjects/kyb_testProject/common/desired_caps.py:15: YAMLLoadWarning: calling yaml.load() without Loader=... is deprecated, as the default Loader is unsafe. Please read https://msg.pyyaml.org/load for full details.
  3. 2019-05-31 16:20:24,649 desired_caps.py[line:32] INFO start app...
  4.   data = yaml.load(file)
  5. Traceback (most recent call last):
  6.   File "/Users/pei/PycharmProjects/kyb_testProject/common/common_fun.py", line 61, in <module>
  7.     com = Common(driver)
  8. TypeError: Common() takes no arguments
复制代码
为什么会这样啊?折磨我好长时间

作者: qqq911    时间: 2021-3-10 10:55
传入参数不对
作者: litingting0214    时间: 2021-3-10 13:53
from baseView.baseView import BaseView:里面脚本写错了认真查看修改即可
作者: jingzizx    时间: 2021-3-10 16:53
需要参数吧




欢迎光临 51Testing软件测试论坛 (http://bbs.51testing.com/) Powered by Discuz! X3.2