diff --git a/README.md b/README.md index c188e21b..e0135577 100755 --- a/README.md +++ b/README.md @@ -485,6 +485,30 @@ self.execute_script("document.body.innerHTML = \"%s\"" % referral_link) self.click("a.analytics") # Clicks the generated button ``` +#### Using non-terminating verifications: + +Let's say you want to verify multiple different elements on a web page in a single test, but you don't want the test to fail until you verified several elements at once so that you don't have to rerun the test to find more missing elements on the same page. That's where page checks come in. Here's the example: + +```python +from seleniumbase import BaseCase + +class MyTestClass(BaseCase): + + def test_non_terminating_checks(self): + self.open('http://xkcd.com/993/') + self.wait_for_element('#comic') + self.check_assert_element('img[alt="Brand Identity"]') + self.check_assert_element('img[alt="Rocket Ship"]') # Will Fail + self.check_assert_element('#comicmap') + self.check_assert_text('Fake Item', '#middleContainer') # Will Fail + self.check_assert_text('Random', '#middleContainer') + self.check_assert_element('a[name="Super Fake !!!"]') # Will Fail + self.process_checks() +``` + +``check_assert_element()`` and ``check_assert_text()`` will save any exceptions that would be raised. +To flush out all the failed checks into a single exception, make sure to call ``self.process_checks()`` at the end of your test method. If your test hits multiple pages, you can call ``self.process_checks()`` at the end of all your checks for a single page. This way, the screenshot from your log file will make the location where the checks were made. + ### Part III: More Details Nosetests automatically runs any python method that starts with "test" from the file you selected. You can also select specific tests to run from files or classes. For example, the code in the early examples could've been run using "nosetests my_first_test.py:MyTestClass.test_basic ... ...". If you wanted to run all tests in MyTestClass, you can use: "nosetests my_first_test.py:MyTestClass ... ...", which is useful when you have multiple tests in the same file. Don't forget the plugins. Use "-s" if you want better logging in the console output.