2

basic question here. I'm following a great tutorial on creating a web2py app by [Marco Laspe] (http://killer-web-development.com). But struggling with resolving a failure in my testing (using Selenium).

here is my about page...

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

and the testing function...

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

WHen testing i get...

======================================================================
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)

Anyone know where i'm going wrong? The other tests are working correctly (included below)

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)

1 Answer 1

2

Instead of getting the tag, the Selenium API provides a function in the Driver class to get the title. Try..

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

Or refactored to

def test_has_right_title(self):
    self.assertEqual('aaa', self.browser.title) # assuming you don't need it anywhere else
Sign up to request clarification or add additional context in comments.

4 Comments

thanbks for the response sircapsalot but i get the following... AttributeError: 'WebDriver' object has no attribute 'get_title'sircapsalot
oops! it's actually just driver.title
Appreciate it!! Thanks
I was stuck on the same thing. Stackoverflow rules!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.