Automation test with Visual Basic 6.0

xiaoxiao2021-03-06  51

Automated test selection with Visual Basic 6.0

HK_VON's Blog

Automated testing with Visual Basic 6.0 (Sai ​​Bao Software Review Center , Guangdong, 510610) Huang Maosheng this article is taken from the Internet. Abstract: This paper explores the possibility of Visual Basic 6.0 in test automation, and lists some examples of existing automation test tools in actual work. An obvious way in front of the software test automation. The fact is that the tools currently can do not do everything we want to do; counting any tool to fully support the test automation of many different applications is unrealistic. Since it is difficult to find a test tool that can fully meet the test automation, and the test automation tool is very expensive, the common practice is to use a primary automated test tool, then use traditional programming languages ​​such as Java, C and Visual Basic. Write an automated test script to make up for the shortcomings of the tool. II Visual Basic's Advantages and Limitations of Automation Tests and Limitations Using Visual Basic's reasonable features better than test automation tools lies in writing test scripts for actual projects, and in fact Visual Basic is indeed. There is more obvious advantages over other programming languages ​​to test automation projects. It is well known that Visual Basic is not a test tool, but it is a very popular software development language; using Visual Basic's biggest benefit is a very popular language, it is simple, easy to learn, and very widely Basic language user base foundation, even for test engineers who don't know Visual Basic, they must be familiar with it or easily find a large number of publications and materials. Visual Basic itself has some features that support the test process, for example, it has functions that return important information about test platforms and measured applications. Visual Basic's shell function and SendKeys function can initiate an application and operate its graphical user interface, with Visual Basic to write some of the required scripts, for example, load a test application. The integrated visual data manager in Visual Basic can connect directly to a database and view its data structure. In addition, Visual Basic can also be used to test applications for background operations, for example, can write some script access initialization files (.ini files) and Windows registry. Applications (API) accessing Windows from Visual Basic is very effective for manipulating applications and reports some important information, and Visual Basic language is more time to master more than other programming languages. High programming efficiency, suitable for fast-building test automation work needs to quickly establish test scripts. Since Visual Basic is not a professional test tool, there is a limit type, first it does not contain most of the functionality of the currently mature automation test tool, for example, Visual Basic itself does not provide defect report, test design and documentation Management and other functions; it also lacks recording and any automated test settings. To include these features in the Visual Basic test code, you need to manually write this function code, and most of the current publications and materials about Visual Basic are targeted. Developers rather than testers. Nonetheless, there are some basic methods that do not need many inputs to automate the test items in Visual Basic. Tools for Test Automation in Three Visual Basic Visual Basic 6.0 contains a set of tools that do not require any encoding to support tests, including rich wizards, visual data tools, and object browsers.

