我已经开始在我们网站的自动化脚本中使用页面对象模型。我用的是Python,Webdriver 我有一个LoginPage类和一些方法 我有一个带有方法的AdministrationPage类。(当用户已登录管理页面时显示)
在登录页面上,我有一个名为clickAdministration(self)的方法。点击按钮在这里,返回的是returnPages.administrationPage页(自驱动程序)在
当我的代码运行并到达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类中单击Administration按钮时,我调用管理页面对象的语法不正确。在
当我在用户登录(从LoginPage类)后单击管理链接时,我应该返回AdministrationPage对象。在
我的LoginPage和AdministrationPage类位于一个名为Pages的包中 我的TestCase类在一个名为TestCases的包中
你也会注意到在我的代码片段中,我对WebDriverWait的调用被注释掉了。这是因为我在使用它时会遇到超时异常。我已经恢复使用时间。睡觉现在。 如果有人也能帮助我的WebDriverWait语法,那会很有帮助。 谢谢您。在
我的代码截取如下:
测试用例\管理页面_测试用例.py在
^{pr2}$页数\管理页面.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")
页数\页面.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
目前没有回答
相关问题 更多 >
编程相关推荐