Unit Test Framework
Selenium is used for Web UI automation ,
To write and to maintain test cases a framework is required.
Here in this case Unitest is used for this purpose
About Unittest
Core Class of unittest
Selenium is used for Web UI automation ,
To write and to maintain test cases a framework is required.
Here in this case Unitest is used for this purpose
About Unittest
- Unittest module started life as the third-party module PyUnit.
- Unittest support fixtures,test suites and a test runner to enable automated testing.
Core Class of unittest
- TestCase
- TestSuite
- TestLoader
- TextTestRunner
- TestResults
- TestCase is a one of the core classes of unittest module.
- TestCase has to be inherited from unittest module
- All the test routines or methods must start with "test".
- Only then will they be executed, Test case can be in a different file,if so the module to be tested must be imported.
Example 1
Unit test for lowercasevowel.py
Output
Note: each "." represents testcase successfully executed ,if test case fails "F" instead of "."
Structure of TestCase Class of unittest
- setUp() where pre-condition for executing the test case are written down.
- tearDown() here clean up ,which is required after each test case is written down.
- skipTest() will skip the current test.
- fail() will fail the test explicitly ie..It will fail the test an raise AssertionError.
- id() Return a string containing the name of the TestCase object and of the test method.
- shortDescription() Return the Docstring present in the Test case method.
methods.
Example 2
Let us use the setUp() and tearDown() methods
Let us use the setUp() and tearDown() methods
Example 3
Let us use the setUp() and tearDown() id() & shortDescription() methods
Problem 1
Search for a python tutorial on youtube ?
Answer
- Open a browser (firefox)
- Nagivate to "http://www.youtube.com"
- Verify that youtube page is opened
- Locate the search Box and type in Python Tutorials
- To take a screenshot
The complete solution with unittest as Framework
Output
This post is so helpfull and informative.keep updating with more information...
ReplyDeletePython Training Mumbai
Python Classes In Ahmedabad
Python Training In Cochin
Python Training Institute In Trivandrum
Python Training Institute In Kolkata