TypeError:当我从登录方法返回页面对象时,未绑定方法



我正在重新组织我最近开始的webdriver, python框架。场景:我从LoginPage类调用userLogin_valid方法登录到我们的网站(这将登录一个有效的用户)我已将此方法更改为返回主仪表板页面对象,因为当用户登录主页时显示仪表板。从这里我可以点击管理选项卡,数据配置选项卡等。

从我的datconfigurationpage_testcase我调用用户登录方法如下:

data_configuration_page = self.login_page.userLogin_valid("userName", "pass")

然后我从主仪表板页面类调用点击数据配置按钮如下(从主仪表板页面我点击数据配置选项卡):

data_configuration_page.click_data_configuration() # Click Data Configuration from menu bar

我得到以下错误:

    Traceback (most recent call last):
  File "C:Usersriaz.ladhaniPycharmProjectsSelenium WebdriverClearCore 501 - CopyTestCasesDataConfigurationPage_TestCase.py", line 30, in test_add_Data_Objects
    data_configuration_page.click_data_configuration() # Click Data Configuration from menu bar
TypeError: unbound method click_data_configuration() must be called with MainDashboardPage instance as first argument (got nothing instead)

一些帮助感谢我做错了什么在这里得到这个错误。我在调用页面对象时出错了。

我的代码片段如下:

页面 login.py

import time
import Locators
from selenium.common.exceptions import NoSuchElementException
from Locators.element import BasePageElement
from Locators.locators import MainPageLocators
from Locators import locators
from Locators import element
from Locators.element import BasePageElement
from Pages.admin import AdministrationPage
from Pages.base import BasePage
from Pages.main_dashboard import MainDashboardPage
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.common.exceptions import TimeoutException
from selenium.webdriver.common.by import By

class LoginPage(BasePage):
    def userLogin_valid(self, name, password):
        _name = name
        _password = password
        userName_textbox = self.driver.find_element(*MainPageLocators.usernameTxtBox)
        userName_textbox.clear()
        userName_textbox.send_keys(_name)
        password_textbox = self.driver.find_element(*MainPageLocators.passwordTxtBox)
        password_textbox.clear()
        password_textbox.send_keys(_password)
        submitButton = self.driver.find_element(*MainPageLocators.submitButton)
        submitButton.click()
        return MainDashboardPage

页面 main_dashboard.py

import time
import datetime
from selenium.common.exceptions import NoSuchElementException
from Locators.locators import MainPageLocators
from Locators.element import BasePageElement
from Pages.base import BasePage
class MainDashboardPage(BasePage):
    def click_data_configuration(self):
        self.driver.find_element(*MainPageLocators.DataConfiguration_button_xpath).click()
        return MainDashboardPage(self.driver)

DataConfigurationPage_TestCase.py测试点

import unittest
import time
import datetime
from selenium import webdriver
from Locators import locators
from Locators import element
from Pages import login
from Pages import admin
from Pages import main_dashboard

class AdministrationPage_TestCase(unittest.TestCase):
    def setUp(self):
        webdriver.DesiredCapabilities.INTERNETEXPLORER["unexpectedAlertBehaviour"] = "accept"
        self.driver = webdriver.Ie("C:QAAutomationPython_projectsSelenium WebdriverIEDriverServer_Win32_2.45.0IEDriverServer.exe")
        self.driver.get("http://riaz-pc.company.local:8080/clearcore")
        self.login_page = login.LoginPage(self.driver)
        self.driver.implicitly_wait(30)
    def test_add_Data_Objects(self):
        print "*** test_add_Data_Objects ***"
        data_configuration_page = self.login_page.userLogin_valid("batman", "batarang123")
        data_configuration_page.click_data_configuration() # Click Data Configuration from menu bar
        assert data_configuration_page.is_Data_Configuration_pageDisplayed(), "Data Configuration Page not displayed"
        print "data_configuration_page.is_Data_Configuration_pageDisplayed()"
        print data_configuration_page.is_Data_Configuration_pageDisplayed()


    def tearDown(self):
        self.login_page.click_logout()
        self.driver.close()
if __name__ == "__main__":
    unittest.main()

您的login_page.userLogin_valid(self, name, password)返回的是一个类,而不是该类的实例。

相关内容

  • 没有找到相关文章

最新更新