Motivation
So you’ve reached a point, where it would be more efficient to code some methods on your own than working with baangtDB or simpler Excel Sheets. Don’t worry, you’re not alone. We’ll create an example where we want to implement additional functionality in BrowserDriver class.
Basic structure of baangt
base
Within this folder you can find all the main classes, that execute test cases, interpret test run definitions and finally export results to database and Excel-Logs.
Also here are the helper classes like IBAN, AddressCreate and many more. You can always look at readthedocs to see the latest list of classes and methods.
Candidates for subclassing are:
- AddressCreate, where you might want to add specific functionality for your industry
- ApiHandling – maybe you have some specific headers or cookies
- BrowserHandling: This is the class that is subclasses most often due to all kinds of special environments either in your intranet or your test system setup
- TK: ExportResults:
katalon importer
This is an experimental feature, which exports actually subclasses of TestCases from Katalon Studio Projects. It’s very beta right now (February 2020) and will mature eventually if demand comes up for further improvements. Using this feature the transfer from a fairly large Katalon Studio project into baangt was possible in approx. 4 hours. Your milage may vary.
TestCase
The TestCaseMaster-Class is always linked to a TestCaseSequence, which holds data files and execution information (e.g. BrowserType, number of parallel sessions, etc.)
TestStep
That’s one of the main classes, with lots of logic to interpret the commands from SimpleFormat Excel sheets and also baangtDB TestSteps. You’ll usually not want to subclass here, as it should work perfectly out of the box.
ui
You guessed it most probably. This is the home of baangt interactive starter ui. You’ll usually not subclass here either. The only exception is, when you need a custom TestRun to be executed in Debug mode.
Custom BrowserDriver
It takes just a few minutes to prepare implementation of new functionality.
Once you know the class and the method the rest should be very easy.
One of the most common subclassing happens in BrowserDriver. You might be confronted with specific behavior of your intranet applications, that can’t be dealt with in baangt standard. It’s very simple to do achieve the subclassing – the desired functionality might be difficult to implement though.
First you’d create a new Python project, new virtual environment and import baangt module using:
>>pip3 install baangt
Next you’ll create a class, that subclasses the main class from baangt, in our example create a new Python file MyBrowserDriver.py.
First we need to select the method, that we want to overwrite in our custom class (for this example it will be findBy-Method), then we can simply write:
from baangt.base.BrowserDriver.BrowserDriver import BrowserHandling
class myBrowserHandling(BrowserHandling):
def findBy(*args):
super().findBy(*args)
# Your custom Code here
All other classes and methods can be treated in the same way. The last thing to do, is let baangt know, to use your custom class instead of the standard classes. For this you’ll need to subclass all calling classes, in the case of browserDriver these are TestRun and CliAndInteractive.
- 5 Minutes or less 100%
Of course you can also use those classes in baangtDB, for instance if you want to SubClass TestCase or TestCaseSequence (even TestStep, but why on earth would you do that?) you can provide your custom class name in baangtDB to execute your versions rather than the standard versions.
Recent Comments