-
-
Notifications
You must be signed in to change notification settings - Fork 22
WebdriverTestCase
WebdriverTestCase provides method aliases on driver and some other cool stuff. If you need driver instance, it's hide in self.driver.
from webdriverwrapper.testcase import WebdriverTestCase
class TestCase(WebdriverTestCase):
def test(self):
self.go_to('http://www.google.com')
self.click('gbqfsb') # I'm feeling luck.
self.contains_text('Doodles')Tip: if you want to write something into __init__, write it into method init and you do not have to call parent's __init__.
By default you have to specify domain in first go_to call. It's not good because you should not know which test is called first. So you can specify domain by this class variable.
class TestCase(WebdriverTestCase):
domain = 'www.example.com'By default WebdriverTestCase create one driver for all tests. If you want one driver for every TestCase or for every test, change this variable.
Note: It's good to define it in some base TestCase for all TestCases.
from webdriverwrapper.testcase import ONE_INSTANCE_FOR_ALL_TESTS
class TestCase(WebdriverTestCase):
instances_of_driver = ONE_INSTANCE_FOR_ALL_TESTSOptions are:
ONE_INSTANCE_FOR_ALL_TESTSONE_INSTANCE_PER_TESTCASEONE_INSTANCE_PER_TEST
When you have to do some debug page (for example with Firebug or with Chrome Developer tools), you can set wait_after_test and after each test it waits for input to continue.
class TestCase(WebdriverTestCase):
wait_after_test = TrueBy default WebdriverTestCase create instance of Firefox. You can overwrite this method and create which instance of driver you want.
WebdriverTestCase check your web application on errors. When your page contains some elements with class error, this method finds them and print that there is some problem.
WebdriverTestCase looks for JavaScript errors in your web application. For that you need put into your site this code:
<script type="text/javascript">
window.jsErrors = [];
window.onerror = function(errorMessage) {
window.jsErrors[window.jsErrors.length] = errorMessage;
}
</script>Show message in console. (Uses module logging.)
Waits for user input. Good for debuging.