While test automation as such has nothing new in its own basics, but how we can drive the same using the pytest is something we will have a look at.
IDE suited for automation test creation and maintenance is VSCode, and do ensure the right stuffs are installed on host machine, typical pytest test automation project needs
python
pytest
Above utilities need to be installed and can be easily done via the VSCode IDE.
Just excute the pip command to install all packages and dont forget to add the pip path as environment variable on the host machine.
Sample command are as under
Pip install pytest
Few other re-usable frameworks to make things easy and optimally utilized. We can talk about them as and when we hit the need to do so.
And a very quick and easy way to get started is just download a sample project from online and get started. Do not delve too much into how to do without getting hand dirty. As all test automation have different set of needs and you need to pay attention to right details in right ratio to get things done.
Sample code to connect to azure databricks and fetch the clusters , jobs etc details is pretty simple.
import databricks_client
db = DatabricksAPI(
host="adb-instance",
token="dapitoken"
)
run_id = db.jobs.run_now(
job_id=job-id of the job which has been created and attached to a cluster . This jobs should be having a notebook hooked onto it.,
)
print(run_id)
The above is involving multiple packages that need to be installed on host and can be done as explained above.
Sample code to connect to azure databricks and fetch the database tables and other objects details is pretty simple. This can aso be done by configuring simba odbc driver instance on the host machine and pointing the automation suite's connection string to that dsn.
This can aso be done by configuring simba odbc driver instance on the host machine and pointing the automation suite's connection string to that dsn.
Do remember to configure the above DSN via the odbc driver , by installing simba driver and configuring same details like adb details, the http path and providing dapi token.
How to do validation on the delta tables of azure databricks is a tricky questions. Since we want it to be done un-attended and seamless in nature.
We need to implement a hybrid of unit and pytest frameworks to achieve this, and few sample code below shall be helpful to attain the same. We cannot go by the basics to achieve it, since basics knowledge is readily available elsewhere.
So basic question which arises is how to achieve low maintainable automation suites.
We achieve this by implementing data driven nature of the sql queries, we keep the sql queries in csv file and invoke them via ddt into testmethods. So what we will be able to acheive is on the relevant tables all set of validation we keep it outside the testmethod in a csv file and data drive the testmethod execution via the framework of ddt.
A sample code below shall be helpful to understand the flow
In the code below entire query content can be put in the called csv file so as to make the
testmethod independent of the calls and same testmethod cna run for all validations on this table
@ddt
The last thing to take care is to make the run unattended. And we can easily drive it via Windows Scheduler. So create a task in scheduler and the question is how do we point the scheduler task to this automation project.
The solution is pretty simple. Create a batch file and put in the right commandlet in there to ensure tha scheduler task m akes the automation run absolute smooth and unattended. Just open up report to do result reconciliation alone and share with stakeholders.
Sample content for batch file is
set rootpath=C:\repos\\AutomationTestProject\
set todaysdate=%date:~-4,4%%date:~-7,2%%date:~-10,2%
cd /d C:
cd %rootpath%reports
mkdir %todaysdate%
cd %rootpath%reports\%todaysdate%
pytest -v -m five --html=report_Module1.html %rootpath%tests\test_Module1.py
pytest -v -m eight --html=report_Module2.html %rootpath%tests\test_Module2.py
pytest -v -m nine --html=report_Module3.html %rootpath%tests\test_Module3.py
The output of this scheduler based task execution of test automation project is html reports which outlines details on pass / fail etc with detail logging on what activities were performed as part of test execution.
Post a Comment