Use the Lotus Notes API to improve the efficiency of automated testing)

Source: Internet
Author: User

Automated Testing can greatly reduce the workload of manual participation and improve testing efficiency. In automated testing, testers often need to deal with the Notes/domino database. For example, before automated testing, you need to select which test cases to be executed from the test case database; after the test is completed, you need to record the test results to the test case database, or store the test report to a specified database in notes. This is usually done manually. If you automate these tasks, the test time and cost will be greatly reduced. Fortunately, Lotus Notes/Domino isProgramProvides a series of C ++/Java APIs that can be used to access, create, and manage the Notes database. This article describes how to use the Lotus Notes API to program and automatically operate the Notes/domino database so that the entire test process is completed automatically.

Figure 1 illustrates the overall process of automated testing: first, extract qualified test cases from tcdb, install the tested software on the specified test machine, execute the selected test cases, generate the test report, and then backfill the test results to the testcase dB, and send the test report to the specified database.

Figure 1.

Back to Top

Application of Notes/Domino C ++ APIs in automated testing

C ++ APIs are built on the basis of encapsulating the notes C APIs. Because of the object-oriented feature of C ++, C ++ APIs are easier to use.

Before using the notes C ++ API for programming, You need to download the C ++ API toolkit of the matching version based on your current Notes version. This Toolkit can be obtained from the IBM website. The toolkit contains API help documents, library files, header files, sample programs, and database files used in the sample programs.

Configure visual c ++

Before using the notes C ++ API for programming, you must configure visual c ++ to ensure that the environment is correctly configured.CodeThe link can be compiled normally.

    • Add the installation path of notes to the environment variable path.
    • Create a C ++ project notesdemos in VC and create a new C ++ file.
    • Choose build> set Active configuration> Win32 release> OK.
    • Add the C ++ API (notescpp) path to lib and include
    • Select project> Add to project> files to add notescpp. lib to the project, as shown in Figure 2:

Figure 2.

Use notes/Domino C ++ API for programming

Next we will introduce how to use the notes C ++ API to access notes and perform operations on documents in the Notes database.

Code List 1 is a simple example program to get a database name.

Listing 1.

# Include <lncppapi. h> # include <iostream. h> void main (INT argc, char * argv []) {char errorbuf [256]; lnnotessession session; lnsetthrowallerrors (true); lndatabase dB; Session. init (); try {session. getdatabase (nsffilename, & dB, server); dB. open (); cout <"DB title:" <dB. gettitle () <Endl;} catch (lnstatus error) {lngeterrormessage (error, errorbuf); cout <"error:" <errorbuf <Endl;} dB. close (); Session. term (); return ;}

Where:

Lncppapi. H: This header file must be included in Notes API programming. This file is located in the notescpp \ include directory and linked to other class libraries that define all API objects and data types through this header file. For example, the lnnotessession class is defined in it.

Session. init: initializes the C ++ API, establishes a connection with the notes, reads the notes. ini file, and finds the current Notes user ID. After establishing a connection with notes, you can operate the Notes database.

Session. Term: After the notes db operation is complete, call this function to disconnect from the notes and release resources.

Getdatabase (const lnstring & Path, lndatabase * dB, const lnstring & Server = ""): The NSF parameter file name and the Server Hostname can be obtained by viewing the database attributes, as shown in 3:

Figure 3.

Each document attribute in the database (which can be obtained by right-clicking) is composed of different domains. Through these domains, You can uniquely identify a document and perform operations on it by changing the Domain value. Document Property 4:

Figure 4.

After the automated test is completed, the test report can be automatically stored in the specified directory of the specified database. Listing 2 demonstrates how to operate the documents in the database. The purpose of this code snippet is to first create a document in the specified database and then import the test report to the document, which makes the test report more intuitive. Of course, you can also call

The lnrichtext: createattachment () method attaches the test report as an attachment to this document.

List 2.