1 Wizard and Template A wide range of wizards in Visual Basic can be used. One of the very useful guiders is the Data Form Wizard, which can create a data window that can connect Access or ODBC databases, which can be set to view a single record separately or batch data records in the form of table, so A test tool for checking the contents of the database can be quickly customized and easy to use. The form template can not only quickly create a standard window, but also with these windows to generate source code, these automatically generated code can be partially or fully applied to a window customized to test, which is very effective for improving test efficiency. of. In addition, some other wizards such as data object wizards, ActiveX Control Window Wizards can achieve minimal coding efforts to create and configure some useful test objects. 2 Visual Data Manager Visual Data Manager can quickly connect to the ODBC or OLEDB data source to view database structures, data tables, views, and other basic objects. Use it to check the background database to implement the database application test. That is to say, if the measured application contains a database in SQL Server, Sybase, Oracle, and Access, you can check all of these databases by visualizing data managers without having to log in to the DBMS interface separately. By Visual Basic as a generic front desk database manager to manage a background database accessible with ODBC or OLEDB, save the testing time of the test engineer and may spend the training time that can be familiar with these database products. Visual Data Manager supports white box test through database input and test SQL statements. Use it to modify background data, even create new data objects such as data tables, store procedures, and data views. Some SQL statements that are used to test data (typically used to retrieve defects for duplicate data rows and exposure integrity) can be created and executed here if necessary. 3 Object Browser Object Browser Object Browser is another very useful Visual Basic tool, through it to check the properties and methods of the object output, and various necessary parameters; testers can use this information to create verification and feature of these objects Sex test, especially for object-oriented tests, very useful and very effective. Object browser can display a custom COM object, which lists the properties, methods, and events of the object, and this object can be developed with any language that supports COM object models. Setting up an object-related information in an object browser and viewing a test person who lacks test training for a short time, of course, to establish a Visual Basic test script to test the properties, methods, events, and events need to do Some write code work. Four Visual Basic's Application Examples of Automated Test Work The following is some examples of using Visual Basic to implement test automation or related work in actual testing, such as recording test results information, simple GUI testing. 1 Using the Text File Record Test Information Example 1Open "Testlog.txt" for Input AS # 1 'Opens the record file Print # 1, FileDateTime ("c: /windows/calc.exe")' record the date and time created by the test program Print # 1, Filelen ("C: /Windows/calc.exe") 'records the length of the test program Print # 1, curdir' records the current directory path Print # 1, Environment ("windir") record the current windows directory path Print # 1, now 'record test start date and time

...... 'Record Test Procedure Information Close # 1' Close Record File In the test process, a job that is often done in the test is to find an error message to check the application's login file. These login files are usually text files, and for any Programming languages ​​are easy to open and read these files with basic file operation functions. The other work is to record the test process information and test results, which is essentially mentioned above to use the same function function: a simple record method is to write a test result into a text file. The code shown in Example 1 is to implement these recording functions. 2 GUI function test example 2 shell ("c: /Windows/calc.exe") 'Start calculator for i = 1 to 100' Set calculation cycle sendKeys I & "{ }", True 'send hit button action to calculation NEXT I 'Calculates the value SendKeys "=", true' in black box test, and implement the test script to write test scripts to simulate the daily operation input of the test script. The shell function and sendKeys function using Visual Basic can simply effectively implement some GUI function tests. The display code of Example 2 opened a Windows calculator, and then sent a keystroke action to simulate the user input, calculate the sum of a series of values ​​(1 to 100); the startup program calls the SHELL function of Visual Basic, the SendKeys instruction is used to send hits Key to an application to simulate user input and calculation results. 3 Reading and setting the Registry Information Example 3 DIM ASTRSETTINGS () AS String 'Defines Variable LstSettings.clear' Clear List Box Content ASTRSETTINGS = GetallSettings (TestAppName, TXTSECTION) 'Call the dedicated function Return to the VB' dedicated location Registry Information for iCount = 0 to Ubound (ASTRSETTINGS) 'Displayed in the list box by looping in the list box LstSettings.addItem Astrsettings (ICOUNT, 0) & ":" _ & ASTRSETTINGS (ICOUNT, 1) Next ICOUNT Note: TestAme is a test application The name of the program has a lot of time to check the registry. The registration table is a place where the application installation settings, options and other important information. Visual Basic 6.0 includes a new functional function that returns information from the registry key value location dedicated to the Visual Basic application software. These functions are simply set and returned to these registry key values, which is especially useful for the application developed with Visual Basic. Example 3 The code returns all registry information in the location "HKEY_CURRENT_USER / VB AND VBA Program Settings /" in the registry and displays this information in a list box named LSTSETTINGS. To access the registry information of other locations, you need to call the Windows API function. The five sizes can be seen, in order to make up for the shortcomings of the current automated test tool, select some test scripts or test aids in actual work in actual work, and Visual Basic 6.0 is easy to learn due to its powerful function. Easy, there is a wide range of user bases, and it is one of the tools applied to test automation.

转载请注明原文地址:https://www.9cbs.com/read-82993.html

New Post(0)