Sunteți pe pagina 1din 3

Writing Simple Automation Scripts with Python By Naveen Nagesh Python is a very popular and powerful tool used

in automation of various repetitive processes. In case of telecoms testing TCL/TK is widely used in automation of various call scenarios. TCL/TK, though very flexible, involves a longer learning cycle. Python, on the other hand has a lot of built-in ready to use plugins/modules that can be easily used to automate simple, repetitive call scenarios, specifically for manual telecoms testing. This article provides a small insight into writing simple scripts for automating calls with Python. Here, I have described a simple way to automatically initiate a call between 2 subscribers. The idea can be extended to anything than just a basic call, like call transfers, data calls, etc. The tools required are: Python 2.6 or more(found here http://www.python.org/download/) Pyserial 2.5(found here http://pypi.python.org/pypi/pyserial) 2 SIMs able to make MO/MT calls 2 Handsets with data cables Here is a simple code which makes the call possible:

import serial
#This imports the pyserial module needed to communicate with the #COM port, to which the phone is attached.

import time #Required for time.sleep command MS_A=serial.Serial(port='COM7')


#Here we are defining a variable MS_A, which is of type pyserial, #and assigning it to COM 7. Change the COM port accordingly.

time.sleep(5) #Wait till the assignment is complete. MS_B=serial.Serial(port='COM9')


#Here we are defining a variable for MS B. Change the COM port accordingly.

time.sleep(5)
#Here we close the ports in case they were not closed properly last time.

MS_A.close() MS_B.close() time.sleep(3)#Wait for some time. MS_A.open() MS_B.open()


#We open the COM ports and then send the AT command to make an MO call.

MS_A.write("atd 07773030667;\r\n" ) MS_B.write("ats0=1;\r\n") #Enable auto answer on MS B. time.sleep(30) #Duration of the call. MS_A.write("at+chup;\r\n") #Send disconnect on MS A. time.sleep(2) MS_A.close() #Close the ports. MS_B.close() In order to execute this code, copy and paste it in a text editor, rename the file as xxxxx.py. Connect the two handsets to the PC which has got Python and Pyserial installed. Note down the COM ports of the handsets (in case of Windows use Start>Control Panel>Device Manager>Modems). Update the COM ports and the MSISDN of the handsets in the above script accordingly. Start the Python IDLE, and open the file you have just saved. Click on Run-->Run Module or press F5. The script should be compiled and executed, resulting in an MO call from handset A to B. The idea can be extended further as long as we have AT commands for the operation we intend to execute. This will definitely help in automating the repetitive tests that might be executed as part of Regression Suites.

I have successfully used Python scripts in automating certain call scenarios like Call transfers, digit analysis tests, CSD calls. Once the scripts are ready, it saves lot of time and effort on part of the test engineer. It also eliminates manual errors like dialling wrong numbers. This is an introductory article to get the reader a taste of Python, especially in automating simple call test scenarios. More information can be found in the extensive documentation of both Python and Pyserial at: http://docs.python.org/tutorial/ http://pyserial.sourceforge.net/pyserial.html A good document of AT commands for Nokia handsets can be found here: http://www.forum.nokia.com/info/sw.nokia.com/id/95672052-6c77-488d-a055acef77e4cdc5/AT_Command_Set_For_Nokia_GSM_And_WCDMA_Products_v1_2_ en.pdf.html

S-ar putea să vă placă și