Session. init (); Session. getdatabase (nsffilename, & dB, server); // connect to the specified database. lntext author, categories, subject, documenttype; lndocument newdoc, newres; dB. open (); // first query the main document, and then make the test report reply to this document: searchformula = "subject = \" "; searchformula + = maindocsubject; searchformula + = "\" "; // if no main document is found, create a Document of the type" maintopic. Search () method, find the document, and return 0. if (dB. search (searchformula, & docresponseto) {dB. createdocument (& newdoc, "maintopic"); Subject. setvalue (maindocsubject); author. setvalue ("cn = Jing Xing/ou = China/o = IBM"); categories. setvalue (category); documenttype. setvalue ("Reference"); // set newdoc for different fields in the document. createitem ("from", author, lnitemflags_summary); newdoc. createitem ("subject", subject, lnitemflags_summary); newdoc. cr Eateitem ("categories", categories, lnitemflags_summary); newdoc. createitem ("doctype", documenttype, lnitemflags_summary); newdoc. computewithform (true); newdoc. save (); // Save the document} // create the document. The type is response dB. createdocument (& newres, "response"); Subject. setvalue (subsubject); author. setvalue ("cn = Jing Xing/ou = China/o = IBM"); categories. setvalue (category); newres. createitem ("from", author, lnitemflags_summar Y); newres. createitem ("subject", subject, lnitemflags_summary); // If the category does not exist, create a new category if (category! = "") {Newres. createitem ("categories", categories, lnitemflags_summary);} newres. createitem ("showauthors", showauthors, lnitemflags_summary); newres. makeresponse (newdoc); // reply to newdoc RT. append ("Here is the report: \ n"); RT. getendcursor (& begincursor); RT. import (reportlocation, & begincursor); // import the report file to the new document. Newres. createitem ("body", RT); newres. Save (); DB. Close (); Session. term ();

For the specific usage of each function, refer to the help document provided by notesapp.

Back to Top

Notes/Domino Java API

Like C ++ APIs, notes Java APIs can perform most operations on the notes/domino database. The difference is that Java APIs are relatively simpler to use. You don't need to configure many things. You only need to set $ {notes}/JVM/lib/EXT/notes. jar is included in classpath. For more information about Java APIs, see IBM Lotus Notes and Domino Information Center.

The following is a simple example to illustrate how to connect to a database through Java APIs. Listing 3 is to access a database and then output its name.

Listing 3.

Public static void main (string ARGs []) {try {notesthread. sinitthread (); // start the thread session = notesfactory. createsession (string) null, (string) null, password); database = session. getdatabase (host, NSF, false); // connect to the database system. out. println ("database tilte is:" + database. gettitle ();} finally {notesthread. stermthread (); // end this thread }}

Where:

    • Notesthread. sinitthread (): initialization process for local calls to notes/Domino.
    • Notesthread. stremthread (): ends the call.
    • Session. getdatabase (string server, string dB, Boolean createonfail): This method is similar to that of C ++. You need to provide the hostname of the server to be accessed and the name of the NSF file of the database. You can also view the database attributes.

As mentioned above, in automated testing, it is necessary to select qualified test cases from the test case database for automatic execution. In code list 4 below, all test cases whose execution method is automated are selected from the database and organized into a test case set and saved in the. Suite file.

Listing 4.

String cycle = "CYC-001"; try {notesthread. sinitthread (); file = new file ("C:/cyc-001.suite"); // This file is used to save the ID of the qualified test case if (file. getparentfile ()! = NULL) file. getparentfile (). mkdirs (); suitefilewriter = new bufferedwriter (New filewriter (suitefile); Session session = notesfactory. createsession (string) null, (string) null, notespassword); database = session. getdatabase (host, NSF, false); documentcollection Dc = database. search ("execcycleid =" + "\" "+ cycle +" \ ""); // search all test cases that belong to the "CYC-001. Document Doc = Dc. getfirstdocument (); While (Doc! = NULL) {string method = Doc. getitemvaluestring ("method"); // obtain the value of the domain "method" string TCID = Doc. getitemvaluestring ("exectcid"); If ("Automated ". equals (method) {suitefilewriter. write ("TCID. replace ("-", "_") + "\ r \ n") ;}}} finally {notesthread. stermthread (); If (suitefilewriter! = NULL) Try {suitefilewriter. Close () ;}catch (exception e ){}}}

Back to Top

Summary

This article describes how to use the APIS provided by notes/domino in automated testing to access the Notes/domino database and perform document operations in the database, so that many tasks in the automated testing can be completed automatically. Both notes C ++ APIs and Java APIs can meet the requirements for notes/domino database operations during automated testing. This greatly increases the automation of testing, reduces test costs.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.