-1

执行测试时出现此错误:

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")

测试

import unittest
from core import Driver
import page

class testLoginOK(unittest.TestCase):

    def setUp(self):
        self.driver = Driver.getDriver('iOS')

    def test_login_error_message(self):

        main_page = page.MainPage(self.driver)
        main_page.click_Login_Button()

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

if __name__ == "__main__":
    unittest.main()
4

1 回答 1

0

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

my_driver = Driver()
something = my_driver.getDriver('iOS')
于 2017-06-27T19:10:05.500 回答