我正在使用的TestCase(unittest.TestCase)类中的Python Webdriver代码 assertTrue因为我想获取网页上元素的文本,如果我的期望值与实际值匹配,则返回true。
assertTrue返回None。它没有返回True。 有谁知道我对assertTrue做错了什么?
在我的方法is_dataObject_name_saved3(self,dataObject_type1)中,我检索元素的文本。我将其打印到控制台以查看值是否在那里。值“名称”就在那里。 在我的IF语句中,我使用
if dataObject_name_element1.text == "Name":
print "pass **************************"
return True
else:
print "fail"
return False
返回None而不是True或False。
该场景是我从左侧导航点击数据对象链接的测试。单击“添加”按钮。它将Name输入Name文本字段,例如“名称”。 它在描述文本字段中输入描述。点击保存。 显示的下一页显示了已保存的值,例如“名称”。 我正在检查名称是否存在,显示在页面上。如果确实如此,那么我的测试已经过去了。
在我的DataConfigurationPage_TestCase(unittest.TestCase)类中,我使用assert来检查
这是我的代码段。一些人非常感谢。
具有方法is_dataObject_name_saved3的类Data_Objects应该返回true或false:
def is_dataObject_name_saved3(self, dataObject_type1):
if dataObject_type1 == "Name":
#return str(text) in self.driver.getPageSource
try:
dataObject_name_element1 = self.driver.find_element(*MainPageLocators.data_objects_name_saved)
print "dataObject_name_element1.text = " + dataObject_name_element1.text
# print "DataObjectType1 = " + dataObject_type1
#dataObject_name_element2 = self.driver.find_element(*MainPageLocators.data_objects_description_saved)
#print dataObject_name_element2.text
#dataObject_name_element3 = self.driver.find_element(*MainPageLocators.data_objects_type_saved)
#print dataObject_name_element3.text
if dataObject_name_element1.text == "Name":
print "pass **************************"
return True
else:
print "fail"
return False
except NoSuchElementException, e:
return False
elif dataObject_type1 == "Address":
try:
dataObject_name_element1 = self.driver.find_element(*MainPageLocators.data_objects_name_saved)
print "dataObject_name_element1.text = " + dataObject_name_element1.text
if dataObject_name_element1.text == "Address":
print "pass **************************"
return True
else:
print "fail"
return False
except NoSuchElementException, e:
return False
#return dataObject_name_element1.text in "Name"
类DataConfigurationPage_TestCase断言是向下的。我在页面对象模型中没有正确使用assertTrue吗?
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
from Pages import data_objects
import datetime
class DataConfigurationPage_TestCase(unittest.TestCase):
def setUp(self):
#webdriver.DesiredCapabilities.FIREFOX["unexpectedAlertBehaviour"] = "accept"
webdriver.DesiredCapabilities.INTERNETEXPLORER["unexpectedAlertBehaviour"] = "accept"
#self.driver = webdriver.Firefox()
#self.driver = webdriver.Ie("C:\QA\Automation\Python_projects\Selenium Webdriver\IEDriverServer_Win32_2.45.0\IEDriverServer.exe")
self.driver = webdriver.Ie("C:\Webdriver\IEDriverServer_Win32_2.46.0\IEDriverServer.exe")
self.driver.get("http://riaz-pc.companyname.local:8080/clearcore501")
self.login_page = login.LoginPage(self.driver)
#print "I am here in setUp self.login_page = page.LoginPage(self.driver)"
self.driver.implicitly_wait(100)
def test_add_Data_Objects(self):
print "*** test_add_Data_Objects ***"
data_dashboard_page = self.login_page.userLogin_valid("riaz.ladhani", "pass123")
md = main_dashboard.MainDashboardPage(self.driver)
md.select_project_from_drop_down()
data_configuration_page = data_dashboard_page.click_data_configuration2() # Click Data Configuration from the Project Navigator
time.sleep(10)
assert data_configuration_page.is_Data_Configuration_pageDisplayed(), "Data Configuration Page not displayed"
if data_configuration_page.is_Data_Configuration_pageDisplayed() == True:
pass
else:
print "ERROR - Data Configuration page is not displayed"
data_objects = md.click_data_objects() # Click Data Objects from the left navigation bar
# Add the Name data object
data_objects.add_DataObject("Name")
# has the data object Name saved
time.sleep(10)
self.assertTrue(data_objects.is_dataObject_name_saved3("Name"), "assertTrue is false")
控制台输出是:
*** test_add_Data_Objects ***
dataObject_name_element1.text = Name
pass **************************
None