TypeError:必须使用Driver实例作为第一个参数调用未绑定方法“getDriver()”(改为使用str实例)

时间:2017-06-27 17:53:27

标签: python python-3.x appium-ios python-appium

执行测试时出现此错误:

studio.sh

这是我的代码:

TypeError: unbound method "getDriver()" must be called with Driver instance as first argument (got str instance instead)

核心

from appium.webdriver.common.mobileby import MobileBy

class Locators(object):    
    def setLocators(self):
        if (self.platform=='android'):
            ACEPTAR_PERMISO_BTN = (MobileBy.ID,"com.android.packageinstaller:id/permission_allow_button")
            ACEPTAR_LOGIN_BTN = (MobileBy.ID,"com.entel.movil:id/btnLogin")
            ACEPTAR_MENSAJE_ERROR_BTN = (MobileBy.ID,"com.entel.movil:id/btnPositive")
            INGRESAR_NUMERO_TXT = (MobileBy.ID,"com.entel.movil:id/etNumber")
            INGRESAR_PASSWORD_TXT = (MobileBy.ID,"com.entel.movil:id/etPassword")
        elif (self.platform=='iOS'):
            INGRESAR_PASSWORD_TXT= (MobileBy.ID,"//XCUIElementTypeSecureTextField[1]")
            ACEPTAR_LOGIN_BTN = (MobileBy.ID,"INGRESAR")

页面

from appium import webdriver

class Driver(object):

    def setUp(self):
        self.browser = 'iOS'
        self.getDriver(self.platform)

    def getDriver(self, platform):
        desired_caps = {}
        urlLink = "XXXXXXXX"
        if platform == 'android':
            self.driver = webdriver.Remote(urlLink, desired_caps)
        elif platform == 'iOS':
            desired_caps['platformName'] = 'iOS'
            desired_caps['platformVersion'] = '10.0'
            desired_caps['deviceName'] = 'XXXXXXX'
            print(desired_caps)
            self.driver = webdriver.Remote(urlLink, desired_caps)
        return self.driver

    def tearDown(self):
        self.driver.quit()

元素

from locators import Locators

class BasePage(object):
    def __init__(self, driver):
        self.driver = driver

class MainPage(BasePage):

    def click_Login_Button(self):
        element = self.driver.find_element(*Locators.setLocators().ACEPTAR_LOGIN_BTN)
        element.click()

测试

from selenium.webdriver.support.ui import WebDriverWait


class BasePageElement(object):
    def __set__(self, obj, value):
        driver = obj.driver
        WebDriverWait(driver, 100).until(
            lambda driver: driver.find_element_by_name(self.locator))
        driver.find_element_by_name(self.locator).send_keys(value)

    def __get__(self, obj):
        driver = obj.driver
        WebDriverWait(driver, 100).until(
            lambda driver: driver.find_element_by_name(self.locator))
        element = driver.find_element_by_name(self.locator)
        return element.get_attribute("value")

1 个答案:

答案 0 :(得分:0)

编写Driver类的方式,您必须先创建它的特定实例,然后才能调用其方法:

my_driver = Driver()
something = my_driver.getDriver('iOS')