Assert/VerifyElementPresent with Python and WebDriver?

前端 未结 5 2092
野趣味
野趣味 2020-12-31 01:05

I may just be confused by the change from Selenium to WebDriver and their respective documentation. In a section about test design in the documentation there is talk of usin

5条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-12-31 01:22

    In Selenium RC, verify/assert methods exist. In WebDriver, they don't. Also, its important to note what verify and assert does and their role in your tests. In Selenium RC, verify is used to perform a check in your test, whether it may be on text, elements, or what have you. Assert, on the other hand, will cause a test to fail and stop. The benefits and advantages are discussed in the link you referenced.

    WebDriver doesn't have verify/assert methods per say. Assertions are performed in the test itself. If you take a look at Corey's answer, he performs an "assert" on an element's text. If the element's text is not 'Example Domains' an AssertionError will be raised, effectively failing your test. But what about a verify? Well as mentioned, WebDriver doesn't have one. But you could still perform something equivalent by doing a comparison.

    if element.text != u'Example Domains':
        print "Verify Failed: element text is not %r" % element.text
    

    So in this case, your test won't fail. But a verification will still take place and will print to stdout.

    So in the end, it's a matter of what you want to fail. It's more of a test design. Hope this helps.

提交回复
热议问题