How to assert on page titles when crawling

I am a newbie to robot framework. I am experimenting with the Browser library to test contents of all pages in a given website. I used the Crawl Site functionality of the library and that works without issues. Now I am trying to test if the page title of the page being crawled does not contain the string ‘Page not found’. I do the assertion on the page title inside the page_crawl_keyword . Here is the code.

*** Test Cases ***
Crawl and find errors
Crawl Site ${URL}
… max_number_of_page_to_crawl=2
… page_crawl_keyword=test_page

*** Keywords ***
${title}= Get Title
Log to Console Title of page crawled is ${title}
Should Not Contain ${title} ‘Page not found’

This assertion does not seem to work. Are assertions expected to work within the page_crawl_keyword?

Hi Balaji,

Should Not Contain    ${title}    ‘Page not found’

This is checking that the title does not contain ‘Page not found’ (including the single quotes) not Page not found (without the single quotes) as I think you expected, if so what you want is:

Should Not Contain    ${title}    Page not found


That was it. Thanks :slight_smile: I still need to get used to not using quotes for strings :wink:

1 Like