我的按钮单击以返回下一页对象显示错误模块对象不可调用

时间:2015-05-19 11:11:13

标签: python selenium-webdriver webdriver

我已经开始在我的网站的自动化脚本中使用页面对象模型。我正在使用Python,Webdriver 我有一些带有一些方法的LoginPage类 我有一个带有方法的AdministrationPage类。 (当用户登录管理页面时显示)

在登录页面上,我有一个名为clickAdministration(self)的方法:按钮单击在这里,返回的是Pages.administrationPage(self.driver)

当我的代码运行并进入clickAdministration时,会显示以下错误:

    Traceback (most recent call last):
  File "C:\Users\riaz.ladhani\PycharmProjects\Selenium Webdriver\ClearCore \TestCases\AdministrationPage_TestCase.py", line 31, in test_add_Project
    administration_page = login_page.clickAdministration()
  File "C:\Users\riaz.ladhani\PycharmProjects\Selenium Webdriver\ClearCore \Pages\page.py", line 59, in clickAdministration
    return Pages.administrationPage(self.driver)
TypeError: 'module' object is not callable

我需要一些帮助,当我从LoginPage类中单击Administraition按钮时,调用Administration Page对象的语法不正确。

当我在用户登录后单击“管理”链接时(从LoginPage类),我应该返回AdministrationPage对象。

我的LoginPage和AdministrationPage类位于名为Pages的包中 我的TestCase类位于名为TestCases的包中

另外,您会在我的代码片段中注意到我对WebDriverWait的调用已被注释掉。这是因为我使用它时会收到超时异常。我现在已经恢复使用time.sleep了。 如果有人也可以帮助我的WebDriverWait语法,这将有所帮助。 谢谢。

我的代码剪断如下:

的TestCases \ AdministrationPage_TestCase.py

    import unittest
import time
from selenium import webdriver
from Locators import locators
from Locators import element
from Pages import page
from Pages.administrationPage import AdministrationPage
from Pages.page import LoginPage


class AdministrationPage_TestCase(unittest.TestCase):

    def setUp(self):
        self.driver = webdriver.Ie("C:\QA\Automation\Python_projects\Selenium Webdriver\IEDriverServer_Win32_2.45.0\IEDriverServer.exe")
        self.driver.get("http://riaz-pc.company.local:8080/clearcore")
        self.login_page = page.LoginPage(self.driver)
        print "I am here in setUp self.login_page = page.LoginPage(self.driver)"
        self.driver.implicitly_wait(30)

    def test_add_Project(self):
        login_page = page.LoginPage(self.driver)
        login_page.userLogin_valid()
        administration_page = login_page.clickAdministration()
        print "I am here administration_page = login_page.clickAdministration(self.driver)"
        administration_page.AdministrationPage.add_project()

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

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

页面\ administrationPage.py

import time
import datetime
from selenium.common.exceptions import NoSuchElementException
from Locators.locators import MainPageLocators
from Locators import locators
from Locators import element
from Locators.element import BasePageElement

class BasePage(object):

    def __init__(self, driver):
        self.driver = driver


class AdministrationPage(BasePage):
    # Add a project, enter project name & description, save
    def add_project(self):
        add_project_button = self.driver.find_element(*MainPageLocators.addButton_project)
        add_project_button.click()
        project_name_textfield = self.driver.find_element(*MainPageLocators.projectName_textfield)
        project_name_textfield.click()
        project_name_textfield.clear()
        dateNow = self.get_date_now()
        project_name_textfield.sendkeys('LADEMO_IE_nn_')
        project_description_textfield = self.driver.find_element(*MainPageLocators.projectDescription_textfield)
        project_description_textfield.click()
        project_description_textfield.clear()
        project_name_textfield.sendkeys("LADEMO create a basic project test script - Selenium Webdriver/Python Automated test")

Pages \ page.py(这是LoginPage类)

    import time
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
import Locators
import Pages.administrationPage


class BasePage(object):

    def __init__(self, driver):
        self.driver = driver


class LoginPage(BasePage):
    def click_go_button(self):
        element = self.driver.find_element(*MainPageLocators.GO_BUTTON)
        element.click()

    def userLogin_valid(self):
        time.sleep(5)
        userName_textbox = self.driver.find_element(*MainPageLocators.usernameTxtBox)
        userName_textbox.clear()
        userName_textbox.send_keys("user1")
        password_textbox = self.driver.find_element(*MainPageLocators.passwordTxtBox)
        password_textbox.clear()
        password_textbox.send_keys("test123")
        submitButton = self.driver.find_element(*MainPageLocators.submitButton)
        submitButton.click()

    #Click Administration from top menu
    def clickAdministration(self):
        # getting Timeout exception when i use this, using sleep for now
        #WebDriverWait (self.driver, 10).until(lambda d: self.driver.find_element(*MainPageLocators.AdministrationButton_xpath).click()) 
        time.sleep(15)
        self.driver.find_element(*MainPageLocators.AdministrationButton_xpath).click()
        time.sleep(5)
        print "I am here, trying to click Pages.administrationPage"
        return Pages.administrationPage(self.driver)

    def user_login_invalid(self):
        userName_textbox = self.driver.find_element(*MainPageLocators.usernameTxtBox)
        userName_textbox.clear()
        userName_textbox.send_keys("user1")
        password_textbox = self.driver.find_element(*MainPageLocators.passwordTxtBox)
        password_textbox.clear()
        password_textbox.send_keys("test1")
        submitButton = self.driver.find_element(*MainPageLocators.submitButton)
        submitButton.click()

    #check if Administration link is present.  When logged in we can check are we on the correct page
    def isAdministration_present(self):
        #administrationLink = self.driver.find_element(*MainPageLocators.AdministrationButton_xpath)
        #print "administrationLink = " + administrationLink
        #wait = WebDriverWait(self.driver, 10)
        #h3 = wait.until(EC.visibility_of_element_located(*MainPageLocators.AdministrationButton_xpath))
        #h3.click()
        #print h3.text
        time.sleep(10)
        try:
            administrationLink_text = self.driver.find_element(*MainPageLocators.AdministrationButton_xpath)
        except NoSuchElementException, e:
            return False
        return "Administration" in administrationLink_text.text # check if the text Administration is in the AdministrationLink_text, return true if it is
        #print "administrationLink_text.text = " + administrationLink_text.text


    def is_text_present(self):
        try:
            #body = self.driver.find_element_by_tag_name("body") # find body tag element
            administrationLink_text = self.driver.find_element(*MainPageLocators.AdministrationButton_xpath)
        except NoSuchElementException, e:
            return False
        return "Administration" in administrationLink_text.text # check if the text is in the Administration Link

0 个答案:

没有答案