2013-10-09 165 views
2

这里的基本问题。我正在关注[Marco Laspe](http://killer-web-development.com)创建web2py应用的一个很好的教程。但努力解决我的测试失败(使用Selenium)。使用Selenium webdriver进行Web2py测试

这里是我的关于网页...

<!DOCTYPEhtml> 
<html> 
    <head> 
    <title>aaa</title> 
    </head> 
    <body> 
    <h1>blah</h1> 
    </body> 
</html> 

和测试功能...

def test_has_right_title(self): 
    title = self.browser.find_element_by_tag_name('title') 
    self.assertEqual('aaa', title.text) 

在测试时,我得到...

====================================================================== 
FAIL: test_has_right_title (test_static_pages.TestPrivacyPage) 
---------------------------------------------------------------------- 
Traceback (most recent call last): 
    File "C:\web2py\applications\pitch\fts\test_static_pages.py", line 40, in test 
_has_right_title 
    self.assertEqual('aaa', title.text) 
AssertionError: 'aaa' != u'' 

---------------------------------------------------------------------- 
Ran 10 tests in 37.497s 

FAILED (failures=3) 

任何人都知道在哪里我错了?其他测试工作正常(包括以下)

def setUp(self): 
    self.url = ROOT + '/pitch/default/privacy' 
    get_browser=self.browser.get(self.url) 

def test_can_view_privacy_page(self): 
    response_code = self.get_response_code(self.url) 
    self.assertEqual(response_code, 200) 

def test_has_right_heading(self):   
    heading = self.browser.find_element_by_tag_name('h1') 
    self.assertIn('Pitch.Me Privacy Policy', heading.text) 

回答

2

非但没有标签的,硒API在Driver类提供了一个功能,拿到冠军。尝试..

def test_has_right_title(self): 
    title = self.browser.title 
    self.assertEqual('aaa', title) 

或者重构为

def test_has_right_title(self): 
    self.assertEqual('aaa', self.browser.title) # assuming you don't need it anywhere else 
+0

为响应sircapsalot thanbks但我得到以下... AttributeError的: 'webdriver的' 对象有没有属性“get_title'sircapsalot – AtomicCrash

+0

糟糕!它实际上只是driver.title – sircapsalot

+0

欣赏它!谢谢 – AtomicCrash

相关问题